Skip to content

Commit 9a1bc45

Browse files
fix(mosaic): render the profile opened from UserButton in modal mode
1 parent 0703fdb commit 9a1bc45

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

‎packages/mosaic/src/features/user-button/__tests__/user-button.feature.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { openMenu } from '../../../__tests__/feature/menu';
2222
import { renderWithClerk } from '../../../__tests__/feature/render';
2323
import { PortalProvider } from '../../../primitives/portal';
24+
import { signedIn as withConnectedAccounts } from '../../user-profile/user-profile-connected-accounts-section/__tests__/user-profile-connected-accounts.fixtures';
2425
import type { UserButtonProps } from '../user-button';
2526
import { UserButton } from '../user-button';
2627

@@ -486,6 +487,25 @@ describe('UserButton', () => {
486487
await waitFor(() => expect(popup()).toBeNull());
487488
});
488489

490+
it('opens the profile as a modal, so an OAuth connection returns to it', async () => {
491+
await wideViewport();
492+
await renderUserButton({}, withConnectedAccounts([]));
493+
const request = holdRequests('post', '/v1/me/external_accounts');
494+
const user = await open();
495+
496+
await user.click(screen.getByRole('button', { name: 'Settings' }));
497+
await user.click(await screen.findByRole('button', { name: 'Connect GitHub' }));
498+
await waitFor(() => expect(request.requests).toHaveLength(1));
499+
500+
const body = new URLSearchParams(await request.requests[0]?.text());
501+
const encoded = new URL(body.get('redirect_url') || '').searchParams.get('__clerk_modal_state');
502+
expect(JSON.parse(window.atob(encoded || ''))).toMatchObject({
503+
componentName: 'UserProfile',
504+
socialProvider: 'github',
505+
});
506+
request.fail();
507+
});
508+
489509
it('opens the profile into the portal root the app provides', async () => {
490510
await wideViewport();
491511
const container = document.body.appendChild(document.createElement('div'));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useUser } from '@clerk/shared/react';
22
import React from 'react';
33

4-
import { UserProfile } from './user-profile';
4+
import { UserProfileSurface } from './user-profile';
55
import type { UserProfileModalContentProps } from './user-profile.modal.types';
66

77
export default function UserProfileModalContent({ options, close }: UserProfileModalContentProps): React.ReactElement {
@@ -16,8 +16,9 @@ export default function UserProfileModalContent({ options, close }: UserProfileM
1616

1717
const { page, ...props } = options ?? {};
1818
return (
19-
<UserProfile
19+
<UserProfileSurface
2020
{...props}
21+
presentation='modal'
2122
defaultPage={page}
2223
/>
2324
);

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ export interface UserProfileProps
120120
* <UserProfile additionalOAuthScopes={{ google: ['https://www.googleapis.com/auth/calendar.readonly'] }} />
121121
* ```
122122
*/
123-
export function UserProfile({
123+
export function UserProfile(props: UserProfileProps) {
124+
return (
125+
<UserProfileSurface
126+
{...props}
127+
presentation='mounted'
128+
/>
129+
);
130+
}
131+
132+
export function UserProfileSurface({
133+
presentation,
124134
mode = 'combined',
125135
organizationProfileProps,
126136
customPages,
@@ -129,7 +139,7 @@ export function UserProfile({
129139
additionalOAuthScopes,
130140
fallback,
131141
apiKeysProps: { hide: hideAPIKeys = false, ...apiKeysProps } = {},
132-
}: UserProfileProps) {
142+
}: UserProfileProps & { presentation: NonNullable<UserProfileOptions['mode']> }) {
133143
const model = useUserProfileUserModel();
134144
const builtInPages = useUserProfilePages();
135145

@@ -156,7 +166,7 @@ export function UserProfile({
156166
return (
157167
<UserProfileProvider
158168
additionalOAuthScopes={additionalOAuthScopes}
159-
mode='mounted'
169+
mode={presentation}
160170
>
161171
{mode === 'user' ? (
162172
<AccountUserProfileView {...viewProps} />

0 commit comments

Comments
 (0)