Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Added dummy post call to backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-andysign committed Jan 26, 2024
1 parent 326332e commit 80ede36
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/pages/components/CertificateActionsButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 (
<Sidebar area="sidebar">
<PaddedDiv>
Expand Down Expand Up @@ -58,6 +94,15 @@ export default function CertificateActionsButtons() {
Submit
{isWaitingVal && <span>...</span>}
</LargeButton>
<br />
<hr />
<button type="button" onClick={handleClick}>
{loading == false && data == null && <span>Submit</span>}
{loading == false && data != null && <span>Submitted</span>}
{loading && <span>...</span>}
</button>
{error && <div>ERROR</div>}
{data && <div>{JSON.stringify(data)}</div>}
</Grid.Panel>
</Grid>
</PaddedDiv>
Expand Down

0 comments on commit 80ede36

Please sign in to comment.