@@ -7,72 +7,65 @@ import {
77 CreditCardIcon ,
88 FileTextIcon ,
99} from '@phosphor-icons/react' ;
10+ import type { Customer , CustomerInvoice } from 'autumn-js' ;
1011import dayjs from 'dayjs' ;
1112import { memo } from 'react' ;
1213import { useBilling } from '@/app/(main)/billing/hooks/use-billing' ;
1314import { Badge } from '@/components/ui/badge' ;
1415import { Button } from '@/components/ui/button' ;
1516import { Card , CardContent } from '@/components/ui/card' ;
1617import { Skeleton } from '@/components/ui/skeleton' ;
17- import type { Customer , Invoice } from '../data/billing-data' ;
1818
1919const InvoiceCard = memo ( function InvoiceCardComponent ( {
2020 invoice,
2121} : {
22- invoice : Invoice ;
22+ invoice : CustomerInvoice ;
2323} ) {
2424 const getStatusBadge = ( ) => {
25- switch ( invoice . status ) {
26- case 'paid' :
27- return (
28- < Badge className = "bg-emerald-500 text-xs hover:bg-emerald-600" >
29- Paid
30- </ Badge >
31- ) ;
32- case 'open' :
33- case 'pending' :
34- return (
35- < Badge className = "text-xs" variant = "secondary" >
36- Pending
37- </ Badge >
38- ) ;
39- case 'failed' :
40- return (
41- < Badge className = "text-xs" variant = "destructive" >
42- Failed
43- </ Badge >
44- ) ;
45- case 'draft' :
46- return (
47- < Badge className = "text-xs" variant = "outline" >
48- Draft
49- </ Badge >
50- ) ;
51- case 'void' :
52- return (
53- < Badge className = "text-xs" variant = "outline" >
54- Void
55- </ Badge >
56- ) ;
57- default :
58- return null ;
25+ const statusConfig = {
26+ paid : {
27+ variant : 'default' as const ,
28+ className : 'bg-emerald-500 hover:bg-emerald-600' ,
29+ text : 'Paid' ,
30+ } ,
31+ open : { variant : 'secondary' as const , className : '' , text : 'Pending' } ,
32+ pending : {
33+ variant : 'secondary' as const ,
34+ className : '' ,
35+ text : 'Pending' ,
36+ } ,
37+ failed : {
38+ variant : 'destructive' as const ,
39+ className : '' ,
40+ text : 'Failed' ,
41+ } ,
42+ draft : { variant : 'outline' as const , className : '' , text : 'Draft' } ,
43+ void : { variant : 'outline' as const , className : '' , text : 'Void' } ,
44+ } ;
45+
46+ const config = statusConfig [ invoice . status as keyof typeof statusConfig ] ;
47+ if ( ! config ) {
48+ return null ;
5949 }
50+
51+ return (
52+ < Badge className = { `text-xs ${ config . className } ` } variant = { config . variant } >
53+ { config . text }
54+ </ Badge >
55+ ) ;
6056 } ;
6157
62- const formatAmount = ( amount : number , currency : string ) => {
63- return new Intl . NumberFormat ( 'en-US' , {
58+ const formatAmount = ( amount : number , currency : string ) =>
59+ new Intl . NumberFormat ( 'en-US' , {
6460 style : 'currency' ,
6561 currency : currency . toUpperCase ( ) ,
6662 } ) . format ( amount ) ;
67- } ;
6863
6964 const getProductNames = ( productIds : string [ ] ) => {
70- const productMap : Record < string , string > = {
71- free : 'Free' ,
72- pro : 'Pro' ,
73- buddy : 'Buddy' ,
74- } ;
75- return productIds . map ( ( id ) => productMap [ id ] || id ) . join ( ', ' ) ;
65+ const productMap = { free : 'Free' , pro : 'Pro' , buddy : 'Buddy' } ;
66+ return productIds
67+ . map ( ( id ) => productMap [ id as keyof typeof productMap ] || id )
68+ . join ( ', ' ) ;
7669 } ;
7770
7871 return (
@@ -195,7 +188,7 @@ const SubscriptionHistoryCard = memo(function SubscriptionHistoryCardComponent({
195188} ) ;
196189
197190interface HistoryTabProps {
198- invoices : Invoice [ ] ;
191+ invoices : CustomerInvoice [ ] ;
199192 customerData : Customer | null ;
200193 isLoading : boolean ;
201194}
@@ -262,8 +255,8 @@ export const HistoryTab = memo(function HistoryTabComponent({
262255 { invoices . length ? (
263256 < div className = "space-y-3" >
264257 { invoices
265- . sort ( ( a : Invoice , b : Invoice ) => b . created_at - a . created_at )
266- . map ( ( invoice : Invoice ) => (
258+ . sort ( ( a , b ) => b . created_at - a . created_at )
259+ . map ( ( invoice ) => (
267260 < InvoiceCard invoice = { invoice } key = { invoice . stripe_id } />
268261 ) ) }
269262 </ div >
0 commit comments