// ============================================================ // CONFIRM MODAL — React replacement for the vanilla showConfirm() // helper. Daniel's feedback is explicit: never call window.confirm() // in the frontend — use a styled modal that matches the app's design // language. Supports a danger variant (destructive actions like // revoke) and an optional password-input variant (e.g. "confirm by // entering your password" for 2FA backup-code regen). // ============================================================ import { useEffect, useState } from 'react'; interface ConfirmModalProps { open: boolean; title: string; body?: string; confirmText?: string; cancelText?: string; danger?: boolean; // When true, a password field is shown and the value is passed to onConfirm. requirePassword?: boolean; passwordPlaceholder?: string; onConfirm: (password?: string) => void; onCancel: () => void; busy?: boolean; } export default function ConfirmModal({ open, title, body, confirmText = 'Confirm', cancelText = 'Cancel', danger = false, requirePassword = false, passwordPlaceholder = 'Password', onConfirm, onCancel, busy = false, }: ConfirmModalProps) { const [password, setPassword] = useState(''); useEffect(() => { if (!open) setPassword(''); }, [open]); useEffect(() => { function onKey(e: KeyboardEvent) { if (!open) return; if (e.key === 'Escape') onCancel(); } window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [open, onCancel]); if (!open) return null; const confirmDisabled = busy || (requirePassword && !password); return (
e.stopPropagation()} >

{title}

{body &&

{body}

} {requirePassword && ( setPassword(e.target.value)} placeholder={passwordPlaceholder} className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" onKeyDown={(e) => { if (e.key === 'Enter' && !confirmDisabled) onConfirm(password); }} /> )}
); }