Skip to content

Commit dad1dac

Browse files
add badges to invoice cards
1 parent de8d57d commit dad1dac

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

packages/web/src/app/(app)/settings/license/recentInvoicesCard.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Link from "next/link";
22
import { ExternalLink } from "lucide-react";
33
import { Invoice } from "@/ee/features/lighthouse/types";
44
import { SettingsCard, SettingsCardGroup } from "../components/settingsCard";
5+
import { Badge } from "@/components/ui/badge";
56
import { Button } from "@/components/ui/button";
67

78
interface RecentInvoicesCardProps {
@@ -26,13 +27,21 @@ export function RecentInvoicesCard({ invoices }: RecentInvoicesCardProps) {
2627
}
2728

2829
function InvoiceRow({ invoice }: { invoice: Invoice }) {
30+
const statusBadge = getStatusBadge(invoice.status);
2931
return (
3032
<SettingsCard>
3133
<div className="flex items-center gap-6">
3234
<p className="text-sm w-32 shrink-0 font-medium">{formatDate(invoice.createdAt)}</p>
33-
<p className="text-sm text-muted-foreground flex-1">
34-
{formatCurrency(invoice.amount, invoice.currency)}
35-
</p>
35+
<div className="flex items-center gap-2 flex-1">
36+
<p className="text-sm text-muted-foreground">
37+
{formatCurrency(invoice.amount, invoice.currency)}
38+
</p>
39+
{statusBadge && (
40+
<Badge variant="outline" className={statusBadge.className}>
41+
{statusBadge.label}
42+
</Badge>
43+
)}
44+
</div>
3645
{invoice.hostedInvoiceUrl && (
3746
<Button variant="ghost" asChild>
3847
<Link
@@ -50,6 +59,20 @@ function InvoiceRow({ invoice }: { invoice: Invoice }) {
5059
);
5160
}
5261

62+
// Maps Stripe invoice statuses to display badges. See:
63+
// https://docs.stripe.com/invoicing/overview#invoice-statuses
64+
const STATUS_BADGES: Record<string, { label: string; className: string }> = {
65+
draft: { label: 'Draft', className: 'border-muted-foreground/30 text-muted-foreground' },
66+
open: { label: 'Open', className: 'border-primary/30 text-primary' },
67+
paid: { label: 'Paid', className: 'border-primary/30 text-primary' },
68+
uncollectible: { label: 'Uncollectible', className: 'border-destructive/30 text-destructive' },
69+
void: { label: 'Void', className: 'border-muted-foreground/30 text-muted-foreground' },
70+
};
71+
72+
function getStatusBadge(status: string): { label: string; className: string } | null {
73+
return STATUS_BADGES[status] ?? null;
74+
}
75+
5376
function formatDate(isoDate: string): string {
5477
return new Date(isoDate).toLocaleDateString('en-US', {
5578
month: 'short',

0 commit comments

Comments
 (0)