Invoice History
An invoices table with status filter pills, status badges, per-row download buttons and a CSV export.
"use client"
import { useState } from "react"
import { DownloadSimpleIcon } from "@phosphor-icons/react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
Card,
CardAction,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
const COPY = {
title: "Invoices",
description: "Every charge to your workspace, newest first.",
export: "Export CSV",
empty: "No invoices with this status.",
} as const
const FILTERS = ["All", "Paid", "Open", "Failed"] as const
const INVOICES = [
{ id: "INV-2041", date: "Nov 1, 2026", amount: "$348.00", status: "Open" },
{ id: "INV-2036", date: "Oct 1, 2026", amount: "$348.00", status: "Paid" },
{ id: "INV-2029", date: "Sep 1, 2026", amount: "$312.50", status: "Paid" },
{ id: "INV-2022", date: "Aug 1, 2026", amount: "$312.50", status: "Failed" },
{ id: "INV-2015", date: "Jul 1, 2026", amount: "$290.00", status: "Paid" },
{ id: "INV-2008", date: "Jun 1, 2026", amount: "$290.00", status: "Paid" },
] as const
type Invoice = (typeof INVOICES)[number]
// Builds a CSV from the given rows and downloads it through a temporary anchor.
function downloadCsv(name: string, list: readonly Invoice[]) {
const lines = [
["Invoice", "Date", "Status", "Amount"],
...list.map((r) => [r.id, r.date, r.status, r.amount]),
].map((cells) => cells.map((c) => `"${c}"`).join(","))
const url = URL.createObjectURL(
new Blob([lines.join("\n")], { type: "text/csv" })
)
const a = document.createElement("a")
a.href = url
a.download = name
a.click()
URL.revokeObjectURL(url)
}
export default function BillingInvoiceTable() {
const [filter, setFilter] = useState<(typeof FILTERS)[number]>("All")
const rows = INVOICES.filter(
(row) => filter === "All" || row.status === filter
)
return (
<Card className="mx-auto w-full max-w-3xl">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
<CardDescription>{COPY.description}</CardDescription>
<CardAction>
<Button
variant="outline"
size="sm"
disabled={rows.length === 0}
onClick={() => downloadCsv("invoices.csv", rows)}
>
<DownloadSimpleIcon data-icon="inline-start" />
{COPY.export}
</Button>
</CardAction>
</CardHeader>
<CardContent className="flex flex-col gap-4">
<div className="flex w-fit rounded-full bg-muted p-0.5 text-sm">
{FILTERS.map((item) => (
<button
key={item}
type="button"
aria-pressed={filter === item}
onClick={() => setFilter(item)}
className="rounded-full px-3 py-1 text-muted-foreground aria-pressed:bg-background aria-pressed:text-foreground aria-pressed:shadow-sm"
>
{item}
</button>
))}
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Date</TableHead>
<TableHead>Status</TableHead>
<TableHead className="text-right">Amount</TableHead>
<TableHead className="w-10" />
</TableRow>
</TableHeader>
<TableBody>
{rows.map((row) => (
<TableRow key={row.id}>
<TableCell className="font-medium">{row.id}</TableCell>
<TableCell className="text-muted-foreground">
{row.date}
</TableCell>
<TableCell>
<StatusBadge status={row.status} />
</TableCell>
<TableCell className="text-right tabular-nums">
{row.amount}
</TableCell>
<TableCell>
<Button
variant="ghost"
size="icon-sm"
aria-label={`Download ${row.id}`}
onClick={() => downloadCsv(`${row.id}.csv`, [row])}
>
<DownloadSimpleIcon />
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
{rows.length === 0 && (
<p className="py-6 text-center text-sm text-muted-foreground">
{COPY.empty}
</p>
)}
</CardContent>
</Card>
)
}
function StatusBadge({ status }: { status: string }) {
if (status === "Paid") return <Badge variant="secondary">Paid</Badge>
if (status === "Failed") return <Badge variant="destructive">Failed</Badge>
return <Badge variant="outline">Open</Badge>
}
Installation
pnpm dlx shadcn@latest add @01orbital/billing-invoices-01npx shadcn@latest add @01orbital/billing-invoices-01yarn dlx shadcn@latest add @01orbital/billing-invoices-01bunx --bun shadcn@latest add @01orbital/billing-invoices-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/billing/billing-invoices-01/index.tsx: change them there, not in the markup. FILTERSandINVOICES, also at the top of the file, hold its lists and settings.
Built from
npm: @phosphor-icons/react. The CLI installs it for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on