// src/pages/DashboardPage/BillingPage/RecordPaymentModal.tsx // Staff record a payment taken outside Akashic (cash, check, a card terminal). Built like // InvoiceStatusModal: a raw confirm button keeps the dialog open while submitting and on error. import { useEffect, useState } from 'react'; import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, } from '../../../components/ui/alert-dialog'; import { Input } from '../../../components/ui/input'; import { parsePartialPayAmount } from '../../../utils/paymentFlow'; import { formatMoney } from '../../../utils/money'; export type RecordPaymentModalProps = { open: boolean; onOpenChange: (open: boolean) => void; remainingCents: number; /** Set while an earlier attempt's outcome is unknown: the retry must send the same amount. */ lockedCents?: number; allowPartialPay: boolean; submitting?: boolean; error?: string; onConfirm: (amountCents: number) => void; }; const RecordPaymentModal = ({ open, onOpenChange, remainingCents, lockedCents, allowPartialPay, submitting, error, onConfirm, }: RecordPaymentModalProps) => { const [amountText, setAmountText] = useState(''); const [touched, setTouched] = useState(false); useEffect(() => { if (open) { setAmountText((remainingCents / 100).toFixed(2)); setTouched(false); } }, [open, remainingCents]); const locked = lockedCents !== undefined; const validation = locked ? { ok: true as const, cents: lockedCents } : allowPartialPay ? parsePartialPayAmount(amountText, remainingCents) : { ok: true as const, cents: remainingCents }; const owed = formatMoney(remainingCents); return ( Record a payment? {allowPartialPay ? 'For a payment taken outside Akashic. ' + owed + ' is still owed.' : 'For a payment taken outside Akashic. This invoice takes no part payments, so this records the ' + owed + ' still owed.'} {allowPartialPay && (
$ { setAmountText(event.target.value); setTouched(true); }} />
{touched && !validation.ok && ( {validation.error} )}
)} {error &&
{error}
} Not now
); }; export default RecordPaymentModal;