Skip to content

The Open Source DocuSign Alternative.

fix: checkout loading button (#1445)

David Nguyen51585849554b
diff --git a/apps/web/src/app/(dashboard)/settings/billing/billing-plans.tsx b/apps/web/src/app/(dashboard)/settings/billing/billing-plans.tsx
index 6d4b350dd..537a0c97b 100644
--- a/apps/web/src/app/(dashboard)/settings/billing/billing-plans.tsx
+++ b/apps/web/src/app/(dashboard)/settings/billing/billing-plans.tsx
@@ -44,11 +44,11 @@ export const BillingPlans = ({ prices }: BillingPlansProps) => {
const isMounted = useIsMounted();
const [interval, setInterval] = useState<Interval>('month');
- const [isFetchingCheckoutSession, setIsFetchingCheckoutSession] = useState(false);
+ const [checkoutSessionPriceId, setCheckoutSessionPriceId] = useState<string | null>(null);
const onSubscribeClick = async (priceId: string) => {
try {
- setIsFetchingCheckoutSession(true);
+ setCheckoutSessionPriceId(priceId);
const url = await createCheckout({ priceId });
@@ -64,7 +64,7 @@ export const BillingPlans = ({ prices }: BillingPlansProps) => {
variant: 'destructive',
});
} finally {
- setIsFetchingCheckoutSession(false);
+ setCheckoutSessionPriceId(null);
}
};
@@ -122,7 +122,8 @@ export const BillingPlans = ({ prices }: BillingPlansProps) => {
<Button
className="mt-4"
- loading={isFetchingCheckoutSession}
+ disabled={checkoutSessionPriceId !== null}
+ loading={checkoutSessionPriceId === price.id}
onClick={() => void onSubscribeClick(price.id)}
>
<Trans>Subscribe</Trans>