1- import { useOrganizationList , useUser } from '@clerk/shared/react' ;
1+ import { useOrganizationList , useSessionContext , useUser } from '@clerk/shared/react' ;
22import { useContext , useState } from 'react' ;
33
44import { Action , Actions } from '@/ui/elements/Actions' ;
@@ -117,6 +117,8 @@ const OrganizationListFlows = ({ showListInitially }: { showListInitially: boole
117117 const { navigateAfterCreateOrganization, skipInvitationScreen, hideSlug } = useOrganizationListContext ( ) ;
118118 const [ isCreateOrganizationFlow , setCreateOrganizationFlow ] = useState ( ! showListInitially ) ;
119119 const sessionTasksContext = useContext ( SessionTasksContext ) ;
120+ const session = useSessionContext ( ) ;
121+
120122 return (
121123 < >
122124 { ! isCreateOrganizationFlow && (
@@ -135,7 +137,18 @@ const OrganizationListFlows = ({ showListInitially }: { showListInitially: boole
135137 startPage = { { headerTitle : localizationKeys ( 'organizationList.createOrganization' ) } }
136138 skipInvitationScreen = { skipInvitationScreen }
137139 navigateAfterCreateOrganization = { org =>
138- navigateAfterCreateOrganization ( org ) . then ( ( ) => setCreateOrganizationFlow ( false ) )
140+ navigateAfterCreateOrganization ( org ) . then ( ( ) => {
141+ const isForceOrganizationSelectionFlow = sessionTasksContext && session ?. currentTask . key === 'org' ;
142+
143+ // During a force organization selection flow, keep displaying the creation form in a loading state
144+ // rather than showing the organization list. This allows the client-side navigation to complete
145+ // before transitioning away from this view.
146+ if ( isForceOrganizationSelectionFlow ) {
147+ return ;
148+ }
149+
150+ setCreateOrganizationFlow ( false ) ;
151+ } )
139152 }
140153 onCancel = {
141154 showListInitially && isCreateOrganizationFlow ? ( ) => setCreateOrganizationFlow ( false ) : undefined
0 commit comments