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/mosaic-user-button-header-organization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/mosaic': patch
---

Show the active organization's name, instead of the account's email or username, under the user's name in the `UserButton` popover header when an organization is active in combined mode.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function requiredPopup() {
const reading = (...names: string[]) =>
within(requiredPopup())
.queryAllByText(new RegExp(`^(${names.join('|')})$`))
.filter(node => !node.closest('.cl-user-button-header'))
.map(node => node.textContent);

const current = () =>
Expand Down Expand Up @@ -788,7 +789,6 @@ describe('UserButton', () => {
await openWithList();

expect(reading('Personal account', 'Acme', 'Other', 'Create organization')).toEqual([
'Acme',
'Acme',
'Personal account',
'Other',
Expand All @@ -809,6 +809,7 @@ describe('UserButton', () => {
const user = await open();

expect(within(requiredPopup()).getByText('Alice Smith')).toBeInTheDocument();
expect(requiredPopup().querySelector('.cl-user-button-header-description')).toHaveTextContent('Acme');
expect(within(requiredPopup()).getByRole('button', { name: 'Invite' })).toBeInTheDocument();
await openSettings(user, 'Organization settings');
expect(openOrganizationProfile).toHaveBeenCalled();
Expand Down
24 changes: 16 additions & 8 deletions packages/mosaic/src/features/user-button/user-button.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ function membershipSubtitle(membership: UserButtonMembership, m: Messages, local
return joinDetails(membership.planLabel, members);
}

function headerSubtitle(lead: LeadSelection, identifier: string, m: Messages, locale: string): string {
if (lead.kind === 'organization') {
return membershipSubtitle(lead.organization, m, locale);
}
if (lead.kind === 'none') {
// No selection is not the account, so it carries no identifier line.
return '';
}
if (lead.badge) {
return lead.badge.name;
}
// An account with no name is titled by its identifier, and repeating it underneath says nothing.
return identifier === lead.name ? '' : identifier;
}

// ─── Presentational leaves ──────────────────────────────────────────────────

/**
Expand Down Expand Up @@ -437,14 +452,7 @@ function Header() {
const lead = leadSelection(data, m);
const { name } = lead;
const organization = leadOrganization(lead);
// An account with no name is titled by its identifier, and repeating it underneath says nothing.
// No selection is not the account, so it carries no identifier line either.
const subtitle =
lead.kind === 'organization'
? membershipSubtitle(lead.organization, m, locale)
: lead.kind === 'user' && identifier !== name
? identifier
: '';
const subtitle = headerSubtitle(lead, identifier, m, locale);

const actions: HeaderAction[] = [];
for (const action of data.layout.actions.header) {
Expand Down
Loading