Skip to content

Commit 7648ea3

Browse files
committed
fix(ui): Determine plan period correctly
1 parent 5c4beab commit 7648ea3

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

packages/ui/src/contexts/components/Plans.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const usePlansContext = () => {
328328
clerk.__internal_openCheckout({
329329
planId: plan.id,
330330
// if the plan doesn't support annual, use monthly
331-
planPeriod: planPeriod === 'annual' && !plan.annualMonthlyFee ? 'month' : planPeriod,
331+
planPeriod: determinePlanPeriod(plan, planPeriod),
332332
for: subscriberType,
333333
onSubscriptionComplete: () => {
334334
revalidateAll();
@@ -364,3 +364,19 @@ export const usePlansContext = () => {
364364
revalidateAll,
365365
};
366366
};
367+
368+
function determinePlanPeriod(plan: BillingPlanResource, period: BillingSubscriptionPlanPeriod) {
369+
if ((period === 'month' && plan.fee) || (period === 'annual' && plan.annualMonthlyFee)) {
370+
return period;
371+
}
372+
373+
if (period === 'month' && !plan.fee) {
374+
return 'annual';
375+
}
376+
377+
if (period === 'annual' && !plan.annualMonthlyFee) {
378+
return 'month';
379+
}
380+
381+
return period;
382+
}

0 commit comments

Comments
 (0)