Skip to content

Commit f318d22

Browse files
authored
fix(clerk-js, shared, clerk-react): Make props of PlanDetails stricter (#6472)
1 parent 1cc66ab commit f318d22

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

.changeset/shaky-sloths-unite.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
'@clerk/nextjs': minor
5+
'@clerk/clerk-react': minor
6+
---
7+
8+
[Billing Beta] Update `PlanDetailsProps` to reflect that either `planId` or `plan` is allowed.

packages/clerk-js/src/ui/components/Plans/__tests__/PlanDetails.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('PlanDetails', () => {
4545
currency: 'USD',
4646
isDefault: false,
4747
payerType: ['user'],
48+
forPayerType: 'user' as const,
4849
publiclyVisible: true,
4950
slug: 'test-plan',
5051
avatarUrl: 'https://example.com/avatar.png',

packages/clerk-js/src/ui/lazyModules/providers.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, { lazy, Suspense } from 'react';
55
import type { FlowMetadata } from '../elements/contexts';
66
import type { Drawer } from '../elements/Drawer';
77
import type { ThemableCssProp } from '../styledSystem';
8+
import type { AvailableComponentCtx } from '../types';
89
import type { ClerkComponentName } from './components';
910
import { ClerkComponents } from './components';
1011

@@ -76,7 +77,11 @@ export const LazyComponentRenderer = (props: LazyComponentRendererProps) => {
7677
>
7778
<Portal
7879
node={props.node}
79-
component={ClerkComponents[props.componentName as ClerkComponentName]}
80+
component={
81+
ClerkComponents[props.componentName as ClerkComponentName] as React.ComponentType<
82+
Omit<AvailableComponentCtx, 'componentName'>
83+
>
84+
}
8085
props={props.componentProps}
8186
componentName={props.componentName}
8287
/>

packages/react/src/components/PlanDetailsButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { withClerk } from './withClerk';
3636
export const PlanDetailsButton = withClerk(
3737
({ clerk, children, ...props }: WithClerkProp<React.PropsWithChildren<__experimental_PlanDetailsButtonProps>>) => {
3838
const { plan, planId, initialPlanPeriod, planDetailsProps, ...rest } = props;
39+
3940
children = normalizeWithDefaultValue(children, 'Plan details');
4041
const child = assertSingleChild(children)('PlanDetailsButton');
4142

@@ -49,7 +50,7 @@ export const PlanDetailsButton = withClerk(
4950
planId,
5051
initialPlanPeriod,
5152
...planDetailsProps,
52-
});
53+
} as __experimental_PlanDetailsButtonProps);
5354
};
5455

5556
const wrappedChildClickHandler: React.MouseEventHandler = async e => {

packages/types/src/clerk.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,10 +1886,20 @@ export type __experimental_CheckoutButtonProps = {
18861886
* <ClerkProvider clerkJsVersion="x.x.x" />
18871887
* ```
18881888
*/
1889-
export type __internal_PlanDetailsProps = {
1889+
export type __internal_PlanDetailsProps = (
1890+
| {
1891+
planId: string;
1892+
plan?: never;
1893+
}
1894+
| {
1895+
/**
1896+
* The plan object will be used as initial data until the plan is fetched from the server.
1897+
*/
1898+
plan: CommercePlanResource;
1899+
planId?: never;
1900+
}
1901+
) & {
18901902
appearance?: PlanDetailTheme;
1891-
plan?: CommercePlanResource;
1892-
planId?: string;
18931903
initialPlanPeriod?: CommerceSubscriptionPlanPeriod;
18941904
portalId?: string;
18951905
portalRoot?: PortalRoot;
@@ -1905,9 +1915,19 @@ export type __internal_PlanDetailsProps = {
19051915
* <ClerkProvider clerkJsVersion="x.x.x" />
19061916
* ```
19071917
*/
1908-
export type __experimental_PlanDetailsButtonProps = {
1909-
plan?: CommercePlanResource;
1910-
planId?: string;
1918+
export type __experimental_PlanDetailsButtonProps = (
1919+
| {
1920+
planId: string;
1921+
plan?: never;
1922+
}
1923+
| {
1924+
/**
1925+
* The plan object will be used as initial data until the plan is fetched from the server.
1926+
*/
1927+
plan: CommercePlanResource;
1928+
planId?: never;
1929+
}
1930+
) & {
19111931
initialPlanPeriod?: CommerceSubscriptionPlanPeriod;
19121932
planDetailsProps?: {
19131933
appearance?: PlanDetailTheme;

0 commit comments

Comments
 (0)