diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 2c230ca..94db69b 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -1046,12 +1046,3 @@ const rootRouteChildren: RootRouteChildren = { export const routeTree = rootRouteImport ._addFileChildren(rootRouteChildren) ._addFileTypes() - -import type { getRouter } from './router.tsx' -import type { createStart } from '@tanstack/react-start' -declare module '@tanstack/react-start' { - interface Register { - ssr: true - router: Awaited> - } -} diff --git a/src/routes/invoices.index.tsx b/src/routes/invoices.index.tsx index de93113..79c5630 100644 --- a/src/routes/invoices.index.tsx +++ b/src/routes/invoices.index.tsx @@ -116,11 +116,11 @@ function InvoicesIndex() { const loadUnbilled = async () => { try { setTabsLoaded(false); - const [t, e] = await Promise.all([ + const [timeRows, expenseRows] = await Promise.all([ fetchAllPages(async (from, to) => { const result = await supabase .from("time_entries") - .select("id, work_date, description, hours, hourly_rate, billable, user_id, invoice_id, case_id, case:cases(id, case_number, title, client_id, client:clients(id, name)), profile:profiles!time_entries_user_id_fkey(id, full_name, email)") + .select("id, work_date, description, hours, hourly_rate, billable, user_id, invoice_id, case_id, case:cases(id, case_number, title, client_id, client:clients(id, name))") .eq("billable", true) .order("work_date", { ascending: false }) .range(from, to); @@ -129,15 +129,31 @@ function InvoicesIndex() { fetchAllPages(async (from, to) => { const result = await supabase .from("expenses") - .select("id, expense_date, description, amount, billable, user_id, invoice_id, case_id, case:cases(id, case_number, title, client_id, client:clients(id, name)), profile:profiles!expenses_user_id_fkey(id, full_name, email)") + .select("id, expense_date, description, amount, billable, user_id, invoice_id, case_id, case:cases(id, case_number, title, client_id, client:clients(id, name))") .eq("billable", true) .order("expense_date", { ascending: false }) .range(from, to); return { data: result.data, error: result.error ? { message: result.error.message } : null }; }), ]); - setTime(t); - setExpenses(e); + + const userIds = Array.from(new Set([ + ...timeRows.map((row) => row.user_id).filter(Boolean), + ...expenseRows.map((row) => row.user_id).filter(Boolean), + ])); + + let profileMap: Record = {}; + if (userIds.length) { + const { data: profiles, error: profilesError } = await supabase + .from("profiles") + .select("id, full_name, email") + .in("id", userIds); + if (profilesError) throw new Error(profilesError.message); + profileMap = Object.fromEntries((profiles ?? []).map((profile: any) => [profile.id, profile])); + } + + setTime(timeRows.map((row) => ({ ...row, profile: row.user_id ? profileMap[row.user_id] ?? null : null }))); + setExpenses(expenseRows.map((row) => ({ ...row, profile: row.user_id ? profileMap[row.user_id] ?? null : null }))); } catch (error: any) { toast.error(error?.message ?? "Could not load unbilled items"); setTime([]);