Skip to content

Commit 76ddb2f

Browse files
committed
fix: pricing card
1 parent 7197f15 commit 76ddb2f

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/components/billing/pricing-modal/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ function Plans({ products, subscription }: PricingProps) {
9090
</div>
9191

9292
<section className="flex flex-col sm:flex-row sm:flex-wrap gap-8 pt-8">
93+
<PricingCard
94+
title="Free"
95+
description=""
96+
price="$0"
97+
interval="month"
98+
subscribedUnitAmount={subscription?.price.unitAmount}
99+
unitAmount={0}
100+
isSubmitting={isSubmitting}
101+
{...(subscription && {
102+
handleClick: () => {
103+
return handleBillingPortal({
104+
type: "cancel",
105+
subscription: subscription.id,
106+
});
107+
},
108+
})}
109+
/>
93110
{products.map((product) => {
94111
const price = product?.prices?.find(
95112
(price) => price.interval === billingInterval,

src/components/billing/pricing-modal/pricing-card.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface PricingCardProps {
1818
subscribedUnitAmount?: bigint | null;
1919
unitAmount: number;
2020
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
21-
handleClick: () => Promise<any>;
21+
handleClick?: () => Promise<any>;
2222
isSubmitting: boolean;
2323
}
2424

@@ -52,9 +52,11 @@ export function PricingCard({
5252
<CardTitle className="text-lg">{title}</CardTitle>
5353
<div className="flex gap-0.5">
5454
<h3 className="text-3xl font-bold">{price}</h3>
55-
<span className="flex flex-col justify-end text-sm mb-1">
56-
/{humanizedInterval[interval]}
57-
</span>
55+
{unitAmount !== 0 && (
56+
<span className="flex flex-col justify-end text-sm mb-1">
57+
/{humanizedInterval[interval]}
58+
</span>
59+
)}
5860
</div>
5961
<CardDescription>{description}</CardDescription>
6062
</CardHeader>
@@ -63,20 +65,25 @@ export function PricingCard({
6365
className={cn(!active && "bg-teal-500 hover:bg-teal-500/80")}
6466
{...(active && { variant: "destructive" })}
6567
onClick={async () => {
66-
setIsLoading(true);
67-
await handleClick();
68-
setIsLoading(false);
68+
if (handleClick) {
69+
setIsLoading(true);
70+
await handleClick();
71+
setIsLoading(false);
72+
}
6973
}}
7074
loading={isLoading}
7175
{...(!isLoading && { disabled: isSubmitting })}
76+
{...(unitAmount === 0 && !subscribedUnitAmount && { disabled: true })}
7277
>
7378
{subscribedUnitAmount
7479
? unitAmount < subscribedUnitAmount
7580
? "Downgrade Plan"
7681
: unitAmount > subscribedUnitAmount
7782
? "Upgrade Plan"
7883
: "Cancel Current Plan"
79-
: "Subscribe"}
84+
: !subscribedUnitAmount && unitAmount === 0
85+
? "Active plan"
86+
: "Subscribe"}
8087
</Button>
8188
</CardFooter>
8289
</Card>

0 commit comments

Comments
 (0)