@@ -2,7 +2,6 @@ import { buildTaskUrl } from '@clerk/shared/internal/clerk-js/sessionTasks';
22import { getFullName , getIdentifier } from '@clerk/shared/internal/clerk-js/user' ;
33import { useClerk , useOrganization , useSession , useUser } from '@clerk/shared/react' ;
44import type {
5- OrganizationProfileModalProps ,
65 OrganizationResource ,
76 OrganizationSwitcherProps ,
87 UserButtonProps as ClerkUserButtonProps ,
@@ -15,6 +14,8 @@ import { useMosaicRouter } from '../../hooks/use-mosaic-router';
1514import { useModal } from '../../modals/use-modal' ;
1615import { useGetPortalContainer } from '../../primitives/portal' ;
1716import { replaceInPages , shrinkTotal } from '../../utils/infinite-pages' ;
17+ import { organizationProfileModal } from '../organization-profile/organization-profile.modal' ;
18+ import type { OrganizationProfileModalOptions } from '../organization-profile/organization-profile.modal.types' ;
1819import { userProfileModal } from '../user-profile/user-profile.modal' ;
1920import type { UserProfileModalOptions } from '../user-profile/user-profile.modal.types' ;
2021import type {
@@ -115,7 +116,7 @@ export interface SwitcherModalProps {
115116 UserProfileModalOptions ,
116117 'customPages' | 'pageOrder' | 'additionalOAuthScopes' | 'apiKeysProps' | 'mode'
117118 > ;
118- organizationProfile ?: Pick < OrganizationProfileModalProps , 'customPages' | 'appearance ' > ;
119+ organizationProfile ?: Pick < OrganizationProfileModalOptions , 'customPages' | 'pageOrder ' > ;
119120}
120121
121122function resolveAfterUrl < T extends object > (
@@ -178,8 +179,8 @@ function toSession(sessionId: string, user: UserResource): SwitcherSession {
178179}
179180
180181/**
181- * @param modals - Props forwarded to the profile modals. The organization profile's custom pages arrive
182- * already bridged, since only the wrapper can render the portals behind them.
182+ * @param modals - Props forwarded to the profile modals. A `combined` user profile also carries the
183+ * organization's pages, so managing the organization opens it on them.
183184 */
184185export function useSwitcherModel ( options ?: SwitcherModelOptions , modals ?: SwitcherModalProps ) : SwitcherModel {
185186 const { isLoaded : isUserLoaded , user } = useUser ( ) ;
@@ -191,6 +192,7 @@ export function useSwitcherModel(options?: SwitcherModelOptions, modals?: Switch
191192 const clerk = useClerk ( ) ;
192193 const router = useMosaicRouter ( ) ;
193194 const userProfile = useModal ( userProfileModal ) ;
195+ const organizationProfile = useModal ( organizationProfileModal ) ;
194196 // The modal must portal into the app's own dialog root, or it renders behind the surface that opened it.
195197 const getContainer = useGetPortalContainer ( ) ;
196198 const environment = useMosaicEnvironment ( ) ;
@@ -202,17 +204,15 @@ export function useSwitcherModel(options?: SwitcherModelOptions, modals?: Switch
202204 enabled : Boolean ( environment ?. organizationSettings . enabled ) ,
203205 } ) ;
204206
207+ const organizationProfileProps = {
208+ ...modals ?. organizationProfile ,
209+ afterLeaveOrganizationUrl : options ?. afterLeaveOrganizationUrl ,
210+ } ;
211+
205212 const manageAccount = openOrNavigate ( {
206213 url : options ?. userProfileUrl ,
207214 mode : options ?. userProfileMode ,
208- openModal : ( ) =>
209- userProfile . open (
210- {
211- ...modals ?. userProfile ,
212- organizationProfileProps : { afterLeaveOrganizationUrl : options ?. afterLeaveOrganizationUrl } ,
213- } ,
214- getContainer ?.( ) ,
215- ) ,
215+ openModal : ( ) => userProfile . open ( { ...modals ?. userProfile , organizationProfileProps } , getContainer ?.( ) ) ,
216216 buildUrl : ( ) => clerk . buildUserProfileUrl ( ) ,
217217 navigate : router . navigate ,
218218 } ) ;
@@ -221,11 +221,12 @@ export function useSwitcherModel(options?: SwitcherModelOptions, modals?: Switch
221221 url : options ?. organizationProfileUrl ,
222222 mode : options ?. organizationProfileMode ,
223223 openModal : ( ) =>
224- clerk . openOrganizationProfile ( {
225- getContainer,
226- ...modals ?. organizationProfile ,
227- afterLeaveOrganizationUrl : options ?. afterLeaveOrganizationUrl ,
228- } ) ,
224+ modals ?. userProfile ?. mode === 'combined'
225+ ? userProfile . open (
226+ { ...modals . userProfile , organizationProfileProps, page : 'organization/general' } ,
227+ getContainer ?.( ) ,
228+ )
229+ : organizationProfile . open ( organizationProfileProps , getContainer ?.( ) ) ,
229230 buildUrl : ( ) => clerk . buildOrganizationProfileUrl ( ) ,
230231 navigate : router . navigate ,
231232 } ) ;
0 commit comments