diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 86ec365..dba1b98 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -9,7 +9,7 @@ import { supabase } from "@/integrations/supabase/client"; import { useAuth } from "@/lib/auth"; import { Briefcase, Receipt, Clock, ArrowRight, CalendarDays, FileText, - CheckSquare, UserPlus, DollarSign, Wallet, AlertCircle, + CheckSquare, UserPlus, DollarSign, Wallet, AlertCircle, CreditCard, } from "lucide-react"; import { formatCurrency, formatDate, statusBadgeClass } from "@/lib/format"; import { format, startOfDay, startOfMonth, endOfMonth, subDays } from "date-fns"; @@ -47,6 +47,7 @@ function Dashboard() { const [todaysEvents, setTodaysEvents] = useState([]); const [recentCases, setRecentCases] = useState([]); const [recentInvoices, setRecentInvoices] = useState([]); + const [recentPayments, setRecentPayments] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { @@ -64,7 +65,7 @@ function Dashboard() { myAssigneeRes, openCasesRes, newCasesRes, closedCasesRes, tasksTodayRes, hearingsTodayRes, - recentCasesRes, recentInvRes, + recentCasesRes, recentInvRes, recentPayRes, ] = await Promise.all([ supabase.from("trust_ledger_entries").select("entry_type, amount"), supabase.from("invoice_payments").select("amount, paid_on").gte("paid_on", monthStart).lte("paid_on", monthEnd), @@ -77,6 +78,7 @@ function Dashboard() { supabase.from("cases").select("id, title, case_number, next_hearing_date, next_hearing_notes").eq("next_hearing_date", todayStr), supabase.from("cases").select("id, case_number, title, status, updated_at, client:clients(name)").order("updated_at", { ascending: false }).limit(5), supabase.from("invoices").select("id, invoice_number, total, status, issue_date, client:clients(name)").order("created_at", { ascending: false }).limit(5), + supabase.from("payment_requests").select("id, recipient_name, description, total_amount_cents, status, created_at, paid_at").order("created_at", { ascending: false }).limit(5), ]); // Trust balance @@ -132,6 +134,7 @@ function Dashboard() { setTodaysEvents(evts); setRecentCases(recentCasesRes.data ?? []); setRecentInvoices(recentInvRes.data ?? []); + setRecentPayments(recentPayRes.data ?? []); setLoading(false); })(); }, [user?.id]); @@ -313,6 +316,39 @@ function Dashboard() { + + {/* Recent payments */} +
+ + + + + Recent payments + + + + + {recentPayments.length === 0 &&

No payment requests yet.

} + {recentPayments.map((p) => ( + +
+
{p.recipient_name}
+
+ {p.description || "Payment request"} ยท {formatDate(p.paid_at || p.created_at)} +
+
+
+ {formatCurrency((p.total_amount_cents ?? 0) / 100)} + {p.status} +
+ + ))} +
+
+
); }