"use client"; import { Calendar, Clock, Edit, Eye, FileText, Plus, User } from "lucide-react"; import Link from "next/link"; import { Badge } from "~/components/ui/badge"; import { Button } from "~/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; import { Skeleton } from "~/components/ui/skeleton"; import { api } from "~/trpc/react"; import { formatCalendarDate } from "@beenvoice/domain/time-zone"; 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 formatCalendarDate(date, { month: "short", day: "numeric", }); }; 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. Create New Invoice ); } 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 View Continue ); }
No open invoice found. Create a new invoice to start tracking your time.
{formatCurrency(totalAmount)}