| 1 | "use client"; |
| 2 | |
| 3 | import type React from " |
| 4 | import { useTranslations } |
| 5 | import { |
| 6 | Dialog, |
| 7 | DialogPopup, |
| 8 | DialogClose, |
| 9 | DialogHeader, |
| 10 | DialogFooter, |
| 11 | DialogTitle, |
| 12 | DialogDescription, |
| 13 | } from "@struxa/ui/components/dialog"; |
| 14 | |
| 15 | interface ConfirmDialogProps { |
| 16 | open: boolean; |
| 17 | onOpenChange: (open |
| 18 | title: string; |
| 19 | description?: string |
| 20 | children?: React |
| 21 | confirmLabel?: string |
| 22 | onConfirm: () |
| 23 | loading?: boolean |
| 24 | destructive?: boolean |
| 25 | } |
| 26 | |
| 27 | export function ConfirmDialog({ |
| 28 | open, |
| 29 | onOpenChange, |
| 30 | title, |
| 31 | description, |
| 32 | children, |
| 33 | confirmLabel, |
| 34 | onConfirm, |
| 35 | loading = false, |
| 36 | destructive = false, |
| 37 | }: ConfirmDialogProps) |
| 38 | const t = |
| 39 | |
| 40 | return ( |
| 41 | <Dialog open={ |
| 42 | <DialogPopup showCloseButton={ |
| 43 | <DialogHeader> |
| 44 | <DialogTitle>{title} |
| 45 | {description && <DialogDescription |
| 46 | </DialogHeader> |
| 47 | {children && <div |
| 48 | <DialogFooter> |
| 49 | <DialogClose |
| 50 | className="rounded-lg px-4 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50" |
| 51 | disabled={loading} |
| 52 | > |
| 53 | {t("cancel") |
| 54 | </DialogClose> |
| 55 | <button |
| 56 | type="button" |
| 57 | onClick={onConfirm} |
| 58 | disabled={loading} |
| 59 | className={`rounded-lg px-4 py-1.5 text-xs font-medium transition-opacity disabled:opacity-50 ${ |
| 60 | destructive |
| 61 | ? "bg-destructive text-destructive-foreground hover:opacity-80" |
| 62 | : "bg-foreground text-background hover:opacity-80" |
| 63 | }`} |
| 64 | > |
| 65 | {loading ? "… |
| 66 | </button> |
| 67 | </DialogFooter> |
| 68 | </DialogPopup> |
| 69 | </Dialog> |
| 70 | ); |
| 71 | } |