diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-31 16:23:25 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-31 19:27:25 +0100 |
| commit | c0e2bdc01366f4a8878ffb373527d786e163a19b (patch) | |
| tree | d98098be23f63d733d6e79cc624b69ba351c616d /apps/web/components/ui | |
| parent | 899842e476d538df777f541d956cc5211994fff7 (diff) | |
| download | karakeep-c0e2bdc01366f4a8878ffb373527d786e163a19b.tar.zst | |
refactor: Extract the action confirming dialog into its own component
Diffstat (limited to 'apps/web/components/ui')
| -rw-r--r-- | apps/web/components/ui/action-confirming-dialog.tsx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/web/components/ui/action-confirming-dialog.tsx b/apps/web/components/ui/action-confirming-dialog.tsx new file mode 100644 index 00000000..980bdd60 --- /dev/null +++ b/apps/web/components/ui/action-confirming-dialog.tsx @@ -0,0 +1,48 @@ +"use client"; + +import { useState } from "react"; +import { + Dialog, + DialogClose, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; + +import { Button } from "./button"; + +export default function ActionConfirmingDialog({ + title, + description, + actionButton, + children, +}: { + title: React.ReactNode; + description: React.ReactNode; + actionButton: (setDialogOpen: (open: boolean) => void) => React.ReactNode; + children: React.ReactNode; +}) { + const [isDialogOpen, setDialogOpen] = useState(false); + + return ( + <Dialog open={isDialogOpen} onOpenChange={setDialogOpen}> + <DialogTrigger asChild>{children}</DialogTrigger> + <DialogContent> + <DialogHeader> + <DialogTitle>{title}</DialogTitle> + </DialogHeader> + {description} + <DialogFooter className="sm:justify-end"> + <DialogClose asChild> + <Button type="button" variant="secondary"> + Close + </Button> + </DialogClose> + {actionButton(setDialogOpen)} + </DialogFooter> + </DialogContent> + </Dialog> + ); +} |
