Skip to content

Commit dac2fc3

Browse files
committed
feat(mosaic): Remove profile mode options from MosaicProvider
1 parent ae26567 commit dac2fc3

4 files changed

Lines changed: 15 additions & 50 deletions

File tree

‎.changeset/mosaic-profile-provider.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Breaking changes:
1515

1616
- `UserButton`: `mode` is replaced by `combined`, which only decides what the menu lists. `mode='user'` becomes `combined={false}`, and to keep the account-only profile too, also set `profile={{ combined: false }}` on `MosaicProvider`.
1717
- `UserButton` and `OrganizationSwitcher`: `userProfileProps` and `organizationProfileProps` move to `MosaicProvider`'s `profile`.
18-
- `UserButton` and `OrganizationSwitcher`: `userProfileUrl`, `userProfileMode`, `organizationProfileUrl` and `organizationProfileMode` move to `MosaicProvider`'s `profile`.
18+
- `UserButton` and `OrganizationSwitcher`: `userProfileUrl` and `organizationProfileUrl` move to `MosaicProvider`'s `profile`.
19+
- `UserButton` and `OrganizationSwitcher`: `userProfileMode` and `organizationProfileMode` are removed. Setting a URL routes there, and leaving it out opens the modal.
1920
- `UserButton` and `OrganizationSwitcher`: `appearance` is no longer accepted in `userProfileProps` or `organizationProfileProps`.
2021
- `UserButton` and `OrganizationSwitcher`: link items (`href`) are no longer accepted in `customPages`.
2122
- `UserButton` and `OrganizationSwitcher`: `afterLeaveOrganizationUrl` moves to `profile.organizationProfileProps`, which also takes `apiKeysProps`.

‎packages/mosaic/src/features/profile-pages/use-mosaic-profile.ts‎

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import type { OrganizationProfilePageId } from '../organization-profile/organiza
55
import type { UserProfileProps } from '../user-profile/user-profile';
66
import type { CustomProfilePage, UserProfilePageId } from '../user-profile/user-profile.types';
77

8-
export type MosaicProfile = MosaicProfileOptions & UserProfileRouting & OrganizationProfileRouting;
9-
10-
interface MosaicProfileOptions {
8+
export interface MosaicProfile {
119
/**
1210
* Whether one profile carries the account's pages and the active organization's. `false` keeps them
1311
* in separate profiles. It decides the profile's shape, not what `UserButton`'s menu lists.
@@ -24,37 +22,16 @@ interface MosaicProfileOptions {
2422
* whichever component opens or mounts it.
2523
*/
2624
organizationProfileProps?: ProfileOrganizationProps;
25+
/**
26+
* Full URL or path of your own user profile page. Setting it routes there instead of opening the modal.
27+
*/
28+
userProfileUrl?: string;
29+
/**
30+
* Full URL or path of your own organization profile page. Setting it routes there instead of opening the modal.
31+
*/
32+
organizationProfileUrl?: string;
2733
}
2834

29-
/** A URL is the whole opt-in to navigation, and `modal` forbids one, so the pair cannot contradict itself. */
30-
type UserProfileRouting =
31-
| {
32-
/** Full URL or path of your own user profile page. Setting it routes there instead of opening the modal. */
33-
userProfileUrl: string;
34-
/** How the user profile opens: `modal` opens it in place, `navigation` goes to `userProfileUrl`. Follows from whether `userProfileUrl` is set. */
35-
userProfileMode?: 'navigation';
36-
}
37-
| {
38-
/** Full URL or path of your own user profile page. Setting it routes there instead of opening the modal. */
39-
userProfileUrl?: never;
40-
/** How the user profile opens: `modal` opens it in place, `navigation` goes to `userProfileUrl`. Follows from whether `userProfileUrl` is set. */
41-
userProfileMode?: 'modal';
42-
};
43-
44-
type OrganizationProfileRouting =
45-
| {
46-
/** Full URL or path of your own organization profile page. Setting it routes there instead of opening the modal. */
47-
organizationProfileUrl: string;
48-
/** How the organization profile opens: `modal` opens it in place, `navigation` goes to `organizationProfileUrl`. Follows from whether `organizationProfileUrl` is set. */
49-
organizationProfileMode?: 'navigation';
50-
}
51-
| {
52-
/** Full URL or path of your own organization profile page. Setting it routes there instead of opening the modal. */
53-
organizationProfileUrl?: never;
54-
/** How the organization profile opens: `modal` opens it in place, `navigation` goes to `organizationProfileUrl`. Follows from whether `organizationProfileUrl` is set. */
55-
organizationProfileMode?: 'modal';
56-
};
57-
5835
/** What a profile takes beyond the profile component's own props. */
5936
export interface ProfilePages<PageId extends string> {
6037
/**

‎packages/mosaic/src/features/switcher/switcher.model.tsx‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ export function resolveAfterUrl<T extends object>(
107107
return undefined;
108108
}
109109

110-
function opensModal(url: string | undefined, mode: 'navigation' | 'modal' | undefined): boolean {
111-
return (mode ?? (url ? 'navigation' : 'modal')) === 'modal';
112-
}
113-
114110
/** Opens the modal unless a URL routes instead. An explicit mode wins; a URL on its own means navigation. */
115111
function openOrNavigate({
116112
url,
@@ -120,12 +116,13 @@ function openOrNavigate({
120116
navigate,
121117
}: {
122118
url: string | undefined;
123-
mode: 'navigation' | 'modal' | undefined;
119+
mode?: 'navigation' | 'modal';
124120
openModal: () => void;
125121
buildUrl: () => string;
126122
navigate: (to: string) => unknown;
127123
}): () => void {
128-
return opensModal(url, mode) ? () => openModal() : () => void navigate(url ?? buildUrl());
124+
const opensModal = (mode ?? (url ? 'navigation' : 'modal')) === 'modal';
125+
return opensModal ? () => openModal() : () => void navigate(url ?? buildUrl());
129126
}
130127

131128
function displayName(user: UserResource): string {
@@ -179,9 +176,7 @@ export function useSwitcherModel(
179176
userProfileProps,
180177
organizationProfileProps,
181178
userProfileUrl,
182-
userProfileMode,
183179
organizationProfileUrl,
184-
organizationProfileMode,
185180
} = profile;
186181
// The modal must portal into the app's own dialog root, or it renders behind the surface that opened it.
187182
const getContainer = useGetPortalContainer();
@@ -198,7 +193,6 @@ export function useSwitcherModel(
198193

199194
const manageAccount = openOrNavigate({
200195
url: userProfileUrl,
201-
mode: userProfileMode,
202196
openModal: () =>
203197
newProfiles
204198
? userProfile.open(mosaicUserProfile, getContainer?.())
@@ -214,7 +208,6 @@ export function useSwitcherModel(
214208

215209
const manageOrganization = openOrNavigate({
216210
url: organizationProfileUrl,
217-
mode: organizationProfileMode,
218211
openModal: () => {
219212
if (!newProfiles) {
220213
clerk.openOrganizationProfile({
@@ -234,11 +227,7 @@ export function useSwitcherModel(
234227
});
235228

236229
const managesBothInOneProfile =
237-
newProfiles &&
238-
menuMode === 'combined' &&
239-
combined &&
240-
opensModal(userProfileUrl, userProfileMode) &&
241-
opensModal(organizationProfileUrl, organizationProfileMode);
230+
newProfiles && menuMode === 'combined' && combined && !userProfileUrl && !organizationProfileUrl;
242231

243232
const createOrganization = openOrNavigate({
244233
url: options.createOrganizationUrl,

‎packages/swingset/src/stories/mosaic-provider.mdx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ its menu lists. [Profile permutations](/user-button/profile-permutations) shows
6060
| -------------------------- | -------------------------- | ------- | --------------------------------------------------------------------------------- |
6161
| `combined` | `boolean` | `true` | Whether one profile carries the account's pages and the active organization's. |
6262
| `userProfileUrl` | `string` | — | Your own user profile page. Setting it routes there instead of opening the modal. |
63-
| `userProfileMode` | `'modal' \| 'navigation'` | — | How the user profile opens. Follows from whether `userProfileUrl` is set. |
6463
| `organizationProfileUrl` | `string` | — | Your own organization profile page. Setting it routes there instead of the modal. |
65-
| `organizationProfileMode` | `'modal' \| 'navigation'` | — | How the organization profile opens. Follows from `organizationProfileUrl`. |
6664
| `userProfileProps` | `ProfileUserProps` | — | Options for the user profile. |
6765
| `organizationProfileProps` | `ProfileOrganizationProps` | — | Options for the organization profile, or its pages in a combined profile. |
6866

0 commit comments

Comments
 (0)