diff --git a/src/components/cases/status-tab.tsx b/src/components/cases/status-tab.tsx index e171365..d5bd569 100644 --- a/src/components/cases/status-tab.tsx +++ b/src/components/cases/status-tab.tsx @@ -23,12 +23,19 @@ export function CaseStatusTab({ caseId }: { caseId: string }) { const [form, setForm] = useState({ title: nowLocal(), body: "" }); const load = async () => { - const { data } = await supabase + const { data, error } = await supabase .from("status_updates") - .select("*, user:profiles!status_updates_created_by_fkey(full_name, email)") + .select("*") .eq("case_id", caseId) .order("created_at", { ascending: false }); - setItems(data ?? []); + if (error) { toast.error("Could not load updates", { description: error.message }); return; } + const ids = Array.from(new Set((data ?? []).map((d: any) => d.created_by).filter(Boolean))); + let profileMap: Record = {}; + if (ids.length) { + const { data: profs } = await supabase.from("profiles").select("id, full_name, email").in("id", ids); + profileMap = Object.fromEntries((profs ?? []).map((p: any) => [p.id, p])); + } + setItems((data ?? []).map((d: any) => ({ ...d, user: d.created_by ? profileMap[d.created_by] : null }))); }; useEffect(() => { load(); }, [caseId]);