UI: Throw error if resetAll() fails

This commit is contained in:
Mike Salvatore 2022-07-01 09:05:42 -04:00
parent 05129c9d6b
commit d8a7ac3fb6
1 changed files with 21 additions and 19 deletions

View File

@ -74,10 +74,19 @@ const IslandResetModal = (props: Props) => {
<button type='button' className='btn btn-danger btn-lg' style={{margin: '5px'}} <button type='button' className='btn btn-danger btn-lg' style={{margin: '5px'}}
onClick={() => { onClick={() => {
setResetAll(Loading); setResetAll(Loading);
resetAll(() => { try {
setResetAll(Done); resetAll().then(res => {
props.onClose(); if (res.status === 200) {
setResetAll(Done);
props.onClose();
} else {
throw 'Error resetting the simulation'
}
}) })
} catch (err) {
// TODO: Display error message
console.error(err)
}
}}> }}>
Reset the Island Reset the Island
</button> </button>
@ -97,24 +106,17 @@ const IslandResetModal = (props: Props) => {
} }
}) })
} }
function resetAll(callback: () => void) { function resetAll() {
auth.authFetch('/api/reset-agent-configuration', {method: 'POST'}) return auth.authFetch('/api/reset-agent-configuration', {method: 'POST'})
.then(res => { .then(res => {
if (res.status === 200) { if (res.status === 200) {
auth.authFetch('/api/clear-simulation-data', {method: 'POST'}) return auth.authFetch('/api/clear-simulation-data', {method: 'POST'})
.then(res => { })
if (res.status === 200) { .then(res => {
auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'}) if (res.status === 200) {
.then(res => { return auth.authFetch('/api/island-mode', {method: 'POST', body: '{"mode": "unset"}'})
if (res.status === 200) { })
callback(); }
}
})
}
})
}
})
}
function showModalButtons() { function showModalButtons() {
return (<Container className={`text-left island-reset-modal`}> return (<Container className={`text-left island-reset-modal`}>