diff --git a/src/routes/documents.pleading.new.tsx b/src/routes/documents.pleading.new.tsx index 14d1807..df671d2 100644 --- a/src/routes/documents.pleading.new.tsx +++ b/src/routes/documents.pleading.new.tsx @@ -195,7 +195,38 @@ function PleadingNewPage() { if (c && !c.counties.includes(county)) setCounty(c.counties[0]); }; + const varMap = useMemo(() => buildVarMap(varCtx), [varCtx]); + const sub = (s: string) => applyVars(s, varMap); + const subFootnotes = (fns: PleadingFootnote[]) => fns.map((f) => ({ ...f, text: sub(f.text) })); + const subServiceList = (list: ServiceContact[]) => + list.map((c) => ({ + ...c, + name: sub(c.name), + role: c.role ? sub(c.role) : c.role, + company: c.company ? sub(c.company) : c.company, + email: c.email ? sub(c.email) : c.email, + phone: c.phone ? sub(c.phone) : c.phone, + address: c.address ? sub(c.address) : c.address, + })); + const input = { + courtType, circuit, county, + plaintiffs: sub(plaintiffs), + defendants: sub(defendants), + caseNumber: sub(caseNumber), + title: sub(title), + bodyHtml: sub(bodyHtml), + footnotes: subFootnotes(footnotes), + footerLeft: sub(footerLeft), + footerCenter: sub(footerCenter), + footerRight: sub(footerRight), + signature: buildSignature(), + serviceList: subServiceList(serviceList), + serviceListTitle: sub(serviceListTitle), + }; + + // Raw input (no substitution) for saving the source so tokens persist + const rawInput = { courtType, circuit, county, plaintiffs, defendants, caseNumber, title, bodyHtml, footnotes, @@ -203,6 +234,8 @@ function PleadingNewPage() { signature: buildSignature(), serviceList, serviceListTitle, + clientId: clientId || null, + caseId: caseId || null, }; const headerLine1 = `IN THE ${courtType} COURT OF THE ${circuit} JUDICIAL CIRCUIT,`;