Skip to content

Commit b4e2906

Browse files
authored
fix(ui): Allow creating additional memberships on unlimited maxAllowedMemberships (#7555)
1 parent 84ea908 commit b4e2906

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

.changeset/some-donkeys-dress.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/ui': patch
4+
---
5+
6+
Allow creating additional memberships on unlimited `environment.organizationSettings.maxAllowedMemberships`

packages/ui/src/common/CreateOrganizationAction.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const CreateOrganizationAction = (props: CreateOrganizationActionProps) =
1111
const { organizationSettings } = useEnvironment();
1212

1313
const currentMembershipCount = (user?.organizationMemberships ?? []).length;
14-
const canCreateAdditionalMembership = currentMembershipCount < organizationSettings.maxAllowedMemberships;
14+
const canCreateAdditionalMembership =
15+
!organizationSettings.maxAllowedMemberships || currentMembershipCount < organizationSettings.maxAllowedMemberships;
1516

1617
if (!user?.createOrganizationEnabled || !canCreateAdditionalMembership) {
1718
return null;

packages/ui/src/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe('OrganizationSwitcher', () => {
291291
expect(getByText('Org2')).toBeInTheDocument();
292292
});
293293

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

311+
it('does allow creating organization if max allowed memberships is not reached', async () => {
312+
const { wrapper, props } = await createFixtures(f => {
313+
f.withOrganizations();
314+
f.withMaxAllowedMemberships({ max: 2 });
315+
f.withUser({
316+
email_addresses: ['[email protected]'],
317+
create_organization_enabled: true,
318+
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
319+
});
320+
});
321+
322+
props.setProps({ hidePersonal: true });
323+
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
324+
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
325+
expect(queryByText('Create organization')).toBeInTheDocument();
326+
});
327+
328+
it('does allow creating organization if max allowed memberships is unlimited', async () => {
329+
const { wrapper, props } = await createFixtures(f => {
330+
f.withOrganizations();
331+
f.withMaxAllowedMemberships({ max: 0 });
332+
f.withUser({
333+
email_addresses: ['[email protected]'],
334+
create_organization_enabled: true,
335+
organization_memberships: [{ name: 'Org1', id: '1', role: 'admin' }],
336+
});
337+
});
338+
339+
props.setProps({ hidePersonal: true });
340+
const { queryByText, getByRole, userEvent } = render(<OrganizationSwitcher />, { wrapper });
341+
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
342+
expect(queryByText('Create organization')).toBeInTheDocument();
343+
});
344+
311345
it.each([
312346
['Admin', 'admin'],
313347
['Member', 'basic_member'],

0 commit comments

Comments
 (0)