Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
59a889d5ab
commit
5dbc839ebe
+27
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user