Skip to content

Commit a8901bd

Browse files
committed
Add path prop to top level profile props
1 parent 5bd0502 commit a8901bd

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎packages/mosaic/src/features/organization-profile/organization-profile.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function OrganizationProfile(props: OrganizationProfileProps) {
7777
const {
7878
customPages = organizationProfileProps?.customPages,
7979
pageOrder = organizationProfileProps?.pageOrder,
80-
path = '/organization',
80+
path = organizationProfileProps?.path ?? '/organization',
8181
afterLeaveOrganizationUrl = organizationProfileProps?.afterLeaveOrganizationUrl,
8282
fallback,
8383
apiKeysProps = organizationProfileProps?.apiKeysProps,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export interface ProfilePages<PageId extends string> {
5050

5151
/** Options for the underlying `<UserProfile />` component. */
5252
export interface ProfileUserProps
53-
extends ProfilePages<UserProfilePageId>, Pick<UserProfileProps, 'additionalOAuthScopes' | 'apiKeysProps'> {}
53+
extends ProfilePages<UserProfilePageId>, Pick<UserProfileProps, 'additionalOAuthScopes' | 'apiKeysProps' | 'path'> {}
5454

5555
/** Options for the underlying `<OrganizationProfile />` component. */
5656
export interface ProfileOrganizationProps
5757
extends
5858
ProfilePages<OrganizationProfilePageId>,
59-
Pick<OrganizationProfileProps, 'afterLeaveOrganizationUrl' | 'apiKeysProps'> {}
59+
Pick<OrganizationProfileProps, 'afterLeaveOrganizationUrl' | 'apiKeysProps' | 'path'> {}
6060

6161
const MosaicProfileContext = createContext<MosaicProfile>({});
6262

‎packages/mosaic/src/features/switcher/__tests__/switcher.profile.feature.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from '../../../__tests__/feature/fapi';
1818
import { openMenu } from '../../../__tests__/feature/menu';
1919
import { renderWithClerk } from '../../../__tests__/feature/render';
20+
import { useVirtualEntries } from '../../../routing/virtual-store';
2021
import { OrganizationProfile } from '../../organization-profile/organization-profile';
2122
import { OrganizationSwitcher } from '../../organization-switcher/organization-switcher';
2223
import type { MosaicProfile } from '../../profile-pages/use-mosaic-profile';
@@ -324,7 +325,24 @@ describe('a mounted OrganizationProfile under a provider profile', () => {
324325
});
325326
});
326327

328+
function Entry({ base }: { base: string }) {
329+
return <output data-testid='entry'>{JSON.stringify(useVirtualEntries().get(base) ?? null)}</output>;
330+
}
331+
327332
describe('a mounted UserProfile under a provider profile', () => {
333+
it("routes its pages under the provider's path", async () => {
334+
await renderWithProfile(
335+
<>
336+
<UserProfile />
337+
<Entry base='/account' />
338+
</>,
339+
{ userProfileProps: { path: '/account' } },
340+
);
341+
342+
await userEvent.setup().click(await screen.findByRole('tab', { name: 'Security' }));
343+
expect(JSON.parse(screen.getByTestId('entry').textContent ?? 'null')).toEqual(['security']);
344+
});
345+
328346
it('fills in what its own organizationProfileProps leave out from the provider', async () => {
329347
await renderWithProfile(<UserProfile organizationProfileProps={{ pageOrder: ['members'] }} />, {
330348
organizationProfileProps: { customPages: [{ ...terms, label: 'Audit', path: 'audit' }], pageOrder: ['general'] },

‎packages/mosaic/src/features/user-profile/user-profile.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export function UserProfile(props: UserProfileProps) {
113113
pageOrder = userProfileProps?.pageOrder,
114114
additionalOAuthScopes = userProfileProps?.additionalOAuthScopes,
115115
apiKeysProps = userProfileProps?.apiKeysProps,
116+
path = userProfileProps?.path,
116117
organizationProfileProps: {
117118
customPages: organizationCustomPages = providerOrganization?.customPages,
118119
pageOrder: organizationPageOrder = providerOrganization?.pageOrder,
@@ -130,6 +131,7 @@ export function UserProfile(props: UserProfileProps) {
130131
pageOrder={pageOrder}
131132
additionalOAuthScopes={additionalOAuthScopes}
132133
apiKeysProps={apiKeysProps}
134+
path={path}
133135
organizationProfileProps={{
134136
customPages: organizationCustomPages,
135137
pageOrder: organizationPageOrder,

0 commit comments

Comments
 (0)