Skip to content

Commit 3dc3fef

Browse files
committed
feat: fixed plans
1 parent 5e58475 commit 3dc3fef

File tree

5 files changed

+178
-772
lines changed

5 files changed

+178
-772
lines changed

apps/dashboard/app/(main)/billing/components/cancel-subscription-dialog.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { CalendarIcon, LightningIcon, XIcon } from '@phosphor-icons/react';
3+
import { CalendarIcon, LightningIcon } from '@phosphor-icons/react';
44
import { Button } from '@/components/ui/button';
55
import {
66
Dialog,
@@ -50,6 +50,7 @@ export function CancelSubscriptionDialog({
5050
onCancel(false);
5151
onOpenChange(false);
5252
}}
53+
type="button"
5354
>
5455
<div className="mb-2 flex items-center gap-3">
5556
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-blue-100">
@@ -61,14 +62,9 @@ export function CancelSubscriptionDialog({
6162
</div>
6263
</div>
6364
<p className="ml-11 text-muted-foreground text-sm">
64-
{periodEndDate ? (
65-
<>Keep access until {periodEndDate}. No additional charges.</>
66-
) : (
67-
<>
68-
Keep access until your current billing period ends. No
69-
additional charges.
70-
</>
71-
)}
65+
{periodEndDate
66+
? `Keep access until ${periodEndDate}. No additional charges.`
67+
: 'Keep access until your current billing period ends. No additional charges.'}
7268
</p>
7369
</button>
7470

@@ -79,6 +75,7 @@ export function CancelSubscriptionDialog({
7975
onCancel(true);
8076
onOpenChange(false);
8177
}}
78+
type="button"
8279
>
8380
<div className="mb-2 flex items-center gap-3">
8481
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-orange-100">

apps/dashboard/app/(main)/billing/components/history-tab.tsx

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,65 @@ import {
77
CreditCardIcon,
88
FileTextIcon,
99
} from '@phosphor-icons/react';
10+
import type { Customer, CustomerInvoice } from 'autumn-js';
1011
import dayjs from 'dayjs';
1112
import { memo } from 'react';
1213
import { useBilling } from '@/app/(main)/billing/hooks/use-billing';
1314
import { Badge } from '@/components/ui/badge';
1415
import { Button } from '@/components/ui/button';
1516
import { Card, CardContent } from '@/components/ui/card';
1617
import { Skeleton } from '@/components/ui/skeleton';
17-
import type { Customer, Invoice } from '../data/billing-data';
1818

1919
const 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

197190
interface 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

Comments
 (0)