Skip to content

Commit

Permalink
fix(clerk-js): In <CreateOrganization /> skip invitation page if max …
Browse files Browse the repository at this point in the history
…allowed memberships equal 1

This commit modifies the logic of the <CreateOrganization /> component
to handle the case the newly create organization has max allowed
memberships equal to 1. In this case, we shouldn't render the invitation
page, as the user can't invite any more members, and they will need to
skip it either way
  • Loading branch information
chanioxaris committed Jul 12, 2023
1 parent e303684 commit cf91866
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-hounds-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

In the <CreateOrganization /> component, if the newly created organization has max allowed membership equal to 1, skip the invitation page
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const CreateOrganizationPage = withCardStateProvider(() => {
const inviteTitle = localizationKeys('organizationProfile.invitePage.title');
const card = useCardState();
const [file, setFile] = React.useState<File | null>();
const { createOrganization } = useCoreOrganizations();
const { createOrganization, isLoaded } = useCoreOrganizations();
const { setActive, closeCreateOrganization } = useCoreClerk();
const { mode, navigateAfterCreateOrganization } = useCreateOrganizationContext();
const { organization } = useCoreOrganization();
Expand Down Expand Up @@ -51,11 +51,26 @@ export const CreateOrganizationPage = withCardStateProvider(() => {
return;
}

return createOrganization?.({ name: nameField.value, slug: slugField.value })
.then(org => (file ? org.setLogo({ file }) : org))
.then(org => setActive({ organization: org }))
.then(wizard.nextStep)
.catch(err => handleError(err, [nameField, slugField], card.setError));
if (!isLoaded) {
return;
}

try {
const organization = await createOrganization({ name: nameField.value, slug: slugField.value });
if (file) {
await organization.setLogo({ file });
}

await setActive({ organization });

if (organization.maxAllowedMemberships === 1) {
return completeFlow();
}

wizard.nextStep();
} catch (err) {
handleError(err, [nameField, slugField], card.setError);
}
};

const completeFlow = () => {
Expand Down

0 comments on commit cf91866

Please sign in to comment.