From 3babc82cba7151cf41bccb8127772619a8a64b54 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 04:02:09 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/routes/settings.import.tsx | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index 3045073..16b271c 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -685,10 +685,49 @@ function ImportPage() { if (cfg.postInsert) cfg.postInsert(inserted_rows, ctx); + // Mirror imported "client" contacts into the clients table so they appear on the Clients page. + let mirrored = 0; + if (cfg.key === "contacts" && contactGroup === "client" && inserted_rows.length > 0) { + const clientRows = inserted_rows + .filter((c) => c.external_id || c.name) + .map((c) => ({ + external_id: c.external_id ?? null, + name: c.name || c.company || "Unnamed client", + client_type: "hoa" as const, + primary_contact_email: c.email ?? null, + primary_contact_phone: c.phone ?? null, + primary_contact_name: c.name ?? null, + address_line1: c.address_line1 ?? null, + address_line2: c.address_line2 ?? null, + city: c.city ?? null, + state: c.state ?? null, + postal_code: c.postal_code ?? null, + notes: c.notes ?? null, + created_by: user.id, + })); + const withExt = clientRows.filter((r) => r.external_id); + const withoutExt = clientRows.filter((r) => !r.external_id); + if (withExt.length > 0) { + const { data, error } = await supabase + .from("clients") + .upsert(withExt, { onConflict: "external_id", ignoreDuplicates: false }) + .select("id"); + if (error) errors.push(`Client mirror (upsert): ${error.message}`); + else mirrored += data?.length ?? 0; + } + if (withoutExt.length > 0) { + const { data, error } = await supabase.from("clients").insert(withoutExt).select("id"); + if (error) errors.push(`Client mirror (insert): ${error.message}`); + else mirrored += data?.length ?? 0; + } + } + const summary = { total: rawRows.length, inserted, skipped, errors, skipReasons }; setResults((r) => ({ ...r, [cfg.key]: summary })); - if (errors.length === 0) toast.success(`${cfg.label}: ${inserted} imported`); - else toast.error(`${cfg.label}: ${errors.length} batch error(s)`); + if (errors.length === 0) { + const extra = mirrored > 0 ? ` (+${mirrored} mirrored to Clients)` : ""; + toast.success(`${cfg.label}: ${inserted} imported${extra}`); + } else toast.error(`${cfg.label}: ${errors.length} batch error(s)`); }; return (