import { useState } from 'react'; import { toast } from 'sonner'; import { ShieldAlert, Loader2, Trash2 } from 'lucide-react'; import { api } from '@/api'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { SectionCard } from './dataShared'; /** * Danger zone: permanently erase the user's financial data. Type-to-confirm, and * makes clear that the account/login/2FA are preserved. Reuses POST * /api/user/erase-data (transactional, audited, re-seeds default categories). */ export default function EraseDataSection({ onErased, cardProps = {} }) { const [open, setOpen] = useState(false); const [confirm, setConfirm] = useState(''); const [busy, setBusy] = useState(false); const canErase = confirm.trim().toUpperCase() === 'ERASE'; async function handleErase() { if (!canErase) return; setBusy(true); try { const r = await api.eraseMyData(confirm.trim()); toast.success(`Your data was erased — ${r.erased} record${r.erased === 1 ? '' : 's'} removed.`); setOpen(false); setConfirm(''); onErased?.(); } catch (err) { toast.error(err.message || 'Erase failed.'); } finally { setBusy(false); } } return (

This permanently deletes your financial data.

Bills, payments, transactions, categories, bank connections, imports and rules will be erased and can’t be recovered. Your account, login and 2FA are kept. Consider downloading a backup first.

{ setOpen(v); if (!v) setConfirm(''); }}> Erase all your data? This permanently deletes your bills, payments, transactions, categories, bank connections and imports. It cannot be undone. Type ERASE to confirm. setConfirm(e.target.value)} placeholder="Type ERASE" className="font-mono" aria-label="Type ERASE to confirm" /> Cancel { e.preventDefault(); handleErase(); }} className="bg-rose-600 text-white hover:bg-rose-700" > {busy ? <>Erasing… : 'Permanently erase'}
); }