From 53adf807c9669c735d1126a03e6b3324717463fa Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 02:14:06 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/lib/forms-shared.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/lib/forms-shared.ts b/src/lib/forms-shared.ts index 88bf9c1..153548e 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")