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

Commit

Permalink
Cleaned up the fetch post call.
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-andysign committed Jan 26, 2024
1 parent 80ede36 commit b115104
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/pages/components/CertificateActionsButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,31 @@ export default function CertificateActionsButtons() {
}

// START
// check w/ u=http://localhost:8000/v1/certificate ; len=$(curl -s $u | jq length) ; curl -s $u | jq .[$((r - 1))]
// check w/
// u=http://localhost:8000/v1/certificate ; len=$(curl -s $u | jq length) ; curl -s $u | jq .[$((r - 1))]
const handleClick = () => {
setLoading(true)
const url = 'http://localhost:8000/v1/certificate'
const obj = {
const bodyObj = {
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),
body: JSON.stringify(bodyObj),
})
.then((r) => r.json())
.then((data) => {
setData(data)
setLoading(false)
})
.then((data) => setData(data))
.catch((error) => {
setError(error)
setLoading(false)
})
.finally(() => setLoading(false))
}
// END

Expand Down Expand Up @@ -101,7 +100,7 @@ export default function CertificateActionsButtons() {
{loading == false && data != null && <span>Submitted</span>}
{loading && <span>...</span>}
</button>
{error && <div>ERROR</div>}
{error && <div>ERROR: {JSON.stringify(error)}</div>}
{data && <div>{JSON.stringify(data)}</div>}
</Grid.Panel>
</Grid>
Expand Down

0 comments on commit b115104

Please sign in to comment.