Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
7f1e326dee
commit
a76d75d912
@@ -11,12 +11,14 @@ import {
|
||||
fmtCurrency,
|
||||
fmtDateLong,
|
||||
ownerFullName,
|
||||
savePdfToDocuments,
|
||||
type ClientLite,
|
||||
type HomeownerLite,
|
||||
type FirmInfo,
|
||||
} from "@/lib/forms-shared";
|
||||
import { buildLetterTokens, loadFormTemplate, renderLetterPdf, type FormTemplateConfig } from "@/lib/form-templates";
|
||||
import { promptFilename } from "@/lib/prompt-filename";
|
||||
import { SaveToCaseDialog } from "./save-to-case-dialog";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function ItfForm() {
|
||||
@@ -26,6 +28,7 @@ export function ItfForm() {
|
||||
const [homeownerId, setHomeownerId] = useState("");
|
||||
const [firm, setFirm] = useState<FirmInfo | null>(null);
|
||||
const [template, setTemplate] = useState<FormTemplateConfig | null>(null);
|
||||
const [saveToCaseOpen, setSaveToCaseOpen] = useState(false);
|
||||
|
||||
const [letterDate, setLetterDate] = useState(new Date().toISOString().slice(0, 10));
|
||||
const [certifiedNo, setCertifiedNo] = useState("");
|
||||
@@ -55,10 +58,10 @@ export function ItfForm() {
|
||||
(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];
|
||||
@@ -68,7 +71,6 @@ export function ItfForm() {
|
||||
const recipient: string[] = [ownerFullName(homeowner) || "[Homeowner]"];
|
||||
if (homeowner?.address) recipient.push(homeowner.address);
|
||||
|
||||
// Compose lien reference inline so users don't need to edit raw template.
|
||||
const lienRef =
|
||||
lienBookPage || lienRecordedDate
|
||||
? ` A Claim of Lien was recorded against the subject property${
|
||||
@@ -95,7 +97,7 @@ export function ItfForm() {
|
||||
extra: { lienRef },
|
||||
});
|
||||
|
||||
const doc = renderLetterPdf({
|
||||
return renderLetterPdf({
|
||||
template,
|
||||
returnAddress,
|
||||
topRightLine: tokens.date as string,
|
||||
@@ -106,13 +108,33 @@ export function ItfForm() {
|
||||
total: { label: labels.totalDue ?? "TOTAL DUE", amount: total },
|
||||
filename: `ITF_${ownerFullName(homeowner) || "draft"}_${letterDate}`,
|
||||
});
|
||||
};
|
||||
|
||||
const name = promptFilename(`ITF_${ownerFullName(homeowner) || "draft"}_${letterDate}`, "pdf");
|
||||
const defaultName = `ITF_${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("ITF 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 (
|
||||
<div className="space-y-4">
|
||||
<Card>
|
||||
|
||||
Reference in New Issue
Block a user