Skip to content

chore(clerk-js): Split <PlanDetails/> and <SubcriptionDetails/> #6148

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 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
17 changes: 16 additions & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
__internal_ComponentNavigationContext,
__internal_OAuthConsentProps,
__internal_PlanDetailsProps,
__internal_SubscriptionDetailsProps,
__internal_UserVerificationModalProps,
APIKeysNamespace,
APIKeysProps,
Expand Down Expand Up @@ -589,7 +590,7 @@ export class Clerk implements ClerkInterface {
void this.#componentControls.ensureMounted().then(controls => controls.closeDrawer('checkout'));
};

public __internal_openPlanDetails = (props?: __internal_PlanDetailsProps): void => {
public __internal_openPlanDetails = (props: __internal_PlanDetailsProps): void => {
this.assertComponentsReady(this.#componentControls);
if (disabledBillingFeature(this, this.environment)) {
if (this.#instanceType === 'development') {
Expand All @@ -602,13 +603,27 @@ export class Clerk implements ClerkInterface {
void this.#componentControls
.ensureMounted({ preloadHint: 'PlanDetails' })
.then(controls => controls.openDrawer('planDetails', props || {}));

this.telemetry?.record(eventPrebuiltComponentOpened(`PlanDetails`, props));
};

public __internal_closePlanDetails = (): void => {
this.assertComponentsReady(this.#componentControls);
void this.#componentControls.ensureMounted().then(controls => controls.closeDrawer('planDetails'));
};

public __internal_openSubscriptionDetails = (props?: __internal_SubscriptionDetailsProps): void => {
this.assertComponentsReady(this.#componentControls);
void this.#componentControls
.ensureMounted({ preloadHint: 'SubscriptionDetails' })
.then(controls => controls.openDrawer('subscriptionDetails', props || {}));
};

public __internal_closeSubscriptionDetails = (): void => {
this.assertComponentsReady(this.#componentControls);
void this.#componentControls.ensureMounted().then(controls => controls.closeDrawer('subscriptionDetails'));
};

public __internal_openReverification = (props?: __internal_UserVerificationModalProps): void => {
this.assertComponentsReady(this.#componentControls);
if (noUserExists(this)) {
Expand Down
26 changes: 22 additions & 4 deletions packages/clerk-js/src/ui/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createDeferredPromise } from '@clerk/shared/utils';
import type {
__internal_CheckoutProps,
__internal_PlanDetailsProps,
__internal_SubscriptionDetailsProps,
__internal_UserVerificationProps,
Appearance,
Clerk,
Expand Down Expand Up @@ -36,7 +37,7 @@ import {
UserVerificationModal,
WaitlistModal,
} from './lazyModules/components';
import { MountedCheckoutDrawer, MountedPlanDetailDrawer } from './lazyModules/drawers';
import { MountedCheckoutDrawer, MountedPlanDetailDrawer, MountedSubscriptionDetailDrawer } from './lazyModules/drawers';
import {
LazyComponentRenderer,
LazyImpersonationFabProvider,
Expand Down Expand Up @@ -106,16 +107,18 @@ export type ComponentControls = {
notify?: boolean;
},
) => void;
openDrawer: <T extends 'checkout' | 'planDetails'>(
openDrawer: <T extends 'checkout' | 'planDetails' | 'subscriptionDetails'>(
drawer: T,
props: T extends 'checkout'
? __internal_CheckoutProps
: T extends 'planDetails'
? __internal_PlanDetailsProps
: never,
: T extends 'subscriptionDetails'
? __internal_SubscriptionDetailsProps
: never,
) => void;
closeDrawer: (
drawer: 'checkout' | 'planDetails',
drawer: 'checkout' | 'planDetails' | 'subscriptionDetails',
options?: {
notify?: boolean;
},
Expand Down Expand Up @@ -160,6 +163,10 @@ interface ComponentsState {
open: false;
props: null | __internal_PlanDetailsProps;
};
subscriptionDetailsDrawer: {
open: false;
props: null | __internal_SubscriptionDetailsProps;
};
nodes: Map<HTMLDivElement, HtmlNodeOptions>;
impersonationFab: boolean;
}
Expand Down Expand Up @@ -249,6 +256,10 @@ const Components = (props: ComponentsProps) => {
open: false,
props: null,
},
subscriptionDetailsDrawer: {
open: false,
props: null,
},
nodes: new Map(),
impersonationFab: false,
});
Expand All @@ -265,6 +276,7 @@ const Components = (props: ComponentsProps) => {
blankCaptchaModal,
checkoutDrawer,
planDetailsDrawer,
subscriptionDetailsDrawer,
nodes,
} = state;

Expand Down Expand Up @@ -588,6 +600,12 @@ const Components = (props: ComponentsProps) => {
onOpenChange={() => componentsControls.closeDrawer('planDetails')}
/>

<MountedSubscriptionDetailDrawer
appearance={state.appearance}
subscriptionDetailsDrawer={subscriptionDetailsDrawer}
onOpenChange={() => componentsControls.closeDrawer('subscriptionDetails')}
/>

{state.impersonationFab && (
<LazyImpersonationFabProvider globalAppearance={state.appearance}>
<ImpersonationFab />
Expand Down
Loading
Loading