Repository navigation
refactor(frontend): share one dialog for confirm-then-act flows #939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f77ec5f
feat(frontend): add a shared dialog that confirms before an action
abdulrafey1 8a299ff
refactor(frontend): confirm pxc activity deletes with the shared dialog
abdulrafey1 0524919
refactor(frontend): confirm whitelist removal with the shared dialog
abdulrafey1 00735b0
refactor(frontend): confirm slack disconnect with the shared dialog
abdulrafey1 541b926
fix(frontend): log confirm dialog failures under a fixed message
abdulrafey1 481a823
fix(frontend): show an error when a confirmed action has no token
abdulrafey1 f7153a8
Merge remote-tracking branch 'origin/main' into rafe/confirm-dialog
abdulrafey1 a4075e5
fix(frontend): show the server's reason when a confirmed action fails
abdulrafey1 f4a7cab
fix(frontend): translate the network error message
abdulrafey1 5c94a33
Merge remote-tracking branch 'origin/main' into rafe/confirm-dialog
abdulrafey1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
|
|
||
| import { Alert } from "@/components/ui/Alert"; | ||
| import { Button } from "@/core/components/ui/Button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@/components/ui/Dialog"; | ||
| import { ApiRequestError } from "@/lib/api"; | ||
|
|
||
| /** | ||
| * A dialog that asks before running an action, such as a delete. | ||
| * | ||
| * While `onConfirm` runs, both buttons are disabled and the dialog cannot be dismissed. If it | ||
| * rejects, the error is logged and the dialog stays open showing the message of an | ||
| * `ApiRequestError`, or `errorMessage` for any other error. On success the caller closes the | ||
| * dialog, usually by unmounting it. | ||
| */ | ||
| export function ConfirmDialog({ | ||
| title, | ||
| description, | ||
| confirmLabel, | ||
| pendingLabel, | ||
| cancelLabel, | ||
| errorMessage, | ||
| onConfirm, | ||
| onClose, | ||
| }: { | ||
| title: string; | ||
| description: React.ReactNode; | ||
| confirmLabel: string; | ||
| pendingLabel: string; | ||
| cancelLabel: string; | ||
| errorMessage: string; | ||
| onConfirm: () => Promise<void>; | ||
| onClose: () => void; | ||
| }): React.JSX.Element { | ||
| const [loading, setLoading] = useState(false); | ||
| const [shownError, setShownError] = useState<string | null>(null); | ||
|
|
||
| async function handleConfirm() { | ||
| setLoading(true); | ||
| setShownError(null); | ||
| try { | ||
| await onConfirm(); | ||
| } catch (error) { | ||
| console.error("ConfirmDialog: action failed", error); | ||
| setShownError(error instanceof ApiRequestError ? error.message : errorMessage); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open onOpenChange={(open) => !open && !loading && onClose()}> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>{title}</DialogTitle> | ||
| <DialogDescription>{description}</DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| {shownError && <Alert severity="error">{shownError}</Alert>} | ||
|
|
||
| <DialogFooter className="gap-2"> | ||
| <Button variant="outline" size="sm" onClick={onClose} disabled={loading}> | ||
| {cancelLabel} | ||
| </Button> | ||
| <Button | ||
| variant="error" | ||
| size="sm" | ||
| loading={loading} | ||
| spinnerLabel={pendingLabel} | ||
| disabled={loading} | ||
| onClick={handleConfirm} | ||
| > | ||
| {confirmLabel} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.