Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/some-donkeys-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/ui': patch
---

Allow creating additional memberships on unlimited `environment.organizationSettings.maxAllowedMemberships`
3 changes: 2 additions & 1 deletion packages/ui/src/common/CreateOrganizationAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const CreateOrganizationAction = (props: CreateOrganizationActionProps) =
const { organizationSettings } = useEnvironment();

const currentMembershipCount = (user?.organizationMemberships ?? []).length;
const canCreateAdditionalMembership = currentMembershipCount < organizationSettings.maxAllowedMemberships;
const canCreateAdditionalMembership =
!organizationSettings.maxAllowedMemberships || currentMembershipCount < organizationSettings.maxAllowedMemberships;

if (!user?.createOrganizationEnabled || !canCreateAdditionalMembership) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('OrganizationSwitcher', () => {
expect(getByText('Org2')).toBeInTheDocument();
});

it('does not allow creating organization if not allowed to create additional membership', async () => {
it('does not allow creating organization if max allowed memberships is reached', async () => {
const { wrapper, props } = await createFixtures(f => {
f.withOrganizations();
f.withMaxAllowedMemberships({ max: 1 });
Expand All @@ -308,6 +308,40 @@ describe('OrganizationSwitcher', () => {
expect(queryByText('Create organization')).not.toBeInTheDocument();
});

it('does allow creating organization if max allowed memberships is not reached', async () => {
const { wrapper, props } = await createFixtures(f => {
f.withOrganizations();
f.withMaxAllowedMemberships({ max: 2 });
f.withUser({
email_addresses: ['[email protected]'],
create_organization_enabled: true,
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
});
});

props.setProps({ hidePersonal: true });
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
expect(queryByText('Create organization')).toBeInTheDocument();
});

it('does allow creating organization if max allowed memberships is unlimited', async () => {
const { wrapper, props } = await createFixtures(f => {
f.withOrganizations();
f.withMaxAllowedMemberships({ max: 0 });
f.withUser({
email_addresses: ['[email protected]'],
create_organization_enabled: true,
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
});
});

props.setProps({ hidePersonal: true });
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
expect(queryByText('Create organization')).toBeInTheDocument();
});

it.each([
['Admin', 'admin'],
['Member', 'basic_member'],
Expand Down
Loading