Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 23:33:55 +00:00
co-authored by renee-png
parent 0cf7ad4d98
commit 6250d24abf
+35 -8
View File
@@ -847,12 +847,35 @@ function BucketCell({ value, danger, positive }: { value: number; danger?: boole
}
// Extract defendant surname from a case title like
// "Corner Lake Estates HOA v Benitez [2074 Corner Glen Drive]"
function extractDefendantSurname(title: string): string | null {
if (!title) return null;
// Match " v " or " v. " or " vs " (case-insensitive)
const m = title.match(/\sv\.?s?\.?\s+([A-Za-z'’\-]+)/i);
if (!m) return null;
return m[1].trim().toLowerCase();
}
function findUniqueHomeownerByTitle(
title: string,
homeowners: any[],
): any | null {
const surname = extractDefendantSurname(title);
if (!surname) return null;
const matches = homeowners.filter(
(h) => (h.last_name || "").toLowerCase() === surname,
);
return matches.length === 1 ? matches[0] : null;
}
// ─── Add collection dialog ──────────────────────────────────────────
function AddCollectionDialog({
open,
onOpenChange,
caseId,
clientId,
caseTitle,
homeowners,
existingHomeownerIds,
onCreated,
@@ -861,6 +884,7 @@ function AddCollectionDialog({
onOpenChange: (v: boolean) => void;
caseId: string;
clientId: string;
caseTitle: string;
homeowners: any[];
existingHomeownerIds: string[];
onCreated: () => void;
@@ -871,18 +895,21 @@ function AddCollectionDialog({
const [notes, setNotes] = useState("");
const [submitting, setSubmitting] = useState(false);
useEffect(() => {
if (open) {
setHomeownerId("");
setStatus("none");
setNotes("");
}
}, [open]);
const available = homeowners.filter(
(h) => !existingHomeownerIds.includes(h.id),
);
useEffect(() => {
if (open) {
// Try to pre-select a homeowner whose surname matches the case title
const match = findUniqueHomeownerByTitle(caseTitle, available);
setHomeownerId(match ? match.id : "");
setStatus("none");
setNotes("");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open, caseTitle]);
const submit = async () => {
if (!homeownerId) {
toast.error("Pick a homeowner");