Skip to content

The open alternative to Salesforce, designed for AI.

Rework plan comparison layout on mobile (#28008)

Marieac4f2b6783d8
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.tsx
index f9ced3f2901..39e00d5d09e 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,7 +16,7 @@ import {
type SegmentedControlOption,
} from 'twenty-ui/components/input';
import { Button } from 'twenty-ui/primitives/input';
-import { themeCssVariables } from 'twenty-ui/theme';
+import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme';
import {
BillingPlanKey,
SubscriptionInterval,
@@ -33,6 +33,8 @@ type SettingsBillingPlanComparisonTableProps = {
const STICKY_HEADER_TOP_OFFSET = themeCssVariables.spacing[6];
+const MOBILE_COMPARISON_GRID_COLUMNS = 'repeat(2, minmax(0, 1fr))';
+
const StyledContentContainer = styled.div`
max-width: 694px;
width: 100%;
@@ -46,6 +48,26 @@ const StyledStickyHeaderContainer = styled.div`
top: 0;
width: 100%;
z-index: 2;
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ margin-top: 0;
+ padding-top: 0;
+ position: static;
+ }
+`;
+
+const StyledMobilePlanNamesGrid = styled.div`
+ 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};
+ position: sticky;
+ top: 0;
+ z-index: 2;
+ }
`;
const StyledComparisonTable = styled.div`
@@ -64,6 +86,10 @@ const StyledComparisonHeaderGrid = styled.div`
overflow: clip;
row-gap: 1px;
width: 100%;
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ grid-template-columns: minmax(0, 1fr);
+ }
`;
const StyledComparisonBodyGrid = styled.div`
@@ -71,6 +97,10 @@ const StyledComparisonBodyGrid = styled.div`
grid-template-columns: repeat(3, minmax(0, 1fr));
overflow: clip;
width: 100%;
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ grid-template-columns: ${MOBILE_COMPARISON_GRID_COLUMNS};
+ }
`;
const StyledHeaderCell = styled.div`
@@ -84,6 +114,11 @@ const StyledHeaderCell = styled.div`
min-width: 0;
overflow: clip;
padding: ${themeCssVariables.spacing[4]};
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ gap: ${themeCssVariables.spacing[4]};
+ min-height: auto;
+ }
`;
const StyledHeaderText = styled.div`
@@ -105,6 +140,14 @@ const StyledPlanTitle = styled.div`
width: 100%;
`;
+const StyledMobilePlanName = styled(StyledPlanTitle)`
+ display: block;
+ overflow: hidden;
+ padding: ${themeCssVariables.spacing[2]};
+ text-overflow: ellipsis;
+ white-space: nowrap;
+`;
+
const StyledComparisonTitle = styled(StyledPlanTitle)`
color: ${themeCssVariables.font.color.secondary};
font-weight: ${themeCssVariables.font.weight.regular};
@@ -145,6 +188,14 @@ const StyledActionSlot = styled.div`
> * {
max-width: 100%;
}
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ width: 100%;
+
+ > * {
+ width: 100%;
+ }
+ }
`;
export const SettingsBillingPlanComparisonTable = ({
@@ -159,6 +210,9 @@ export const SettingsBillingPlanComparisonTable = ({
const formatAnimatedPrice = (value: number) =>
formatNumber(Math.max(0, value));
+ const getPlanTitle = (planKey: BillingPlanKey) =>
+ planKey === BillingPlanKey.PRO ? t`Pro plan` : t`Organization`;
+
const billingIntervalOptions = [
{
label: t`Annual`,
@@ -200,11 +254,7 @@ export const SettingsBillingPlanComparisonTable = ({
return (
<StyledHeaderCell key={planKey}>
<StyledHeaderText>
- <StyledPlanTitle>
- {planKey === BillingPlanKey.PRO
- ? t`Pro plan`
- : t`Organization`}
- </StyledPlanTitle>
+ <StyledPlanTitle>{getPlanTitle(planKey)}</StyledPlanTitle>
<StyledPriceLine>
<StyledPrice>
$
@@ -237,6 +287,14 @@ export const SettingsBillingPlanComparisonTable = ({
</StyledComparisonHeaderGrid>
</StyledStickyHeaderContainer>
+ <StyledMobilePlanNamesGrid aria-hidden>
+ {SETTINGS_BILLING_COMPARED_PLAN_KEYS.map((planKey) => (
+ <StyledMobilePlanName key={planKey}>
+ {getPlanTitle(planKey)}
+ </StyledMobilePlanName>
+ ))}
+ </StyledMobilePlanNamesGrid>
+
<StyledComparisonBodyGrid>
{SETTINGS_BILLING_PLAN_COMPARISON_ROWS.map((row, rowIndex) => (
<SettingsBillingPlanComparisonTableRow
diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx
index 483fb515ec3..7bdedc36a3b 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx
@@ -6,7 +6,7 @@ import {
import { useLingui } from '@lingui/react/macro';
import { styled } from '@linaria/react';
import { IconCheck, IconX } from 'twenty-ui/icon';
-import { themeCssVariables, useTheme } from 'twenty-ui/theme';
+import { MOBILE_VIEWPORT, themeCssVariables, useTheme } from 'twenty-ui/theme';
const StyledFeatureCell = styled.div<{
hasTopBorder?: boolean;
@@ -28,6 +28,24 @@ const StyledFeatureCell = styled.div<{
min-height: 40px;
min-width: 0;
padding: 0 ${themeCssVariables.spacing[4]};
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ border-top: 0;
+ min-height: auto;
+ padding: ${themeCssVariables.spacing[1]} ${themeCssVariables.spacing[2]}
+ ${themeCssVariables.spacing[2]};
+ }
+`;
+
+const StyledFeatureLabelCell = styled(StyledFeatureCell)`
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ border-top: ${({ hasTopBorder }) =>
+ hasTopBorder
+ ? `1px solid ${themeCssVariables.border.color.medium}`
+ : '0'};
+ grid-column: 1 / -1;
+ padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[2]} 0;
+ }
`;
const StyledCategoryCell = styled.div<{ hasTopBorder?: boolean }>`
@@ -44,6 +62,10 @@ const StyledCategoryCell = styled.div<{ hasTopBorder?: boolean }>`
line-height: 1.4;
min-height: 40px;
padding: 0 ${themeCssVariables.spacing[4]};
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ padding: 0 ${themeCssVariables.spacing[2]};
+ }
`;
const StyledCellText = styled.span`
@@ -51,6 +73,10 @@ const StyledCellText = styled.span`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ white-space: normal;
+ }
`;
const StyledComparisonCellIcon = styled.div<{ isIncluded: boolean }>`
@@ -111,9 +137,9 @@ export const SettingsBillingPlanComparisonTableRow = ({
return (
<>
- <StyledFeatureCell hasTopBorder={hasTopBorder} isLabel>
+ <StyledFeatureLabelCell hasTopBorder={hasTopBorder} isLabel>
<StyledCellText>{i18n._(row.featureLabel)}</StyledCellText>
- </StyledFeatureCell>
+ </StyledFeatureLabelCell>
{SETTINGS_BILLING_COMPARED_PLAN_KEYS.map((planKey) => (
<StyledFeatureCell hasTopBorder={hasTopBorder} key={planKey}>
<SettingsBillingPlanComparisonCellContent cell={row.plans[planKey]} />
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.tsx
index 18a52b586a1..fc9f805785a 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
@@ -58,30 +58,54 @@ const meta = {
export default meta;
type Story = StoryObj<typeof meta>;
+const playBillingPeriodToggle: NonNullable<Story['play']> = async ({
+ canvasElement,
+ args,
+}) => {
+ const canvas = within(canvasElement);
+ const period = within(
+ canvas.getByRole('radiogroup', { name: 'Billing period' }),
+ );
+
+ await expect(period.getByRole('radio', { name: 'Annual' })).toBeChecked();
+ await expect(canvas.getByText('Save 25% when billed annually')).toBeVisible();
+ await userEvent.click(period.getByRole('radio', { name: 'Monthly' }));
+ await expect(period.getByRole('radio', { name: 'Monthly' })).toBeChecked();
+ await expect(args.onBillingIntervalChange).toHaveBeenLastCalledWith(
+ SubscriptionInterval.Month,
+ );
+ await expect(canvas.getByText('Billed monthly')).toBeVisible();
+ await userEvent.keyboard('{ArrowLeft}');
+ await expect(period.getByRole('radio', { name: 'Annual' })).toBeChecked();
+ await expect(args.onBillingIntervalChange).toHaveBeenLastCalledWith(
+ SubscriptionInterval.Year,
+ );
+ await expect(canvas.getByText('Save 25% when billed annually')).toBeVisible();
+};
+
export const BillingPeriod: Story = {
- play: async ({ canvasElement, args }) => {
- const canvas = within(canvasElement);
- const period = within(
- canvas.getByRole('radiogroup', { name: 'Billing period' }),
- );
+ play: playBillingPeriodToggle,
+};
- await expect(period.getByRole('radio', { name: 'Annual' })).toBeChecked();
- await expect(
- canvas.getByText('Save 25% when billed annually'),
- ).toBeVisible();
- await userEvent.click(period.getByRole('radio', { name: 'Monthly' }));
- await expect(period.getByRole('radio', { name: 'Monthly' })).toBeChecked();
- await expect(args.onBillingIntervalChange).toHaveBeenLastCalledWith(
- SubscriptionInterval.Month,
- );
- await expect(canvas.getByText('Billed monthly')).toBeVisible();
- await userEvent.keyboard('{ArrowLeft}');
- await expect(period.getByRole('radio', { name: 'Annual' })).toBeChecked();
- await expect(args.onBillingIntervalChange).toHaveBeenLastCalledWith(
- SubscriptionInterval.Year,
- );
+export const MobileBillingPeriod: Story = {
+ parameters: {
+ viewport: { defaultViewport: 'mobile1' },
+ },
+ play: async (context) => {
+ const canvas = within(context.canvasElement);
+ const periodGroup = canvas.getByRole('radiogroup', {
+ name: 'Billing period',
+ });
+ const headerCell = periodGroup.parentElement;
+ const monthlyOption = within(periodGroup).getByRole('radio', {
+ name: 'Monthly',
+ });
+
+ await expect(headerCell).not.toBeNull();
await expect(
- canvas.getByText('Save 25% when billed annually'),
- ).toBeVisible();
+ monthlyOption.getBoundingClientRect().right,
+ ).toBeLessThanOrEqual(headerCell?.getBoundingClientRect().right ?? 0);
+
+ await playBillingPeriodToggle(context);
},
};