Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
7de0827070
commit
0e72b0d941
@@ -55,8 +55,8 @@ export function ImportUnbilledDialog({ open, onOpenChange, kind, caseId, clientI
|
||||
return;
|
||||
}
|
||||
const select = kind === "time"
|
||||
? "id, work_date, description, hours, hourly_rate, case_id, user:profiles!time_entries_user_id_fkey(full_name, email)"
|
||||
: "id, expense_date, description, amount, case_id, user:profiles!expenses_user_id_fkey(full_name, email)";
|
||||
? "id, work_date, description, hours, hourly_rate, case_id, user_id"
|
||||
: "id, expense_date, description, amount, case_id, user_id";
|
||||
const { data, error } = await supabase
|
||||
.from(table)
|
||||
.select(select)
|
||||
@@ -66,7 +66,18 @@ export function ImportUnbilledDialog({ open, onOpenChange, kind, caseId, clientI
|
||||
.order(dateCol, { ascending: false })
|
||||
.limit(1000);
|
||||
if (error) toast.error(error.message);
|
||||
setRows((data ?? []).map((r: any) => ({ ...r, _case: caseMap[r.case_id] })));
|
||||
const baseRows = (data ?? []) as any[];
|
||||
// Fetch users separately (no FK relationship between these tables and profiles).
|
||||
const userIds = Array.from(new Set(baseRows.map((r) => r.user_id).filter(Boolean)));
|
||||
let userMap: Record<string, any> = {};
|
||||
if (userIds.length) {
|
||||
const { data: profs } = await supabase
|
||||
.from("profiles")
|
||||
.select("id, full_name, email")
|
||||
.in("id", userIds);
|
||||
userMap = Object.fromEntries((profs ?? []).map((p: any) => [p.id, p]));
|
||||
}
|
||||
setRows(baseRows.map((r) => ({ ...r, _case: caseMap[r.case_id], user: r.user_id ? userMap[r.user_id] : null })));
|
||||
setLoading(false);
|
||||
})();
|
||||
}, [open, clientId, caseId, kind]);
|
||||
|
||||
Reference in New Issue
Block a user