"use client"; import Link from "next/link"; import { api } from "~/trpc/react"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; import { Button } from "~/components/ui/button"; import { Badge } from "~/components/ui/badge"; import { Skeleton } from "~/components/ui/skeleton"; import { FileText, Clock, Plus, Edit, Eye, DollarSign, User, Calendar, } from "lucide-react"; export function CurrentOpenInvoiceCard() { const { data: currentInvoice, isLoading } = api.invoices.getCurrentOpen.useQuery(); const formatCurrency = (amount: number) => { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", }).format(amount); }; const formatDate = (date: Date) => { return new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", }).format(new Date(date)); }; if (isLoading) { return ( Current Open Invoice
); } if (!currentInvoice) { return ( Current Open Invoice

No open invoice found. Create a new invoice to start tracking your time.

); } const totalHours = currentInvoice.items?.reduce((sum, item) => sum + item.hours, 0) ?? 0; const totalAmount = currentInvoice.totalAmount; return ( Current Open Invoice
{currentInvoice.invoiceNumber} Draft

{formatCurrency(totalAmount)}

Client: {currentInvoice.client?.name}
Due: {formatDate(currentInvoice.dueDate)}
Hours: {totalHours.toFixed(1)}h
); }