-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79e9ce3
commit 7bdc281
Showing
6 changed files
with
160 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use client'; | ||
import { Button } from '@/lib/Button'; | ||
import { Label } from '@/lib/Label'; | ||
import { ProgressCircle } from '@/lib/ProgressCircle'; | ||
import { useState } from 'react'; | ||
import { toast } from 'react-toastify'; | ||
|
||
const notifyErr = (errMsg: string) => { | ||
toast.error(errMsg, { | ||
position: toast.POSITION.BOTTOM_CENTER, | ||
}); | ||
}; | ||
|
||
const AckButton = ({ ack, id }: { ack: boolean; id: number | bigint }) => { | ||
const [loading, setLoading] = useState(false); | ||
const [updated, setUpdated] = useState(false); | ||
// handleAck updates ack to true for the given mirrorId list | ||
const handleAck = async (mirrorIDList: (bigint | number)[]) => { | ||
setLoading(true); | ||
const updateRes = await fetch('/api/mirrors/alerts', { | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
mirrorIDStringList: mirrorIDList.map((id) => id.toString()), | ||
}), | ||
}).then((res) => res.json()); | ||
setLoading(false); | ||
if (!updateRes || updateRes === 0) { | ||
notifyErr('Something went wrong when trying to acknowledge'); | ||
return; | ||
} | ||
setUpdated(true); | ||
}; | ||
return ( | ||
<> | ||
{ack !== true && updated !== true ? ( | ||
<Button variant='normalSolid' onClick={() => handleAck([id])}> | ||
<Label as='label' style={{ fontSize: 13 }}> | ||
{loading ? ( | ||
<ProgressCircle variant='intermediate_progress_circle' /> | ||
) : ( | ||
'Acknowledge' | ||
)} | ||
</Label> | ||
</Button> | ||
) : ( | ||
<Button variant='normal' disabled={true}> | ||
<Label as='label' style={{ fontSize: 13 }}> | ||
Acknowledged | ||
</Label> | ||
</Button> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default AckButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters