From b08890dc9d43d1606019d69ae0e4bc5186f2d6e0 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 00:40:06 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/forms/itl-form.tsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/forms/itl-form.tsx b/src/components/forms/itl-form.tsx index f81ca7b..5586a98 100644 --- a/src/components/forms/itl-form.tsx +++ b/src/components/forms/itl-form.tsx @@ -56,10 +56,10 @@ export function ItlForm() { (parseFloat(adminFees) || 0) - (parseFloat(lessPayments) || 0); - const handleExport = () => { + const buildPdf = () => { if (!client || !template) { toast.error("Select a client first"); - return; + return null; } const returnAddress = [client.name]; @@ -87,7 +87,7 @@ export function ItlForm() { total, }); - const doc = renderLetterPdf({ + return renderLetterPdf({ template, returnAddress, topRightLine: tokens.date as string, @@ -98,13 +98,33 @@ export function ItlForm() { total: { label: labels.totalDue ?? "TOTAL DUE", amount: total }, filename: `ITL_${ownerFullName(homeowner) || "draft"}_${letterDate}`, }); + }; - const name = promptFilename(`ITL_${ownerFullName(homeowner) || "draft"}_${letterDate}`, "pdf"); + const defaultName = `ITL_${ownerFullName(homeowner) || "draft"}_${letterDate}`; + + const handleExport = () => { + const doc = buildPdf(); + if (!doc) return; + const name = promptFilename(defaultName, "pdf"); if (!name) return; doc.save(`${name}.pdf`); toast.success("ITL PDF downloaded"); }; + const handleSaveToCase = async ({ caseId, name, folder }: { caseId: string; name: string; folder: string }) => { + const doc = buildPdf(); + if (!doc) return; + const filename = name.endsWith(".pdf") ? name : `${name}.pdf`; + await savePdfToDocuments({ + blob: doc.output("blob"), + caseId, + name: filename, + folder, + mimeType: "application/pdf", + }); + toast.success("Saved to case files"); + }; + return (