fix billingCheckoutSession query param + enable redirect on workspace… (#11509)

… during onboarding



fixes : https://github.com/twentyhq/core-team-issues/issues/668
This commit is contained in:
Etienne
2025-04-10 16:47:40 +02:00
committed by GitHub
parent d69932c6c4
commit ee5aa2393d
20 changed files with 151 additions and 92 deletions

View File

@ -14,11 +14,14 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { isDefined } from 'twenty-shared/utils';
import { Loader } from 'twenty-ui/feedback';
import { CardPicker, MainButton } from 'twenty-ui/input';
import { CAL_LINK, ClickToActionLink } from 'twenty-ui/navigation';
import {
CAL_LINK,
ClickToActionLink,
TWENTY_PRICING_LINK,
} from 'twenty-ui/navigation';
import {
BillingPlanKey,
BillingPriceLicensedDto,
SubscriptionInterval,
useBillingBaseProductPricesQuery,
} from '~/generated/graphql';
@ -94,7 +97,7 @@ export const ChooseYourPlan = () => {
const { data: plans } = useBillingBaseProductPricesQuery();
const currentPlan = billingCheckoutSession.plan || BillingPlanKey.PRO;
const currentPlan = billingCheckoutSession.plan;
const getPlanBenefits = (planKey: BillingPlanKey) => {
if (planKey === BillingPlanKey.ENTERPRISE) {
@ -128,7 +131,7 @@ export const ChooseYourPlan = () => {
const baseProductPrice = baseProduct?.prices?.find(
(price): price is BillingPriceLicensedDto =>
isBillingPriceLicensed(price) &&
price.recurringInterval === SubscriptionInterval.Month,
price.recurringInterval === billingCheckoutSession.interval,
);
const hasWithoutCreditCardTrialPeriod = billing?.trialPeriods.some(
@ -160,27 +163,10 @@ export const ChooseYourPlan = () => {
};
};
const handleSwitchPlan = (planKey: BillingPlanKey) => {
return () => {
if (isDefined(baseProductPrice)) {
setBillingCheckoutSession({
plan: planKey,
interval: baseProductPrice.recurringInterval,
requirePaymentMethod: billingCheckoutSession.requirePaymentMethod,
});
}
};
};
const { signOut } = useAuth();
const withCreditCardTrialPeriodDuration = withCreditCardTrialPeriod?.duration;
const alternatePlan =
currentPlan === BillingPlanKey.PRO
? BillingPlanKey.ENTERPRISE
: BillingPlanKey.PRO;
const planName = plans?.plans.find((plan) => plan.planKey === currentPlan)
?.baseProduct.name;
@ -252,8 +238,8 @@ export const ChooseYourPlan = () => {
<Trans>Log out</Trans>
</ClickToActionLink>
<span />
<ClickToActionLink onClick={handleSwitchPlan(alternatePlan)}>
<Trans>Switch Plan</Trans>
<ClickToActionLink href={TWENTY_PRICING_LINK}>
<Trans>Change Plan</Trans>
</ClickToActionLink>
<span />
<ClickToActionLink href={CAL_LINK} target="_blank" rel="noreferrer">