"use client"; import { usePoll } from "@/lib/use-poll"; import type { ExpenseSummary } from "@/lib/types"; import { StatCard } from "@/components/stat-card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { DataTable, Column } from "@/components/data-table"; interface Transaction { id: string; date: string; vendor: string; amount: number; category: string; } export default function ExpensesPage() { const { data: summary } = usePoll( "/api/expenses/summary", 120000 ); const { data: transactions } = usePoll( "/api/expenses/transactions", 120000 ); const maxVendor = summary?.top_vendors.reduce( (max, v) => Math.max(max, v.amount), 0 ) ?? 1; const txColumns: Column[] = [ { key: "date", label: "Date" }, { key: "vendor", label: "Vendor", render: (row) => ( {row.vendor} ), }, { key: "amount", label: "Amount", render: (row) => ( ${row.amount.toFixed(2)} ), }, { key: "category", label: "Category" }, ]; const categories = transactions ? [...new Set(transactions.map((t) => t.category))] : []; return (

Expenses

{/* Summary Cards */}
{/* Top Vendors Bar Chart */} Top Vendors {!summary ? (

Loading...

) : (
{summary.top_vendors.map((v) => (
{v.vendor} ${v.amount.toFixed(2)}
))}
)} {/* Transactions Table */} Transactions data={transactions ?? []} columns={txColumns} searchKey="vendor" filterKey="category" filterOptions={categories} />
); }