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
5 changes: 5 additions & 0 deletions .changeset/quiet-roles-show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/mosaic': minor
---

The combined organization and user switcher now shows the user's role in the active organization next to their identifier in the popup header, for example `cameron@clerk.com · Admin`.
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ describe('Switcher', () => {

const header = requiredPopup().querySelector('.cl-switcher-header');
expect(header?.querySelector('.cl-switcher-header-title')).toHaveTextContent('Acme');
expect(header?.querySelector('.cl-switcher-header-description')).toHaveTextContent('alice');
expect(header?.querySelector('.cl-switcher-header-description')).toHaveTextContent('alice · Member');
expect(header?.querySelector('.cl-switcher-avatar > [data-shape]')).toHaveAttribute('data-shape', 'square');
expect(header?.querySelector('.cl-switcher-avatar-badge > [data-shape]')).toHaveAttribute('data-shape', 'circle');
expect(within(header ?? requiredPopup()).queryAllByRole('button')).toEqual([]);
Expand Down
8 changes: 6 additions & 2 deletions packages/mosaic/src/features/switcher/switcher.model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ export function useSwitcherModel(
const { isLoaded: isUserLoaded, user } = useUser();
const { isLoaded: isSessionLoaded, session } = useSession();
// The active org names the trigger. That is not a request to turn Organizations on.
const { isLoaded: isOrgLoaded, organization } = useOrganization({
const {
isLoaded: isOrgLoaded,
organization,
membership,
} = useOrganization({
__internal_skipAttemptToEnableOrganizations: true,
});
const clerk = useClerk();
Expand Down Expand Up @@ -328,7 +332,7 @@ export function useSwitcherModel(
organizationsEnabled,
renderBranding: displayConfig.branded,
activeSession: toSession(session.id, user),
activeOrganization: organization ? toMembership(organization) : null,
activeOrganization: organization ? { ...toMembership(organization), roleName: membership?.roleName } : null,
// The user resource settles this before the paginated list answers; the count covers a stale resource.
hasOrganizations: user.organizationMemberships.length > 0 || (userMemberships.count ?? 0) > 0,
hidePersonal: forceOrganizationSelection || (options.hidePersonal ?? false),
Expand Down
2 changes: 2 additions & 0 deletions packages/mosaic/src/features/switcher/switcher.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface SwitcherMembership {
imageUrl?: string;
membersCount?: number;
planLabel?: string;
/** The signed-in user's role in this organization, as Clerk names it. */
roleName?: string;
}

export interface SwitcherSuggestion {
Expand Down
4 changes: 3 additions & 1 deletion packages/mosaic/src/features/switcher/switcher.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ function membershipSubtitle(membership: SwitcherMembership, m: Messages, locale:

function headerSubtitle(lead: LeadSelection, identifier: string, m: Messages, locale: string): string {
if (lead.kind === 'organization') {
return lead.user ? identifier : membershipSubtitle(lead.organization, m, locale);
return lead.user
? joinDetails(identifier, lead.organization.roleName)
: membershipSubtitle(lead.organization, m, locale);
}
if (lead.kind === 'none') {
// No selection is not the account, so it carries no identifier line.
Expand Down
1 change: 1 addition & 0 deletions packages/swingset/src/stories/fixtures/switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const nestLabs: SwitcherMembership = {
name: 'NestLabs Creative',
membersCount: 24,
planLabel: 'Pro plan',
roleName: 'Admin',
imageUrl: defaultOrgLogo,
};

Expand Down
Loading