Skip to content

Commit dacc1af

Browse files
authored
chore(clerk-js,types): Use the for prop in PricingTable (#6978)
1 parent 80e45d7 commit dacc1af

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

.changeset/weak-ways-agree.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
---
5+
6+
[Billing Beta] Replace `forOrganizations: true` with `for: "organization"` in `<PricingTable/>`.

packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function Card(props: CardProps) {
136136
subscription,
137137
plan,
138138
planPeriod,
139-
forOrganizations: pricingTableProps.forOrganizations,
139+
for: pricingTableProps.for,
140140
hasActiveOrganization: !!organization,
141141
});
142142

packages/clerk-js/src/ui/components/PricingTable/utils/pricing-footer-state.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@ const run = (args: {
4646
subscription?: BillingSubscriptionItemResource;
4747
plan?: BillingPlanResource;
4848
planPeriod?: BillingSubscriptionPlanPeriod;
49-
forOrganizations?: boolean;
49+
for?: 'user' | 'organization';
5050
hasActiveOrganization?: boolean;
5151
}) =>
5252
getPricingFooterState({
5353
subscription: args.subscription,
5454
plan: args.plan ?? basePlan,
5555
planPeriod: args.planPeriod ?? 'month',
56-
forOrganizations: args.forOrganizations,
56+
for: args.for,
5757
hasActiveOrganization: args.hasActiveOrganization ?? false,
5858
});
5959

6060
describe('usePricingFooterState', () => {
6161
it('hides footer when org plans and no active org', () => {
62-
const res = run({ subscription: undefined, forOrganizations: true, hasActiveOrganization: false });
62+
const res = run({ subscription: undefined, for: 'organization', hasActiveOrganization: false });
6363
expect(res).toEqual({ shouldShowFooter: false, shouldShowFooterNotice: false });
6464
});
6565

6666
it('shows footer when no subscription and user plans', () => {
67-
const res = run({ subscription: undefined, forOrganizations: false });
67+
const res = run({ subscription: undefined, for: 'user' });
6868
expect(res).toEqual({ shouldShowFooter: true, shouldShowFooterNotice: false });
6969
});
7070

packages/clerk-js/src/ui/components/PricingTable/utils/pricing-footer-state.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type UsePricingFooterStateParams = {
44
subscription: BillingSubscriptionItemResource | undefined;
55
plan: BillingPlanResource;
66
planPeriod: BillingSubscriptionPlanPeriod;
7-
forOrganizations?: boolean;
7+
for?: 'user' | 'organization';
88
hasActiveOrganization: boolean;
99
};
1010

@@ -13,14 +13,14 @@ type UsePricingFooterStateParams = {
1313
* @returns [shouldShowFooter, shouldShowFooterNotice]
1414
*/
1515
const valueResolution = (params: UsePricingFooterStateParams): [boolean, boolean] => {
16-
const { subscription, plan, planPeriod, forOrganizations, hasActiveOrganization } = params;
16+
const { subscription, plan, planPeriod, for: forWhom, hasActiveOrganization } = params;
1717
const show_with_notice: [boolean, boolean] = [true, true];
1818
const show_without_notice: [boolean, boolean] = [true, false];
1919
const hide: [boolean, boolean] = [false, false];
2020

2121
// No subscription
2222
if (!subscription) {
23-
if (forOrganizations && !hasActiveOrganization) {
23+
if (forWhom === 'organization' && !hasActiveOrganization) {
2424
return hide;
2525
}
2626
return show_without_notice;

packages/clerk-js/src/ui/contexts/ClerkUIComponentsContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function ComponentContextProvider({
9595
);
9696
case 'PricingTable':
9797
return (
98-
<SubscriberTypeContext.Provider value={(props as PricingTableProps).forOrganizations ? 'organization' : 'user'}>
98+
<SubscriberTypeContext.Provider value={(props as PricingTableProps).for || 'user'}>
9999
<PricingTableContext.Provider value={{ componentName, ...(props as PricingTableProps) }}>
100100
{children}
101101
</PricingTableContext.Provider>

packages/types/src/clerk.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,10 +1829,11 @@ type PricingTableDefaultProps = {
18291829

18301830
type PricingTableBaseProps = {
18311831
/**
1832-
* Whether to show pricing table for organizations.
1833-
* @default false
1832+
* The subscriber type to display plans for.
1833+
* If `organization`, show plans for the active organization; otherwise for the user.
1834+
* @default 'user'
18341835
*/
1835-
forOrganizations?: boolean;
1836+
for?: ForPayerType;
18361837
/**
18371838
* Customisation options to fully match the Clerk components to your own brand.
18381839
* These options serve as overrides and will be merged with the global `appearance`

0 commit comments

Comments
 (0)