diff --git a/src/components/forms/custom-form-builder.tsx b/src/components/forms/custom-form-builder.tsx index 1c52bb9..e8575d3 100644 --- a/src/components/forms/custom-form-builder.tsx +++ b/src/components/forms/custom-form-builder.tsx @@ -630,19 +630,22 @@ export function CustomFormBuilder() { ? AlignmentType.JUSTIFIED : AlignmentType.LEFT; const indentTwips = Math.round((seg.indent || 0) * 15); // ~px → twips (1px≈15twip) + const lines = applyVariables(seg.text, ctx).split("\n"); children.push( new DocxParagraph({ alignment: align, indent: indentTwips ? { left: indentTwips } : undefined, - children: [ - new TextRun({ - text: applyVariables(seg.text, ctx), + children: lines.flatMap((line, idx) => { + const run = new TextRun({ + text: line, font: fontFamily, size: fontSize * 2, italics: seg.caption, bold: !!seg.heading && seg.heading > 0, - }), - ], + break: idx > 0 ? 1 : undefined, + }); + return [run]; + }), }), ); } diff --git a/src/components/forms/form-field-defs-dialog.tsx b/src/components/forms/form-field-defs-dialog.tsx index d13f3cf..7e38423 100644 --- a/src/components/forms/form-field-defs-dialog.tsx +++ b/src/components/forms/form-field-defs-dialog.tsx @@ -33,6 +33,7 @@ const TYPE_LABEL: Record = { county: "Florida County", client: "Client / Association", homeowner: "Homeowner", + contact: "Contact (court, counsel, etc.)", }; function slug(s: string): string { diff --git a/src/components/forms/form-fields-fill-panel.tsx b/src/components/forms/form-fields-fill-panel.tsx index 307fcb3..2655d68 100644 --- a/src/components/forms/form-fields-fill-panel.tsx +++ b/src/components/forms/form-fields-fill-panel.tsx @@ -12,8 +12,11 @@ import { import { fetchClients, fetchHomeowners, + fetchContacts, + contactMailingLines, type ClientLite, type HomeownerLite, + type ContactLite, type FormFieldDef, } from "@/lib/forms-shared"; import { FL_COUNTIES } from "@/lib/florida"; @@ -29,14 +32,20 @@ export function FormFieldsFillPanel({ }) { const [clients, setClients] = useState([]); const [homeownersByClient, setHomeownersByClient] = useState>({}); + const [contacts, setContacts] = useState([]); // Track which client a homeowner field is filtered by (per-field-key) const [hoClientByField, setHoClientByField] = useState>({}); + // Track which contact id is selected per contact-field-key + const [contactIdByField, setContactIdByField] = useState>({}); useEffect(() => { if (fields.some((f) => f.type === "client" || f.type === "homeowner")) { fetchClients().then(setClients); } + if (fields.some((f) => f.type === "contact")) { + fetchContacts().then(setContacts); + } }, [fields]); const set = (key: string, v: string) => onChange({ ...values, [key]: v }); @@ -215,6 +224,43 @@ export function FormFieldsFillPanel({ ); } + if (f.type === "contact") { + const selectedId = contactIdByField[f.key] ?? ""; + const selected = contacts.find((c) => c.id === selectedId); + return ( +
+ {labelEl} + + {selected && ( +
+                  {contactMailingLines(selected).join("\n")}
+                
+ )} +
+ ); + } // text (default) return (
diff --git a/src/lib/forms-shared.ts b/src/lib/forms-shared.ts index 88bf9c1..61174a5 100644 --- a/src/lib/forms-shared.ts +++ b/src/lib/forms-shared.ts @@ -26,6 +26,45 @@ export interface HomeownerLite { opening_balance: number; } +export interface ContactLite { + id: string; + name: string; + contact_type: string; + company: string | null; + title: string | null; + address_line1: string | null; + address_line2: string | null; + city: string | null; + state: string | null; + postal_code: string | null; + email: string | null; + phone: string | null; +} + +export async function fetchContacts(): Promise { + const { data } = await supabase + .from("contacts") + .select( + "id,name,contact_type,company,title,address_line1,address_line2,city,state,postal_code,email,phone", + ) + .is("archived_at", null) + .order("name"); + return (data ?? []) as ContactLite[]; +} + +export function contactMailingLines(c: ContactLite | null | undefined): string[] { + if (!c) return []; + const lines: string[] = []; + if (c.name) lines.push(c.name); + if (c.title) lines.push(c.title); + if (c.company) lines.push(c.company); + if (c.address_line1) lines.push(c.address_line1); + if (c.address_line2) lines.push(c.address_line2); + const cityLine = [c.city, c.state, c.postal_code].filter(Boolean).join(", "); + if (cityLine) lines.push(cityLine); + return lines; +} + export async function fetchClients(): Promise { const { data } = await supabase .from("clients") @@ -144,7 +183,8 @@ export type FormFieldType = | "dropdown" | "county" | "client" - | "homeowner"; + | "homeowner" + | "contact"; export interface FormFieldDef { key: string;