From 979e3f3e71367cc8e8f32ba0448abf3a297eb6c9 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 15 Nov 2024 21:34:39 +0700 Subject: [PATCH] fix: always allow access to billing (#1476) --- .../billing/billing-portal-button.tsx | 5 +- .../app/(dashboard)/settings/billing/page.tsx | 112 ++++++++++-------- 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/apps/web/src/app/(dashboard)/settings/billing/billing-portal-button.tsx b/apps/web/src/app/(dashboard)/settings/billing/billing-portal-button.tsx index da230908a..c8ab8c132 100644 --- a/apps/web/src/app/(dashboard)/settings/billing/billing-portal-button.tsx +++ b/apps/web/src/app/(dashboard)/settings/billing/billing-portal-button.tsx @@ -12,9 +12,10 @@ import { createBillingPortal } from './create-billing-portal.action'; export type BillingPortalButtonProps = { buttonProps?: React.ComponentProps; + children?: React.ReactNode; }; -export const BillingPortalButton = ({ buttonProps }: BillingPortalButtonProps) => { +export const BillingPortalButton = ({ buttonProps, children }: BillingPortalButtonProps) => { const { _ } = useLingui(); const { toast } = useToast(); @@ -63,7 +64,7 @@ export const BillingPortalButton = ({ buttonProps }: BillingPortalButtonProps) = onClick={async () => handleFetchPortalUrl()} loading={isFetchingPortalUrl} > - Manage Subscription + {children || Manage Subscription} ); }; diff --git a/apps/web/src/app/(dashboard)/settings/billing/page.tsx b/apps/web/src/app/(dashboard)/settings/billing/page.tsx index e60698818..05be0c6cb 100644 --- a/apps/web/src/app/(dashboard)/settings/billing/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/billing/page.tsx @@ -68,60 +68,74 @@ export default async function BillingSettingsPage() { return (
-

- Billing -

+
+
+

+ Billing +

-
- {isMissingOrInactiveOrFreePlan && ( -

- - You are currently on the Free Plan. - -

- )} - - {/* Todo: Translation */} - {!isMissingOrInactiveOrFreePlan && - match(subscription.status) - .with('ACTIVE', () => ( -

- {subscriptionProduct ? ( - - You are currently subscribed to{' '} - {subscriptionProduct.name} - - ) : ( - You currently have an active plan - )} - - {subscription.periodEnd && ( - - {' '} - which is set to{' '} - {subscription.cancelAtPeriodEnd ? ( - - end on{' '} - {i18n.date(subscription.periodEnd)}. - - ) : ( - - automatically renew on{' '} - {i18n.date(subscription.periodEnd)}. - - )} - - )} -

- )) - .with('PAST_DUE', () => ( +
+ {isMissingOrInactiveOrFreePlan && (

- Your current plan is past due. Please update your payment information. + You are currently on the Free Plan.

- )) - .otherwise(() => null)} + )} + + {/* Todo: Translation */} + {!isMissingOrInactiveOrFreePlan && + match(subscription.status) + .with('ACTIVE', () => ( +

+ {subscriptionProduct ? ( + + You are currently subscribed to{' '} + {subscriptionProduct.name} + + ) : ( + You currently have an active plan + )} + + {subscription.periodEnd && ( + + {' '} + which is set to{' '} + {subscription.cancelAtPeriodEnd ? ( + + end on{' '} + + {i18n.date(subscription.periodEnd)}. + + + ) : ( + + automatically renew on{' '} + + {i18n.date(subscription.periodEnd)}. + + + )} + + )} +

+ )) + .with('PAST_DUE', () => ( +

+ + Your current plan is past due. Please update your payment information. + +

+ )) + .otherwise(() => null)} +
+
+ + {isMissingOrInactiveOrFreePlan && ( + + Manage billing + + )}