From d59f0378f0f2f86793a30885c9e268a9c581cd1b Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 02:37:21 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/cases/invoices-tab.tsx | 51 ++++++++------------------- src/routeTree.gen.ts | 9 ----- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/src/components/cases/invoices-tab.tsx b/src/components/cases/invoices-tab.tsx index b6ed1db..a755064 100644 --- a/src/components/cases/invoices-tab.tsx +++ b/src/components/cases/invoices-tab.tsx @@ -4,17 +4,15 @@ import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { supabase } from "@/integrations/supabase/client"; -import { useAuth } from "@/lib/auth"; -import { FilePlus, Loader2 } from "lucide-react"; +import { FilePlus } from "lucide-react"; import { formatCurrency, formatDate, statusBadgeClass } from "@/lib/format"; -import { toast } from "sonner"; +import { GenerateInvoiceDialog } from "@/components/invoices/generate-invoice-dialog"; export function CaseInvoicesTab({ caseRecord }: { caseRecord: any }) { - const { user } = useAuth(); const [invoices, setInvoices] = useState([]); const [unbilledTime, setUnbilledTime] = useState([]); const [unbilledExpenses, setUnbilledExpenses] = useState([]); - const [generating, setGenerating] = useState(false); + const [genOpen, setGenOpen] = useState(false); const load = async () => { const [{ data: invs }, { data: t }, { data: ex }] = await Promise.all([ @@ -33,48 +31,19 @@ export function CaseInvoicesTab({ caseRecord }: { caseRecord: any }) { const expensesTotal = unbilledExpenses.reduce((s, e) => s + Number(e.amount), 0); const subtotal = timeTotal + expensesTotal; - const generate = async () => { - if (subtotal <= 0) { toast.error("Nothing to invoice"); return; } - setGenerating(true); - const yr = new Date().getFullYear(); - const num = `INV-${yr}-${Math.floor(1000 + Math.random() * 9000)}`; - const due = new Date(); due.setDate(due.getDate() + 30); - const { data: inv, error } = await supabase.from("invoices").insert({ - invoice_number: num, - client_id: caseRecord.client.id, - case_id: caseRecord.id, - status: "draft", - issue_date: new Date().toISOString().slice(0, 10), - due_date: due.toISOString().slice(0, 10), - subtotal, - tax: 0, - total: subtotal, - created_by: user?.id, - }).select("id").single(); - if (error || !inv) { toast.error(error?.message || "Failed"); setGenerating(false); return; } - // Link entries - const timeIds = unbilledTime.map((t) => t.id); - const expIds = unbilledExpenses.map((e) => e.id); - if (timeIds.length) await supabase.from("time_entries").update({ invoice_id: inv.id }).in("id", timeIds); - if (expIds.length) await supabase.from("expenses").update({ invoice_id: inv.id }).in("id", expIds); - setGenerating(false); - toast.success(`Invoice ${num} created (draft)`); - load(); - }; - return (
-
Unbilled work
+
Unbilled work on this case
{unbilledTime.length} time entries ยท {unbilledExpenses.length} expenses
{formatCurrency(subtotal)}
-
@@ -111,6 +80,14 @@ export function CaseInvoicesTab({ caseRecord }: { caseRecord: any }) {
+ +
); } diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index c896612..c19f0ac 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -616,12 +616,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> - } -}