From 968d9c2651ce25f6e03c2e6eecd81f7daf876f03 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Thu, 29 Jun 2023 13:35:36 +0300 Subject: [PATCH] fix(clerk-react): Add `openCreateOrganization` method to isomorphicClerk This was causing `const {openCreateOrganization} = useClerk()` to result in an error when the function was called --- .changeset/rude-glasses-hang.md | 5 +++++ packages/react/src/isomorphicClerk.ts | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .changeset/rude-glasses-hang.md diff --git a/.changeset/rude-glasses-hang.md b/.changeset/rude-glasses-hang.md new file mode 100644 index 0000000000..83f4864251 --- /dev/null +++ b/.changeset/rude-glasses-hang.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-react': patch +--- + +Populate `openCreateOrganization` return from the `useClerk()` hook diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index a659a55688..a4a71fd367 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -62,6 +62,7 @@ export default class IsomorphicClerk { private preopenSignUp?: null | SignUpProps = null; private preopenUserProfile?: null | UserProfileProps = null; private preopenOrganizationProfile?: null | OrganizationProfileProps = null; + private preopenCreateOrganization?: null | CreateOrganizationProps = null; private premountSignInNodes = new Map(); private premountSignUpNodes = new Map(); private premountUserProfileNodes = new Map(); @@ -239,6 +240,10 @@ export default class IsomorphicClerk { clerkjs.openUserProfile(this.preopenUserProfile); } + if (this.preopenCreateOrganization !== null) { + clerkjs.openCreateOrganization(this.preopenCreateOrganization); + } + this.premountSignInNodes.forEach((props: SignInProps, node: HTMLDivElement) => { clerkjs.mountSignIn(node, props); }); @@ -389,6 +394,22 @@ export default class IsomorphicClerk { } }; + openCreateOrganization = (props?: CreateOrganizationProps): void => { + if (this.clerkjs && this.#loaded) { + this.clerkjs.openCreateOrganization(props); + } else { + this.preopenCreateOrganization = props; + } + }; + + closeCreateOrganization = (): void => { + if (this.clerkjs && this.#loaded) { + this.clerkjs.closeCreateOrganization(); + } else { + this.preopenCreateOrganization = null; + } + }; + openSignUp = (props?: SignUpProps): void => { if (this.clerkjs && this.#loaded) { this.clerkjs.openSignUp(props);