diff --git a/src/pages/components/CertificateActionsButtons.js b/src/pages/components/CertificateActionsButtons.js index 93c8c86d..b9b1e911 100644 --- a/src/pages/components/CertificateActionsButtons.js +++ b/src/pages/components/CertificateActionsButtons.js @@ -4,6 +4,12 @@ import styled from 'styled-components' import { Grid, Button } from '@digicatapult/ui-component-library' export default function CertificateActionsButtons() { + // START + const [data, setData] = useState(null) + const [error, setError] = useState('') + const [loading, setLoading] = useState(false) + // END + const [isWaitingVal, setIsWaitingVal] = useState(false) const handleClickSaveDraft = (e) => { @@ -22,6 +28,36 @@ export default function CertificateActionsButtons() { }, 2000) } + // START + // check w/ u=http://localhost:8000/v1/certificate ; len=$(curl -s $u | jq length) ; curl -s $u | jq .[$((r - 1))] + const handleClick = () => { + const url = 'http://localhost:8000/v1/certificate' + const obj = { + energy_consumed_wh: 2000000, + production_start_time: '2024-01-25T10:00:00.000Z', + production_end_time: '2024-01-25T20:00:00.000Z', + regulator: 'Reginald', + energy_owner: 'Emma', + hydrogen_quantity_wh: 2000000, + } + setLoading(true) + fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(obj), + }) + .then((r) => r.json()) + .then((data) => { + setData(data) + setLoading(false) + }) + .catch((error) => { + setError(error) + setLoading(false) + }) + } + // END + return ( @@ -58,6 +94,15 @@ export default function CertificateActionsButtons() { Submit {isWaitingVal && ...} +
+
+ + {error &&
ERROR
} + {data &&
{JSON.stringify(data)}
}