11import { useClerk , useSession , useUser } from '@clerk/shared/react' ;
2- import { useState , type ComponentType } from 'react' ;
2+ import { useState } from 'react' ;
33
44import { useSignOutContext , withCoreSessionSwitchGuard } from '@/ui/contexts' ;
55import { descriptors , Flex , Flow , localizationKeys , Spinner } from '@/ui/customizables' ;
@@ -14,24 +14,16 @@ import { ChooseOrganizationScreen } from './ChooseOrganizationScreen';
1414import { CreateOrganizationScreen } from './CreateOrganizationScreen' ;
1515
1616const TaskChooseOrganizationInternal = ( ) => {
17- const { signOut } = useClerk ( ) ;
1817 const { user } = useUser ( ) ;
19- const { session } = useSession ( ) ;
2018 const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView ( ) ;
21- const { otherSessions } = useMultipleSessions ( { user } ) ;
22- const { navigateAfterSignOut, navigateAfterMultiSessionSingleSignOutUrl } = useSignOutContext ( ) ;
23-
24- const handleSignOut = ( ) => {
25- if ( otherSessions . length === 0 ) {
26- return signOut ( navigateAfterSignOut ) ;
27- }
28-
29- return signOut ( navigateAfterMultiSessionSingleSignOutUrl , { sessionId : session ?. id } ) ;
30- } ;
3119
3220 const isLoading = userMemberships ?. isLoading || userInvitations ?. isLoading || userSuggestions ?. isLoading ;
3321 const hasExistingResources = ! ! ( userMemberships ?. count || userInvitations ?. count || userSuggestions ?. count ) ;
34- const identifier = user ?. primaryEmailAddress ?. emailAddress ?? user ?. username ;
22+ const isOrganizationCreationDisabled = ! isLoading && ! user ?. createOrganizationEnabled && ! hasExistingResources ;
23+
24+ if ( isOrganizationCreationDisabled ) {
25+ return < OrganizationCreationDisabledScreen /> ;
26+ }
3527
3628 return (
3729 < Flow . Root flow = 'taskChooseOrganization' >
@@ -127,18 +119,6 @@ const TaskChooseOrganizationFlows = withCardStateProvider((props: TaskChooseOrga
127119 return < ChooseOrganizationScreen onCreateOrganizationClick = { ( ) => setCurrentFlow ( 'create' ) } /> ;
128120} ) ;
129121
130- export const withOrganizationCreationEnabledGuard = < T , > ( Component : ComponentType < T > ) => {
131- return ( props : T ) => {
132- const { user } = useUser ( ) ;
133-
134- if ( ! user ?. createOrganizationEnabled ) {
135- return < OrganizationCreationDisabledScreen /> ;
136- }
137-
138- return < Component { ...props } /> ;
139- } ;
140- } ;
141-
142122function OrganizationCreationDisabledScreen ( ) {
143123 return (
144124 < Flow . Root flow = 'taskChooseOrganization' >
@@ -163,8 +143,5 @@ function OrganizationCreationDisabledScreen() {
163143}
164144
165145export const TaskChooseOrganization = withCoreSessionSwitchGuard (
166- withTaskGuard (
167- withCardStateProvider ( withOrganizationCreationEnabledGuard ( TaskChooseOrganizationInternal ) ) ,
168- 'choose-organization' ,
169- ) ,
146+ withTaskGuard ( withCardStateProvider ( TaskChooseOrganizationInternal ) , 'choose-organization' ) ,
170147) ;
0 commit comments