'use client'; import {useState} from 'react'; import {Dialog, DialogHeader} from '@astryxdesign/core/Dialog'; import {VStack, HStack} from '@astryxdesign/core/Layout'; import {TextInput} from '@astryxdesign/core/TextInput'; import {Button} from '@astryxdesign/core/Button'; import {Banner} from '@astryxdesign/core/Banner'; import {customerRepository} from '@/features/customers/repositories/customerRepository'; import type {Customer} from '@/features/customers/types/customer'; /** * Erase a customer — the right-to-be-forgotten path. Manager and above. * * Irreversible, so it asks for the customer number to be typed. What it does * is said plainly: the face and photo are destroyed; the visits stay as * anonymous footfall; the consent record stays, revoked. * * A failure is shown and never softened. The platform's 502 means the photo * could not be deleted and NOTHING was erased — telling the merchant otherwise * would leave them believing data is gone that is still there. */ export function EraseCustomerDialog({ customer, onClose, onErased, }: { customer: Customer; onClose: () => void; onErased: () => void; }) { const expected = customer.ref ?? customer.id; const [confirm, setConfirm] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function submit() { setBusy(true); setError(null); const res = await customerRepository.erase(customer.id); setBusy(false); if (!res.ok) { setError(res.message ?? 'Nothing was erased. Please try again.'); return; } onErased(); } return ( (open ? undefined : onClose())} purpose="required" width={460} aria-label="Erase customer" > (open ? undefined : onClose())} /> {error ? : null} ); }