diff --git a/.changeset/quiet-roles-show.md b/.changeset/quiet-roles-show.md new file mode 100644 index 00000000000..5e96ba5bced --- /dev/null +++ b/.changeset/quiet-roles-show.md @@ -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`. diff --git a/packages/mosaic/src/features/switcher/__tests__/switcher.feature.test.tsx b/packages/mosaic/src/features/switcher/__tests__/switcher.feature.test.tsx index 653c9cd3a72..c90993a4c8e 100644 --- a/packages/mosaic/src/features/switcher/__tests__/switcher.feature.test.tsx +++ b/packages/mosaic/src/features/switcher/__tests__/switcher.feature.test.tsx @@ -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([]); diff --git a/packages/mosaic/src/features/switcher/switcher.model.tsx b/packages/mosaic/src/features/switcher/switcher.model.tsx index d47dff42aee..32b63a5c0af 100644 --- a/packages/mosaic/src/features/switcher/switcher.model.tsx +++ b/packages/mosaic/src/features/switcher/switcher.model.tsx @@ -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(); @@ -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), diff --git a/packages/mosaic/src/features/switcher/switcher.types.ts b/packages/mosaic/src/features/switcher/switcher.types.ts index 3affed65882..1ac90e8d3cc 100644 --- a/packages/mosaic/src/features/switcher/switcher.types.ts +++ b/packages/mosaic/src/features/switcher/switcher.types.ts @@ -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 { diff --git a/packages/mosaic/src/features/switcher/switcher.view.tsx b/packages/mosaic/src/features/switcher/switcher.view.tsx index 1f3c05366c0..49e0ada8945 100644 --- a/packages/mosaic/src/features/switcher/switcher.view.tsx +++ b/packages/mosaic/src/features/switcher/switcher.view.tsx @@ -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. diff --git a/packages/swingset/src/stories/fixtures/switcher.tsx b/packages/swingset/src/stories/fixtures/switcher.tsx index e2f746458a8..7f87a9a4131 100644 --- a/packages/swingset/src/stories/fixtures/switcher.tsx +++ b/packages/swingset/src/stories/fixtures/switcher.tsx @@ -35,6 +35,7 @@ const nestLabs: SwitcherMembership = { name: 'NestLabs Creative', membersCount: 24, planLabel: 'Pro plan', + roleName: 'Admin', imageUrl: defaultOrgLogo, };