Skip to content

Commit 05b9734

Browse files
authoredMar 15, 2025
fix(clerk-js): Update plan fee rendering within <PlanCard /> (#5357)
1 parent 021bc5f commit 05b9734

File tree

2 files changed

+53
-40
lines changed

2 files changed

+53
-40
lines changed
 

‎.changeset/soft-houses-camp.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Update plan feed rendering within `<PlanCard />` to only render `annualMonthlyAmount` when it's greater than 0.

‎packages/clerk-js/src/ui/components/PricingTable/PlanCard.tsx

+48-40
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,19 @@ export const PlanCardHeader = React.forwardRef<HTMLDivElement, PlanCardHeaderPro
147147
const prefersReducedMotion = usePrefersReducedMotion();
148148
const { animations: layoutAnimations } = useAppearance().parsedLayout;
149149
const { plan, isCompact, planPeriod, setPlanPeriod, closeSlot } = props;
150-
const { name, avatarUrl, isActiveForPayer } = plan;
150+
const { name, avatarUrl, isActiveForPayer, annualMonthlyAmount } = plan;
151151
const isMotionSafe = !prefersReducedMotion && layoutAnimations === true;
152152
const planCardFeePeriodNoticeAnimation: ThemableCssProp = t => ({
153153
transition: isMotionSafe
154154
? `grid-template-rows ${t.transitionDuration.$slower} ${t.transitionTiming.$slowBezier}`
155155
: 'none',
156156
});
157+
const getPlanFee = React.useMemo(() => {
158+
if (annualMonthlyAmount <= 0) {
159+
return plan.amountFormatted;
160+
}
161+
return planPeriod === 'annual' ? plan.annualMonthlyAmountFormatted : plan.amountFormatted;
162+
}, [annualMonthlyAmount, planPeriod, plan.amountFormatted, plan.annualMonthlyAmountFormatted]);
157163
return (
158164
<Box
159165
ref={ref}
@@ -247,7 +253,7 @@ export const PlanCardHeader = React.forwardRef<HTMLDivElement, PlanCardHeaderPro
247253
colorScheme='body'
248254
>
249255
{plan.currencySymbol}
250-
{planPeriod === 'month' ? plan.amountFormatted : plan.annualMonthlyAmountFormatted}
256+
{getPlanFee}
251257
</Text>
252258
<Text
253259
elementDescriptor={descriptors.planCardFeePeriod}
@@ -262,47 +268,49 @@ export const PlanCardHeader = React.forwardRef<HTMLDivElement, PlanCardHeaderPro
262268
})}
263269
localizationKey={localizationKeys('__experimental_commerce.month')}
264270
/>
265-
<Box
266-
elementDescriptor={descriptors.planCardFeePeriodNotice}
267-
sx={[
268-
_ => ({
269-
width: '100%',
270-
display: 'grid',
271-
gridTemplateRows: planPeriod === 'annual' ? '1fr' : '0fr',
272-
}),
273-
planCardFeePeriodNoticeAnimation,
274-
]}
275-
// @ts-ignore - Needed until React 19 support
276-
inert={planPeriod !== 'annual' ? 'true' : undefined}
277-
>
271+
{annualMonthlyAmount > 0 ? (
278272
<Box
279-
elementDescriptor={descriptors.planCardFeePeriodNoticeInner}
280-
sx={{
281-
overflow: 'hidden',
282-
minHeight: 0,
283-
}}
284-
>
285-
<Text
286-
elementDescriptor={descriptors.planCardFeePeriodNoticeLabel}
287-
variant='caption'
288-
colorScheme='secondary'
289-
sx={t => ({
273+
elementDescriptor={descriptors.planCardFeePeriodNotice}
274+
sx={[
275+
_ => ({
290276
width: '100%',
291-
display: 'flex',
292-
alignItems: 'center',
293-
columnGap: t.space.$1,
294-
})}
277+
display: 'grid',
278+
gridTemplateRows: planPeriod === 'annual' ? '1fr' : '0fr',
279+
}),
280+
planCardFeePeriodNoticeAnimation,
281+
]}
282+
// @ts-ignore - Needed until React 19 support
283+
inert={planPeriod !== 'annual' ? 'true' : undefined}
284+
>
285+
<Box
286+
elementDescriptor={descriptors.planCardFeePeriodNoticeInner}
287+
sx={{
288+
overflow: 'hidden',
289+
minHeight: 0,
290+
}}
295291
>
296-
<Icon
297-
icon={InformationCircle}
298-
colorScheme='neutral'
299-
size='sm'
300-
aria-hidden
301-
/>{' '}
302-
<Span localizationKey={localizationKeys('__experimental_commerce.billedAnnually')} />
303-
</Text>
292+
<Text
293+
elementDescriptor={descriptors.planCardFeePeriodNoticeLabel}
294+
variant='caption'
295+
colorScheme='secondary'
296+
sx={t => ({
297+
width: '100%',
298+
display: 'flex',
299+
alignItems: 'center',
300+
columnGap: t.space.$1,
301+
})}
302+
>
303+
<Icon
304+
icon={InformationCircle}
305+
colorScheme='neutral'
306+
size='sm'
307+
aria-hidden
308+
/>{' '}
309+
<Span localizationKey={localizationKeys('__experimental_commerce.billedAnnually')} />
310+
</Text>
311+
</Box>
304312
</Box>
305-
</Box>
313+
) : null}
306314
</>
307315
) : (
308316
<Text
@@ -313,7 +321,7 @@ export const PlanCardHeader = React.forwardRef<HTMLDivElement, PlanCardHeaderPro
313321
/>
314322
)}
315323
</Flex>
316-
{plan.hasBaseFee ? (
324+
{plan.hasBaseFee && annualMonthlyAmount > 0 ? (
317325
<Box
318326
elementDescriptor={descriptors.planCardPeriodToggle}
319327
sx={t => ({

0 commit comments

Comments
 (0)