The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(billing): show the current legacy plan on the Plans page (#28624)
Etienne060384441df0
diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsxindex d955fca3743..34e99039622 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsx@@ -16,11 +16,9 @@ import {type SegmentedControlOption,} from 'twenty-ui/components/input';import { Button } from 'twenty-ui/primitives/input';+import { Tag } from 'twenty-ui/primitives/data-display';import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme';-import {- type BillingPlanKey,- SubscriptionInterval,-} from '~/generated-metadata/graphql';+import { SubscriptionInterval } from '~/generated-metadata/graphql';type SettingsBillingPlanComparisonTableProps = {billingInterval: SettingsBillingPlanInterval;@@ -33,7 +31,8 @@ type SettingsBillingPlanComparisonTableProps = {const STICKY_HEADER_TOP_OFFSET = themeCssVariables.spacing[6];-const MOBILE_COMPARISON_GRID_COLUMNS = 'repeat(2, minmax(0, 1fr))';+const getComparisonGridColumns = (columnCount: number) =>+ `repeat(${columnCount}, minmax(0, 1fr))`;const StyledContentContainer = styled.div`max-width: 694px;@@ -56,14 +55,15 @@ const StyledStickyHeaderContainer = styled.div`}`;-const StyledMobilePlanNamesGrid = styled.div`+const StyledMobilePlanNamesGrid = styled.div<{ planCount: number }>`display: none;@media (max-width: ${MOBILE_VIEWPORT}px) {background: ${themeCssVariables.background.primary};border-bottom: 1px solid ${themeCssVariables.border.color.medium};display: grid;- grid-template-columns: ${MOBILE_COMPARISON_GRID_COLUMNS};+ grid-template-columns: ${({ planCount }) =>+ getComparisonGridColumns(planCount)};position: sticky;top: 0;z-index: 2;@@ -76,13 +76,14 @@ const StyledComparisonTable = styled.div`width: 100%;`;-const StyledComparisonHeaderGrid = styled.div`+const StyledComparisonHeaderGrid = styled.div<{ planCount: number }>`background: ${themeCssVariables.border.color.medium};border: 1px solid ${themeCssVariables.border.color.medium};border-radius: ${themeCssVariables.border.radius.md};box-sizing: border-box;display: grid;- grid-template-columns: repeat(3, minmax(0, 1fr));+ grid-template-columns: ${({ planCount }) =>+ getComparisonGridColumns(planCount + 1)};overflow: clip;row-gap: 1px;width: 100%;@@ -92,14 +93,16 @@ const StyledComparisonHeaderGrid = styled.div`}`;-const StyledComparisonBodyGrid = styled.div`+const StyledComparisonBodyGrid = styled.div<{ planCount: number }>`display: grid;- grid-template-columns: repeat(3, minmax(0, 1fr));+ grid-template-columns: ${({ planCount }) =>+ getComparisonGridColumns(planCount + 1)};overflow: clip;width: 100%;@media (max-width: ${MOBILE_VIEWPORT}px) {- grid-template-columns: ${MOBILE_COMPARISON_GRID_COLUMNS};+ grid-template-columns: ${({ planCount }) =>+ getComparisonGridColumns(planCount)};}`;@@ -135,15 +138,21 @@ const StyledPlanTitle = styled.div`display: flex;font-size: ${themeCssVariables.font.size.md};font-weight: ${themeCssVariables.font.weight.medium};+ gap: ${themeCssVariables.spacing[2]};line-height: 1.4;min-height: 20px;width: 100%;`;const StyledMobilePlanName = styled(StyledPlanTitle)`- display: block;- overflow: hidden;+ flex-wrap: wrap;+ gap: ${themeCssVariables.spacing[1]};padding: ${themeCssVariables.spacing[2]};+`;++const StyledPlanName = styled.span`+ min-width: 0;+ overflow: hidden;text-overflow: ellipsis;white-space: nowrap;`;@@ -206,8 +215,15 @@ export const SettingsBillingPlanComparisonTable = ({const formatAnimatedPrice = (value: number) =>formatNumber(Math.max(0, value));- const getPlanTitle = (planKey: BillingPlanKey) =>- t(BILLING_PLAN_LABELS[planKey]);+ const getPlanTitle = ({+ isLegacy,+ planKey,+ }: Pick<SettingsBillingComparedPlan, 'isLegacy' | 'planKey'>) => (+ <>+ <StyledPlanName>{t(BILLING_PLAN_LABELS[planKey])}</StyledPlanName>+ {isLegacy && <Tag color="gray">{t`Legacy`}</Tag>}+ </>+ );const billingIntervalOptions = [{@@ -224,7 +240,7 @@ export const SettingsBillingPlanComparisonTable = ({<StyledContentContainer><StyledComparisonTable><StyledStickyHeaderContainer>- <StyledComparisonHeaderGrid>+ <StyledComparisonHeaderGrid planCount={comparedPlans.length}><StyledHeaderCell><StyledHeaderText><StyledComparisonTitle>{t`Compare plans`}</StyledComparisonTitle>@@ -243,13 +259,15 @@ export const SettingsBillingPlanComparisonTable = ({/></StyledHeaderCell>- {comparedPlans.map(({ action, planKey }) => {+ {comparedPlans.map(({ action, isLegacy, planKey }) => {const price = planPrices[planKey][billingInterval];return (<StyledHeaderCell key={planKey}><StyledHeaderText>- <StyledPlanTitle>{getPlanTitle(planKey)}</StyledPlanTitle>+ <StyledPlanTitle>+ {getPlanTitle({ isLegacy, planKey })}+ </StyledPlanTitle><StyledPriceLine><StyledPrice>$@@ -282,15 +300,15 @@ export const SettingsBillingPlanComparisonTable = ({</StyledComparisonHeaderGrid></StyledStickyHeaderContainer>- <StyledMobilePlanNamesGrid aria-hidden>- {comparedPlans.map(({ planKey }) => (+ <StyledMobilePlanNamesGrid aria-hidden planCount={comparedPlans.length}>+ {comparedPlans.map(({ isLegacy, planKey }) => (<StyledMobilePlanName key={planKey}>- {getPlanTitle(planKey)}+ {getPlanTitle({ isLegacy, planKey })}</StyledMobilePlanName>))}</StyledMobilePlanNamesGrid>- <StyledComparisonBodyGrid>+ <StyledComparisonBodyGrid planCount={comparedPlans.length}>{SETTINGS_BILLING_PLAN_COMPARISON_ROWS.map((row, rowIndex) => (<SettingsBillingPlanComparisonTableRowkey={`row-${rowIndex}`}diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsxindex fe9b0d88cba..a79346a668b 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsx@@ -1,6 +1,7 @@import { type Meta, type StoryObj } from '@storybook/react-vite';import { type ComponentProps, useState } from 'react';import { expect, fn, userEvent, within } from 'storybook/test';+import { IconArrowUp } from 'twenty-ui/icon';import { ComponentDecorator } from 'twenty-ui/testing';import { SettingsBillingPlanComparisonTable } from '@/settings/billing/components/internal/SettingsBillingPlanComparisonTable';@@ -98,6 +99,44 @@ export const BillingPeriod: Story = {play: playBillingPeriodToggle,};+export const WithLegacyPlan: Story = {+ args: {+ comparedPlans: [+ {+ action: { disabled: true, title: 'Current', variant: 'outline' },+ isLegacy: true,+ planKey: BillingPlanKey.PRO,+ },+ {+ action: {+ color: 'accent',+ Icon: IconArrowUp,+ title: 'Upgrade',+ variant: 'solid',+ },+ planKey: BillingPlanKey.PRO_V2,+ },+ {+ action: {+ color: 'accent',+ Icon: IconArrowUp,+ title: 'Upgrade',+ variant: 'solid',+ },+ planKey: BillingPlanKey.ORGANIZATION_V2,+ },+ ],+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await expect(canvas.getAllByText('Legacy')[0]).toBeVisible();+ await expect(+ canvas.getAllByRole('button', { name: 'Upgrade' }),+ ).toHaveLength(2);+ },+};+export const MobileBillingPeriod: Story = {parameters: {viewport: { defaultViewport: 'mobile1' },diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.tsindex ac1aa06cecc..19045ca8b35 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.ts@@ -23,6 +23,7 @@ import {assertUnreachable,getSettingsPath,isDefined,+ isNonEmptyArray,} from 'twenty-shared/utils';import {IconArrowDown,@@ -58,6 +59,13 @@ export const useBillingPlanActions = ({const { getBillingPlanLabel } = useBillingWording();const { getPlanByPlanKey } = usePlanByPlanKey();const currentPlan = getPlanByPlanKey(currentPlanKey);+ const canCurrentPlanSwitch =+ isNonEmptyArray(currentPlan.upgradePlanKeys) ||+ isNonEmptyArray(currentPlan.downgradePlanKeys);+ const displayedPlanKeys = comparedPlanKeys.includes(currentPlanKey)+ ? comparedPlanKeys+ : [currentPlanKey, ...comparedPlanKeys];+ const hasShortChangeTitles = displayedPlanKeys.length > 2;const currentWorkspace = useAtomStateValue(currentWorkspaceState);const subscriptionStatus = useSubscriptionStatus();const { nextPlan } = useNextPlan();@@ -119,6 +127,17 @@ export const useBillingPlanActions = ({change: BillingSubscriptionChange;isUpgrade: boolean;}) => {+ if (hasShortChangeTitles) {+ if (+ change.type === 'CANCEL_PLAN_SWITCH' ||+ change.type === 'CANCEL_INTERVAL_SWITCH'+ ) {+ return t`Cancel switch`;+ }++ return isUpgrade ? t`Upgrade` : t`Switch`;+ }+switch (change.type) {case 'SWITCH_PLAN':return getSwitchPlanTitle({@@ -206,11 +225,16 @@ export const useBillingPlanActions = ({};}- if (+ const isPlanSwitchUnavailable =cell.change.type === 'SWITCH_PLAN' &&!currentPlan.upgradePlanKeys.includes(planKey) &&- !currentPlan.downgradePlanKeys.includes(planKey)- ) {+ !currentPlan.downgradePlanKeys.includes(planKey);+ const isLegacyIntervalSwitchDeferred =+ cell.change.type === 'SWITCH_INTERVAL' &&+ !getPlanByPlanKey(planKey).isSellable &&+ canCurrentPlanSwitch;++ if (isPlanSwitchUnavailable || isLegacyIntervalSwitchDeferred) {return {disabled: true,title: t`Unavailable`,@@ -245,8 +269,12 @@ export const useBillingPlanActions = ({});};- const comparedPlans: SettingsBillingComparedPlan[] = comparedPlanKeys.map(- (planKey) => ({ action: getPlanAction(planKey), planKey }),+ const comparedPlans: SettingsBillingComparedPlan[] = displayedPlanKeys.map(+ (planKey) => ({+ action: getPlanAction(planKey),+ isLegacy: !getPlanByPlanKey(planKey).isSellable,+ planKey,+ }),);return { comparedPlans };diff --git a/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.ts b/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.tsindex f9ebb481dc2..e33e4836df7 100644--- a/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.ts+++ b/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.ts@@ -3,5 +3,6 @@ import { type BillingPlanKey } from '~/generated-metadata/graphql';export type SettingsBillingComparedPlan = {action: SettingsBillingPlanAction;+ isLegacy?: boolean;planKey: BillingPlanKey;};