import { useState } from 'react'; import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel, } from '@/components/ui/alert-dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { cn } from '@/lib/utils'; import { buttonVariants } from '@/components/ui/button'; interface Props { title?: string; message: string; confirmLabel?: string; cancelLabel?: string; danger?: boolean; /** When set, user must type this exact phrase before the confirm button enables. */ confirmPhrase?: string; onConfirm: () => void; onCancel: () => void; } export function ConfirmDialog({ title = 'Confirm', message, confirmLabel = 'Confirm', cancelLabel = 'Cancel', danger = false, confirmPhrase = '', onConfirm, onCancel, }: Props) { const [typed, setTyped] = useState(''); const enabled = confirmPhrase === '' || typed === confirmPhrase; return ( { if (!o) onCancel(); }}> { if (e.key === 'Enter' && enabled) onConfirm(); }} > {title} {message} {confirmPhrase && (
setTyped(e.target.value)} className="font-mono" />
)} {cancelLabel} { if (enabled) onConfirm(); }} > {confirmLabel}
); }