Skip to content

chore(clerk-js,localizations): Reposition manage subscription button #6428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/better-results-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/localizations': minor
'@clerk/clerk-js': patch
'@clerk/types': minor
---

Change placement of the manage subscription button inside `<UserProfile/>` and `<OrganizationProfile/>`
5 changes: 4 additions & 1 deletion integration/tests/pricing-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl

await u.page.waitForTimeout(1000);
await expect(u.po.page.locator('.cl-profileSectionContent__subscriptionsList').getByText('Plus')).toBeVisible();
await u.po.page.getByRole('button', { name: 'Manage subscription' }).first().click();
await u.po.page
.locator('.cl-profileSectionContent__subscriptionsList')
.getByRole('button', { name: 'Manage' })
.click();
await u.po.subscriptionDetails.waitForMounted();
await u.po.subscriptionDetails.root.locator('.cl-menuButtonEllipsisBordered').click();
await u.po.subscriptionDetails.root.getByText('Cancel subscription').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ const OrganizationBillingPageInternal = withCardStateProvider(() => {
<TabPanel sx={{ width: '100%', flexDirection: 'column' }}>
<SubscriptionsList
title={localizationKeys('organizationProfile.billingPage.subscriptionsListSection.title')}
arrowButtonText={localizationKeys(
switchPlansLabel={localizationKeys(
'organizationProfile.billingPage.subscriptionsListSection.actionLabel__switchPlan',
)}
arrowButtonEmptyText={localizationKeys(
newSubscriptionLabel={localizationKeys(
'organizationProfile.billingPage.subscriptionsListSection.actionLabel__newSubscription',
)}
manageSubscriptionLabel={localizationKeys(
'organizationProfile.billingPage.subscriptionsListSection.actionLabel__manageSubscription',
)}
/>
<Protect condition={has => has({ permission: 'org:sys_billing:manage' })}>
<PaymentSources />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { CommercePlanResource } from '@clerk/types';
import { useMemo } from 'react';

import { useProtect } from '@/ui/common/Gate';
import { ProfileSection } from '@/ui/elements/Section';

import { useProtect } from '../../common';
import {
useEnvironment,
usePlansContext,
Expand All @@ -11,44 +12,43 @@ import {
useSubscription,
} from '../../contexts';
import type { LocalizationKey } from '../../customizables';
import {
Button,
Col,
Flex,
Icon,
localizationKeys,
Span,
Table,
Tbody,
Td,
Text,
Th,
Thead,
Tr,
} from '../../customizables';
import { Col, Flex, Icon, localizationKeys, Span, Table, Tbody, Td, Text, Th, Thead, Tr } from '../../customizables';
import { ArrowsUpDown, CogFilled, Plans, Plus } from '../../icons';
import { useRouter } from '../../router';
import { SubscriptionBadge } from './badge';

const isFreePlan = (plan: CommercePlanResource) => !plan.hasBaseFee;

export function SubscriptionsList({
title,
arrowButtonText,
arrowButtonEmptyText,
switchPlansLabel,
newSubscriptionLabel,
manageSubscriptionLabel,
}: {
title: LocalizationKey;
arrowButtonText: LocalizationKey;
arrowButtonEmptyText: LocalizationKey;
switchPlansLabel: LocalizationKey;
newSubscriptionLabel: LocalizationKey;
manageSubscriptionLabel: LocalizationKey;
}) {
const { captionForSubscription, openSubscriptionDetails } = usePlansContext();
const localizationRoot = useSubscriberTypeLocalizationRoot();
const subscriberType = useSubscriberTypeContext();
const { subscriptionItems } = useSubscription();
const canManageBilling = useProtect(
has => has({ permission: 'org:sys_billing:manage' }) || subscriberType === 'user',
);
const { subscriptionItems, data: subscription } = useSubscription();
const canManageBilling =
useProtect(has => has({ permission: 'org:sys_billing:manage' })) || subscriberType === 'user';
const { navigate } = useRouter();
const { commerceSettings } = useEnvironment();

const billingPlansExist =
(commerceSettings.billing.user.hasPaidPlans && subscriberType === 'user') ||
(commerceSettings.billing.organization.hasPaidPlans && subscriberType === 'organization');

const hasActiveFreePlan = useMemo(() => {
return subscriptionItems.some(sub => isFreePlan(sub.plan) && sub.status === 'active');
}, [subscriptionItems]);

const isManageButtonVisible = canManageBilling && !!subscription && !hasActiveFreePlan;

const sortedSubscriptions = useMemo(
() =>
subscriptionItems.sort((a, b) => {
Expand Down Expand Up @@ -90,11 +90,6 @@ export function SubscriptionsList({
`${localizationRoot}.billingPage.subscriptionsListSection.tableHeader__startDate`,
)}
/>
<Th
localizationKey={localizationKeys(
`${localizationRoot}.billingPage.subscriptionsListSection.tableHeader__edit`,
)}
/>
</Tr>
</Thead>
<Tbody>
Expand Down Expand Up @@ -164,57 +159,54 @@ export function SubscriptionsList({
)}
</Text>
</Td>
<Td
sx={_ => ({
textAlign: 'right',
})}
>
<Button
aria-label='Manage subscription'
onClick={event => openSubscriptionDetails(event)}
variant='bordered'
colorScheme='secondary'
isDisabled={!canManageBilling}
sx={t => ({
width: t.sizes.$6,
height: t.sizes.$6,
})}
>
<Icon
icon={CogFilled}
sx={t => ({
width: t.sizes.$4,
height: t.sizes.$4,
opacity: t.opacity.$inactive,
})}
/>
</Button>
</Td>
</Tr>
))}
</Tbody>
</Table>
)}

{(commerceSettings.billing.user.hasPaidPlans && subscriberType === 'user') ||
(commerceSettings.billing.organization.hasPaidPlans && subscriberType === 'organization') ? (
<ProfileSection.ArrowButton
id='subscriptionsList'
textLocalizationKey={subscriptionItems.length > 0 ? arrowButtonText : arrowButtonEmptyText}
sx={[
t => ({
justifyContent: 'start',
height: t.sizes.$8,
}),
]}
leftIcon={subscriptionItems.length > 0 ? ArrowsUpDown : Plus}
leftIconSx={t => ({
width: t.sizes.$4,
height: t.sizes.$4,
})}
onClick={() => void navigate('plans')}
/>
) : null}
<ProfileSection.ButtonGroup id='subscriptionsList'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alignment of these feels off. Do we need the arrow button usage on these?

Screenshot 2025-07-30 at 9 37 41 AM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here

image

{billingPlansExist ? (
<ProfileSection.ArrowButton
id='subscriptionsList'
textLocalizationKey={subscriptionItems.length > 0 ? switchPlansLabel : newSubscriptionLabel}
sx={[
t => ({
justifyContent: 'start',
height: t.sizes.$8,
width: isManageButtonVisible ? 'unset' : undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the goal were after here? span full width if alone, justify between if there are two? Can this be handled via the parent group container vs needing to do this width changes/unsetting here?

}),
]}
leftIcon={subscriptionItems.length > 0 ? ArrowsUpDown : Plus}
leftIconSx={t => ({
width: t.sizes.$4,
height: t.sizes.$4,
})}
onClick={() => void navigate('plans')}
/>
) : null}

{isManageButtonVisible ? (
<ProfileSection.ArrowButton
id='subscriptionsList'
textLocalizationKey={manageSubscriptionLabel}
sx={[
t => ({
justifyContent: 'start',
height: t.sizes.$8,
width: 'unset',
}),
]}
rightIcon={null}
leftIcon={CogFilled}
leftIconSx={t => ({
width: t.sizes.$4,
height: t.sizes.$4,
})}
onClick={event => openSubscriptionDetails(event)}
/>
) : null}
</ProfileSection.ButtonGroup>
</ProfileSection.Root>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ const BillingPageInternal = withCardStateProvider(() => {
<TabPanel sx={_ => ({ width: '100%', flexDirection: 'column' })}>
<SubscriptionsList
title={localizationKeys('userProfile.billingPage.subscriptionsListSection.title')}
arrowButtonText={localizationKeys(
switchPlansLabel={localizationKeys(
'userProfile.billingPage.subscriptionsListSection.actionLabel__switchPlan',
)}
arrowButtonEmptyText={localizationKeys(
newSubscriptionLabel={localizationKeys(
'userProfile.billingPage.subscriptionsListSection.actionLabel__newSubscription',
)}
manageSubscriptionLabel={localizationKeys(
'userProfile.billingPage.subscriptionsListSection.actionLabel__manageSubscription',
)}
/>
<PaymentSources />
</TabPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export const APPEARANCE_KEYS = containsAllElementsConfigKeys([
'profileSectionSubtitleText',
'profileSectionContent',
'profileSectionPrimaryButton',
'profileSectionButtonGroup',
'profilePage',

'formattedPhoneNumber',
Expand Down
38 changes: 20 additions & 18 deletions packages/clerk-js/src/ui/elements/ArrowBlockButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ArrowRightIcon } from '../icons';
import type { PropsOfComponent, ThemableCssProp } from '../styledSystem';

type ArrowBlockButtonProps = PropsOfComponent<typeof Button> & {
rightIcon?: React.ComponentType;
rightIcon?: React.ComponentType | null;
rightIconSx?: ThemableCssProp;
leftIcon?: React.ComponentType | React.ReactElement;
leftIconSx?: ThemableCssProp;
Expand Down Expand Up @@ -125,23 +125,25 @@ export const ArrowBlockButton = React.forwardRef<HTMLButtonElement, ArrowBlockBu
</Text>
{badge}
</Flex>
<Icon
elementDescriptor={arrowElementDescriptor}
elementId={arrowElementId}
icon={rightIcon}
sx={[
theme => ({
transition: 'all 100ms ease',
minWidth: theme.sizes.$4,
minHeight: theme.sizes.$4,
width: '1em',
height: '1em',
opacity: `var(--arrow-opacity)`,
transform: `var(--arrow-transform)`,
}),
rightIconSx,
]}
/>
{rightIcon && (
<Icon
elementDescriptor={arrowElementDescriptor}
elementId={arrowElementId}
icon={rightIcon}
sx={[
theme => ({
transition: 'all 100ms ease',
minWidth: theme.sizes.$4,
minHeight: theme.sizes.$4,
width: '1em',
height: '1em',
opacity: `var(--arrow-opacity)`,
transform: `var(--arrow-transform)`,
}),
rightIconSx,
]}
/>
)}
</SimpleButton>
);
});
21 changes: 21 additions & 0 deletions packages/clerk-js/src/ui/elements/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ const ProfileSectionArrowButton = forwardRef<HTMLButtonElement, ProfileSectionBu
);
});

type ProfileSectionButtonGroupProps = PropsOfComponent<typeof Flex> & {
id: ProfileSectionId;
disableAnimation?: boolean;
};

const ProfileSectionButtonGroup = (props: ProfileSectionButtonGroupProps) => {
const { children, id, ...rest } = props;
return (
<Flex
elementDescriptor={descriptors.profileSectionButtonGroup}
elementId={descriptors.profileSectionButtonGroup.setId(id)}
justify='between'
gap={2}
{...rest}
>
{children}
</Flex>
);
};

export type ProfileSectionActionMenuItemProps = PropsOfComponent<typeof MenuItem> & {
destructive?: boolean;
leftIcon?: React.ComponentType | React.ReactElement;
Expand Down Expand Up @@ -318,6 +338,7 @@ export const ProfileSection = {
Item: ProfileSectionItem,
Button: ProfileSectionButton,
ArrowButton: ProfileSectionArrowButton,
ButtonGroup: ProfileSectionButtonGroup,
ActionMenu: ProfileSectionActionMenu,
ActionMenuItem: ProfileSectionActionMenuItem,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/localizations/src/ar-SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export const arSA: LocalizationResource = {
totalPaid: undefined,
},
subscriptionsListSection: {
actionLabel__manageSubscription: undefined,
actionLabel__newSubscription: undefined,
actionLabel__switchPlan: undefined,
tableHeader__edit: undefined,
Expand Down Expand Up @@ -952,6 +953,7 @@ export const arSA: LocalizationResource = {
totalPaid: undefined,
},
subscriptionsListSection: {
actionLabel__manageSubscription: undefined,
actionLabel__newSubscription: undefined,
actionLabel__switchPlan: undefined,
tableHeader__edit: undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/localizations/src/be-BY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export const beBY: LocalizationResource = {
totalPaid: undefined,
},
subscriptionsListSection: {
actionLabel__manageSubscription: undefined,
actionLabel__newSubscription: undefined,
actionLabel__switchPlan: undefined,
tableHeader__edit: undefined,
Expand Down Expand Up @@ -961,6 +962,7 @@ export const beBY: LocalizationResource = {
totalPaid: undefined,
},
subscriptionsListSection: {
actionLabel__manageSubscription: undefined,
actionLabel__newSubscription: undefined,
actionLabel__switchPlan: undefined,
tableHeader__edit: undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/localizations/src/bg-BG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const bgBG: LocalizationResource = {
totalPaid: undefined,
},
subscriptionsListSection: {
actionLabel__manageSubscription: undefined,
actionLabel__newSubscription: undefined,
actionLabel__switchPlan: undefined,
tableHeader__edit: undefined,
Expand Down Expand Up @@ -952,6 +953,7 @@ export const bgBG: LocalizationResource = {
totalPaid: undefined,
},
subscriptionsListSection: {
actionLabel__manageSubscription: undefined,
actionLabel__newSubscription: undefined,
actionLabel__switchPlan: undefined,
tableHeader__edit: undefined,
Expand Down
Loading
Loading