Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 01:34:47 +00:00
co-authored by renee-png
parent 59a889d5ab
commit 5dbc839ebe
2 changed files with 48 additions and 1 deletions
+27 -1
View File
@@ -78,9 +78,29 @@ export const SYSTEM_VARIABLES = [
{ key: "{{firmName}}", description: "Your firm name" },
] as const;
export interface CustomFieldVar {
key: string;
label: string;
description: string | null;
}
export async function fetchCustomFieldDefs(): Promise<CustomFieldVar[]> {
const { data } = await supabase
.from("custom_case_fields")
.select("key,label,description")
.eq("active", true)
.order("sort_order");
return (data ?? []) as CustomFieldVar[];
}
export function applyVariables(
body: string,
ctx: { client?: ClientLite | null; homeowner?: HomeownerLite | null; firmName?: string },
ctx: {
client?: ClientLite | null;
homeowner?: HomeownerLite | null;
firmName?: string;
customValues?: Record<string, string>;
},
): string {
const today = format(new Date(), "MMMM d, yyyy");
const replacements: Record<string, string> = {
@@ -97,6 +117,12 @@ export function applyVariables(
for (const [k, v] of Object.entries(replacements)) {
out = out.split(k).join(v);
}
// Custom variables like {{custom.mortgage_holder}}
if (ctx.customValues) {
for (const [k, v] of Object.entries(ctx.customValues)) {
out = out.split(`{{custom.${k}}}`).join(v ?? "");
}
}
return out;
}