-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Errors UI: Acknowledge functionality (#901)
Users can now mark errors as 'Acknowledged'. If there are no unacknowledged errors for a mirror, it's status is said to be 'Active' <img width="1484" alt="Screenshot 2023-12-25 at 10 51 03 PM" src="https://github.com/PeerDB-io/peerdb/assets/65964360/dc9f1118-e1d7-4b93-8447-e3d98905c3bf"> Users can click on the status and be taken to the page above. <img width="1484" alt="Screenshot 2023-12-25 at 10 22 34 PM" src="https://github.com/PeerDB-io/peerdb/assets/65964360/09e45398-0f03-403c-b54c-5b7757d92613"> - Loading indicator for acknowledge button - Error toast incase acknowledge operation fails
- Loading branch information
1 parent
ed67a63
commit f1038ba
Showing
6 changed files
with
174 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,57 @@ | ||
'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 | ||
const handleAck = async (mirrorID: bigint | number) => { | ||
setLoading(true); | ||
const updateResResult = await fetch('/api/mirrors/alerts', { | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
mirrorIDStringList: [mirrorID.toString()], | ||
}), | ||
}); | ||
const updateRes = await updateResResult.json(); | ||
setLoading(false); | ||
if (!updateRes) { | ||
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