From 95fc6ace13cee19dee4578f0479e8d137e173ddb Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 17:39:16 +0000 Subject: [PATCH 1/3] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/routes/settings.import.tsx | 35 +++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index bf92579..049e46e 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -190,27 +190,48 @@ const IMPORTERS: ImporterConfig[] = [ conflict: "external_id", required: ["case_number", "title", "client_id"], aliases: { - id: "external_id", caseid: "external_id", externalid: "external_id", + id: "external_id", caseid: "external_id", externalid: "external_id", mycaseid: "external_id", casenumber: "case_number", number: "case_number", mattercode: "case_number", + caseno: "case_number", casenum: "case_number", name: "title", title: "title", mattername: "title", - companyid: "_clientext", clientid: "_clientext", company: "_clientname", client: "_clientname", - description: "description", summary: "case_summary", casesummary: "case_summary", + casemattername: "title", casename: "title", + companyid: "_clientext", clientid: "_clientext", + clientno: "_clientext", clientnumber: "_clientext", + company: "_clientname", client: "_clientname", + communityassociation: "_clientname", associationname: "_clientname", + managementcompany: "_clientname", + description: "description", casedescription: "description", + summary: "case_summary", casesummary: "case_summary", practicearea: "practice_area", area: "practice_area", - status: "status", - opened: "opened_at", openedat: "opened_at", dateopened: "opened_at", - closed: "closed_at", closedat: "closed_at", dateclosed: "closed_at", + caseinquirytype: "practice_area", representation: "practice_area", + associationtype: "practice_area", + status: "status", casestage: "status", + opened: "opened_at", openedat: "opened_at", dateopened: "opened_at", opendate: "opened_at", + closed: "closed_at", closedat: "closed_at", dateclosed: "closed_at", closeddate: "closed_at", + caseclosed: "_closedflag", court: "court", judge: "judge", jurisdiction: "jurisdiction", + district: "jurisdiction", county: "jurisdiction", countylocation: "jurisdiction", + courtinformation: "court", primarycaselocation: "court", caseCaption: "case_caption", caption: "case_caption", courtcasenumber: "court_case_number", filingdate: "filing_date", nexthearing: "next_hearing_date", nexthearingdate: "next_hearing_date", + pretrialconference: "next_hearing_date", trial: "next_hearing_date", opposingparty: "opposing_party", - opposingcounsel: "opposing_counsel", + defendants: "opposing_party", plaintiffs: "opposing_party", + opposingcounsel: "opposing_counsel", opposingcounsels: "opposing_counsel", opposingcounselfirm: "opposing_counsel_firm", opposingcounselemail: "opposing_counsel_email", opposingcounselphone: "opposing_counsel_phone", + leadattorney: "_assignedname", originatingattorney: "_originatingname", claimamount: "claim_amount", settlementamount: "settlement_amount", + outstandingbalance: "claim_amount", + casebalance: "claim_amount", ledgerbalance: "claim_amount", + totaldue: "claim_amount", duetofirm: "claim_amount", hourlyrate: "default_hourly_rate", rate: "default_hourly_rate", + flatfee: "flat_fee_amount", + billingtype: "billing_method", + soldate: "statute_of_limitations", archived: "_archived", isarchived: "_archived", }, numeric: ["claim_amount", "settlement_amount", "default_hourly_rate"], From 750b41e8cd6cb201c6cfabe9978186fd671e7fc4 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 17:39:34 +0000 Subject: [PATCH 2/3] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/routes/settings.import.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index 049e46e..edb52cd 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -234,16 +234,28 @@ const IMPORTERS: ImporterConfig[] = [ soldate: "statute_of_limitations", archived: "_archived", isarchived: "_archived", }, - numeric: ["claim_amount", "settlement_amount", "default_hourly_rate"], + numeric: ["claim_amount", "settlement_amount", "default_hourly_rate", "flat_fee_amount"], dateCols: ["opened_at", "closed_at", "filing_date", "next_hearing_date", "statute_of_limitations"], transform: (r, ctx) => { const cid = r._clientext ? ctx.clientByExt.get(String(r._clientext)) : null; const cidByName = r._clientname ? ctx.clientByName.get(String(r._clientname).toLowerCase()) : null; r.client_id = cid ?? cidByName ?? null; delete r._clientext; delete r._clientname; + delete r._assignedname; delete r._originatingname; if (!r.client_id) return null; + const closedFlag = String(r._closedflag ?? "").toLowerCase(); + delete r._closedflag; const s = String(r.status ?? "").toLowerCase(); - r.status = s.includes("close") ? "closed" : s.includes("hold") ? "on_hold" : s.includes("intake") ? "intake" : "active"; + if (closedFlag === "yes" || closedFlag === "true" || closedFlag === "1") { + r.status = "closed"; + } else { + r.status = s.includes("close") ? "closed" : s.includes("hold") ? "on_hold" : s.includes("intake") ? "intake" : "active"; + } + // Normalise billing method + if (r.billing_method) { + const bm = String(r.billing_method).toLowerCase(); + r.billing_method = bm.includes("flat") ? "flat" : bm.includes("contingency") ? "contingency" : bm.includes("hour") ? "hourly" : null; + } if (!r.case_number) r.case_number = `CASE-${Date.now()}-${Math.floor(Math.random() * 1000)}`; if (!r.title) r.title = r.case_number; return r; From b552ab33b41e70c6031d41e4cbe24e908cf5e998 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 17:39:50 +0000 Subject: [PATCH 3/3] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/routes/settings.import.tsx | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index edb52cd..6147976 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -1096,15 +1096,34 @@ function ImportPage() { } } if (withoutConflict.length > 0) { - const { data, error } = await supabase - .from(cfg.table as any) - .insert(withoutConflict as any) - .select("*"); - if (error) { - errors.push(`Batch ${i / chunkSize + 1} (insert): ${error.message}`); - } else if (data) { - inserted += data.length; - inserted_rows.push(...data); + // For cases without external_id, upsert on case_number to avoid duplicate-key errors on re-import + if (cfg.table === "cases") { + const withCaseNum = withoutConflict.filter((r) => r.case_number); + const noCaseNum = withoutConflict.filter((r) => !r.case_number); + if (withCaseNum.length > 0) { + const { data, error } = await supabase + .from("cases" as any) + .upsert(withCaseNum as any, { onConflict: "case_number", ignoreDuplicates: false }) + .select("*"); + if (error) errors.push(`Batch ${i / chunkSize + 1} (upsert case_number): ${error.message}`); + else if (data) { inserted += data.length; inserted_rows.push(...(data as Row[])); } + } + if (noCaseNum.length > 0) { + const { data, error } = await supabase.from("cases" as any).insert(noCaseNum as any).select("*"); + if (error) errors.push(`Batch ${i / chunkSize + 1} (insert): ${error.message}`); + else if (data) { inserted += data.length; inserted_rows.push(...(data as Row[])); } + } + } else { + const { data, error } = await supabase + .from(cfg.table as any) + .insert(withoutConflict as any) + .select("*"); + if (error) { + errors.push(`Batch ${i / chunkSize + 1} (insert): ${error.message}`); + } else if (data) { + inserted += data.length; + inserted_rows.push(...data); + } } } }