Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 02:04:41 +00:00
co-authored by renee-png
parent 6b56628dd8
commit 00c484d102
+29 -1
View File
@@ -102,6 +102,7 @@ export function applyVariables(
homeowner?: HomeownerLite | null;
firmName?: string;
customValues?: Record<string, string>;
fieldValues?: Record<string, string>;
},
): string {
const today = format(new Date(), "MMMM d, yyyy");
@@ -119,15 +120,42 @@ export function applyVariables(
for (const [k, v] of Object.entries(replacements)) {
out = out.split(k).join(v);
}
// Custom variables like {{custom.mortgage_holder}}
// Custom case-field variables like {{custom.mortgage_holder}}
if (ctx.customValues) {
for (const [k, v] of Object.entries(ctx.customValues)) {
out = out.split(`{{custom.${k}}}`).join(v ?? "");
}
}
// Per-form fillable fields like {{field.tenant_name}}
if (ctx.fieldValues) {
for (const [k, v] of Object.entries(ctx.fieldValues)) {
out = out.split(`{{field.${k}}}`).join(v ?? "");
}
}
return out;
}
// ---------- Per-template fillable fields ----------
export type FormFieldType =
| "text"
| "textarea"
| "number"
| "date"
| "dropdown"
| "county"
| "client"
| "homeowner";
export interface FormFieldDef {
key: string;
label: string;
type: FormFieldType;
required?: boolean;
options?: string[]; // for dropdown
placeholder?: string;
default?: string;
}
export function fmtCurrency(n: number | string | null | undefined): string {
const v = typeof n === "string" ? parseFloat(n) : (n ?? 0);
return (Number.isFinite(v) ? v : 0).toLocaleString("en-US", {