diff --git a/src/components/AccountSidebar.astro b/src/components/AccountSidebar.astro index 9b609304e..b4e9ca417 100644 --- a/src/components/AccountSidebar.astro +++ b/src/components/AccountSidebar.astro @@ -64,6 +64,16 @@ const sidebarLinks = [ classes: 'h-4 w-4', }, }, + { + href: '/account/billing', + title: 'Billing', + id: 'billing', + isNew: true, + icon: { + glyph: 'badge', + classes: 'h-4 w-4', + }, + }, { href: '/account/settings', title: 'Settings', @@ -97,7 +107,7 @@ const sidebarLinks = [ }`} > - Teams + Teams { diff --git a/src/components/Billing/BillingPage.tsx b/src/components/Billing/BillingPage.tsx index d2713ce59..094970b7c 100644 --- a/src/components/Billing/BillingPage.tsx +++ b/src/components/Billing/BillingPage.tsx @@ -8,7 +8,7 @@ import { } from '../../queries/billing'; import { queryClient } from '../../stores/query-client'; import { httpPost } from '../../lib/query-http'; -import { UpgradePlanModal } from '../CourseLanding/UpgradePlanModal'; +import { UpgradeAccountModal } from './UpgradeAccountModal'; import { getUrlParams } from '../../lib/browser'; import { VerifyUpgrade } from './VerifyUpgrade'; @@ -66,15 +66,12 @@ export function BillingPage() { } const selectedPlanDetails = USER_SUBSCRIPTION_PLAN_PRICES.find( - (plan) => plan.planId === (billingDetails?.planId || 'free'), + (plan) => plan.priceId === billingDetails?.priceId, ); const shouldHideDeleteButton = billingDetails?.status === 'canceled' || billingDetails?.cancelAtPeriodEnd; - const priceDetails = - (billingDetails?.interval || 'month') === 'month' - ? selectedPlanDetails?.prices.month - : selectedPlanDetails?.prices.year; + const priceDetails = selectedPlanDetails; const formattedNextBillDate = new Date( billingDetails?.currentPeriodEnd || '', @@ -87,7 +84,7 @@ export function BillingPage() { return ( <> {showUpgradeModal && ( - { setShowUpgradeModal(false); }} @@ -101,7 +98,7 @@ export function BillingPage() { {billingDetails?.status === 'none' && !isLoadingBillingDetails && (

- You are using free plan,  + You are not subscribed to any plan, 

)} - {billingDetails?.status !== 'none' && !isLoadingBillingDetails && ( - <> - {billingDetails?.status === 'past_due' && ( -
- We were not able to charge your card. Please update your payment - information. -
- )} - -
-
- Plan - - {selectedPlanDetails?.name} - -
-
+ {billingDetails?.status !== 'none' && + !isLoadingBillingDetails && + priceDetails && ( + <> + {billingDetails?.status === 'past_due' && ( +
+ We were not able to charge your card. Please update your payment + information. +
+ )} + +
- Payment + Plan - ${priceDetails!.amount / 100} - -  / {priceDetails!.interval} - + {selectedPlanDetails?.name}
- - {!shouldHideDeleteButton && ( - - )} +
+
+ Payment + + ${priceDetails.amount} + +  / {priceDetails.interval} + + +
+ + {!shouldHideDeleteButton && ( + + )} +
-
- -
-
- - {billingDetails?.cancelAtPeriodEnd ? 'Expires On' : 'Renews On'} - - - {formattedNextBillDate} - + +
+
+ + {billingDetails?.cancelAtPeriodEnd + ? 'Expires On' + : 'Renews On'} + + + {formattedNextBillDate} + +
+
- -
- - )} + + )} ); } diff --git a/src/components/Billing/UpgradeAccountModal.tsx b/src/components/Billing/UpgradeAccountModal.tsx index 274bc7ab6..18a57e0e3 100644 --- a/src/components/Billing/UpgradeAccountModal.tsx +++ b/src/components/Billing/UpgradeAccountModal.tsx @@ -26,10 +26,13 @@ type CreateSubscriptionCheckoutSessionResponse = { type UpgradeAccountModalProps = { onClose: () => void; + + success?: string; + cancel?: string; }; export function UpgradeAccountModal(props: UpgradeAccountModalProps) { - const { onClose } = props; + const { onClose, success, cancel } = props; const [selectedPlan, setSelectedPlan] = useState('month'); @@ -199,8 +202,8 @@ export function UpgradeAccountModal(props: UpgradeAccountModalProps) { const currentUrlPath = window.location.pathname; createCheckoutSession({ priceId: plan.priceId, - success: `${currentUrlPath}?s=1`, - cancel: `${currentUrlPath}?s=0`, + success: success || `${currentUrlPath}?s=1`, + cancel: cancel || `${currentUrlPath}?s=0`, }); return; }