diff --git a/client/src/pages/InvoiceDetailPage.tsx b/client/src/pages/InvoiceDetailPage.tsx index 8e9685b..703612d 100644 --- a/client/src/pages/InvoiceDetailPage.tsx +++ b/client/src/pages/InvoiceDetailPage.tsx @@ -87,6 +87,7 @@ export function InvoiceDetailPage() { const [downloadLoading, setDownloadLoading] = useState(false); const [downloaded, setDownloaded] = useState(false); const [gmailLoading, setGmailLoading] = useState(false); + const [statusLoading, setStatusLoading] = useState(null); const [copied, setCopied] = useState(false); const [toast, setToast] = useState(null); const [error, setError] = useState(null); @@ -176,6 +177,25 @@ export function InvoiceDetailPage() { } }; + const handleStatusUpdate = async (status: Extract) => { + if (!invoice) { + return; + } + + try { + setStatusLoading(status); + const updatedInvoice = await invoicesApi.updateStatus(invoice.id, status); + setInvoice(updatedInvoice); + setToast(status === "SENT" ? "Invoice marked as sent." : "Invoice marked as paid."); + setError(null); + } catch (error) { + setError(getApiErrorMessage(error, `Failed to mark invoice as ${status.toLowerCase()}`)); + console.error("Error updating invoice status:", error); + } finally { + setStatusLoading(null); + } + }; + useEffect(() => { const handler = (event: KeyboardEvent) => { const target = event.target as HTMLElement | null; @@ -270,6 +290,26 @@ export function InvoiceDetailPage() { Open in Gmail ) : null} + {invoice.status === "DRAFT" ? ( + + ) : null} + {invoice.status === "SENT" || invoice.status === "OVERDUE" ? ( + + ) : null}