Skip to content

Commit

Permalink
chore(clerk-js,types): Add hideSlug support to OrganizationSwitcher
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Aug 2, 2024
1 parent 10b33d7 commit cd4ccf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, Orga
navigateAfterSelectOrganization,
organizationProfileProps,
skipInvitationScreen,
hideSlug,
} = useOrganizationSwitcherContext();

const { user } = useUser();
Expand Down Expand Up @@ -85,7 +86,7 @@ export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, Orga
if (createOrganizationMode === 'navigation') {
return navigateCreateOrganization();
}
return openCreateOrganization({ afterCreateOrganizationUrl, skipInvitationScreen });
return openCreateOrganization({ afterCreateOrganizationUrl, skipInvitationScreen, hideSlug });
};

const handleItemClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,23 @@ describe('OrganizationSwitcher', () => {
expect(fixtures.clerk.openCreateOrganization).toHaveBeenCalled();
});

it('opens create organization without slug field', async () => {
const { wrapper, fixtures, props } = await createFixtures(f => {
f.withOrganizations();
f.withUser({
email_addresses: ['test@clerk.com'],
create_organization_enabled: true,
});
});

props.setProps({ hideSlug: true });
const { getByRole, queryByLabelText, userEvent } = render(<OrganizationSwitcher />, { wrapper });
await userEvent.click(getByRole('button', { name: 'Open organization switcher' }));
await userEvent.click(getByRole('menuitem', { name: 'Create organization' }));
expect(fixtures.clerk.openCreateOrganization).toHaveBeenCalled();
expect(queryByLabelText(/Slug/i)).toBeNull();
});

it('does not display create organization button if permissions not present', async () => {
const { wrapper, props } = await createFixtures(f => {
f.withOrganizations();
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,10 @@ export type OrganizationSwitcherProps = CreateOrganizationMode &
* the number of max allowed members is equal to 1
*/
skipInvitationScreen?: boolean;
/**
* Hides the slug field in the form.
*/
hideSlug?: boolean;
/**
* Customisation options to fully match the Clerk components to your own brand.
* These options serve as overrides and will be merged with the global `appearance`
Expand Down

0 comments on commit cd4ccf2

Please sign in to comment.