@@ -25,6 +25,34 @@ import { ToolTipLabel } from "@/components/ui/tooltip";
2525import { ThirdwebMiniLogo } from "../../../../../../../components/ThirdwebMiniLogo" ;
2626import { searchParams } from "../search-params" ;
2727
28+ function getStatusBadge ( invoice : Stripe . Invoice ) {
29+ switch ( invoice . status ) {
30+ case "paid" :
31+ return < Badge variant = "success" > Paid</ Badge > ;
32+ case "open" :
33+ // we treat "uncollectible" as unpaid
34+ case "uncollectible" : {
35+ // if the invoice has a due date, use that, otherwise use the effective at date (which is the date the invoice was created)
36+ const effectiveDueDate = invoice . due_date || invoice . effective_at ;
37+
38+ // if the invoice due date is in the past, we want to display it as past due
39+ if ( effectiveDueDate && effectiveDueDate * 1000 < Date . now ( ) ) {
40+ return < Badge variant = "destructive" > Past Due</ Badge > ;
41+ }
42+ return < Badge variant = "outline" > Open</ Badge > ;
43+ }
44+ case "void" :
45+ return < Badge variant = "secondary" > Void</ Badge > ;
46+
47+ default :
48+ return < Badge variant = "outline" > Unknown</ Badge > ;
49+ }
50+ }
51+
52+ function isInvoicePayable ( invoice : Stripe . Invoice ) {
53+ return invoice . status === "open" || invoice . status === "uncollectible" ;
54+ }
55+
2856export function BillingHistory ( props : {
2957 teamSlug : string ;
3058 invoices : Stripe . Invoice [ ] ;
@@ -57,27 +85,6 @@ export function BillingHistory(props: {
5785 } ) ;
5886 } ;
5987
60- const getStatusBadge = ( invoice : Stripe . Invoice ) => {
61- switch ( invoice . status ) {
62- case "paid" :
63- return < Badge variant = "success" > Paid</ Badge > ;
64- case "open" :
65- // we treate "uncollectible" as unpaid
66- case "uncollectible" : {
67- // if the invoice due date is in the past, we want to display it as past due
68- if ( invoice . due_date && invoice . due_date * 1000 < Date . now ( ) ) {
69- return < Badge variant = "destructive" > Past Due</ Badge > ;
70- }
71- return < Badge variant = "outline" > Open</ Badge > ;
72- }
73- case "void" :
74- return < Badge variant = "secondary" > Void</ Badge > ;
75-
76- default :
77- return < Badge variant = "outline" > Unknown</ Badge > ;
78- }
79- } ;
80-
8188 if ( props . invoices . length === 0 ) {
8289 if ( props . status === "open" ) {
8390 return (
@@ -126,7 +133,7 @@ export function BillingHistory(props: {
126133 < TableCell > { getStatusBadge ( invoice ) } </ TableCell >
127134 < TableCell className = "text-right" >
128135 < div className = "flex justify-end space-x-2" >
129- { invoice . status === "open" && (
136+ { isInvoicePayable ( invoice ) && (
130137 < >
131138 { /* always show the crypto payment button */ }
132139 < ToolTipLabel
0 commit comments