Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-17 02:09:53 +00:00
co-authored by renee-png
parent 28629222ea
commit 982f17fb82
+11 -4
View File
@@ -17,7 +17,7 @@ interface CaseTimeTabProps {
onInvoice?: () => void;
}
export function CaseTimeTab({ caseRecord }: { caseRecord: any }) {
export function CaseTimeTab({ caseRecord, onInvoice }: CaseTimeTabProps) {
const { user } = useAuth();
const [entries, setEntries] = useState<any[]>([]);
const [showForm, setShowForm] = useState(false);
@@ -32,12 +32,19 @@ export function CaseTimeTab({ caseRecord }: { caseRecord: any }) {
});
const load = async () => {
const { data } = await supabase
const { data, error } = await supabase
.from("time_entries")
.select("*, user:profiles!time_entries_user_id_fkey(full_name, email)")
.select("*")
.eq("case_id", caseRecord.id)
.order("work_date", { ascending: false });
setEntries(data ?? []);
if (error) { toast.error("Could not load time entries", { description: error.message }); return; }
const ids = Array.from(new Set((data ?? []).map((d: any) => d.user_id).filter(Boolean)));
let profileMap: Record<string, any> = {};
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]));
}
setEntries((data ?? []).map((d: any) => ({ ...d, user: d.user_id ? profileMap[d.user_id] : null })));
};
useEffect(() => { load(); }, [caseRecord.id]);