1
1
import { useOrganizationList } from '@clerk/shared/react/index' ;
2
- import type { ComponentProps , PropsWithChildren } from 'react' ;
3
- import { useEffect , useState } from 'react' ;
2
+ import type { PropsWithChildren } from 'react' ;
3
+ import { useState } from 'react' ;
4
4
5
5
import { OrganizationListContext } from '@/ui/contexts' ;
6
6
import { Card } from '@/ui/elements/Card' ;
@@ -11,8 +11,13 @@ import { CreateOrganizationForm } from '../../CreateOrganization/CreateOrganizat
11
11
import { OrganizationListPageList } from '../../OrganizationList/OrganizationListPage' ;
12
12
import { organizationListParams } from '../../OrganizationSwitcher/utils' ;
13
13
14
- const ForceOrganizationSelectionFlows = ( ) => {
15
- const { isLoading, hasData, currentFlow, setCurrentFlow } = useForceOrganizationSelectionFlows ( ) ;
14
+ /**
15
+ * @internal
16
+ */
17
+ export const ForceOrganizationSelectionTask = withCardStateProvider ( ( ) => {
18
+ const { userMemberships, userInvitations, userSuggestions } = useOrganizationList ( organizationListParams ) ;
19
+ const isLoading = userMemberships ?. isLoading || userInvitations ?. isLoading || userSuggestions ?. isLoading ;
20
+ const hasData = ! ! ( userMemberships ?. count || userInvitations ?. count || userSuggestions ?. count ) ;
16
21
17
22
if ( isLoading ) {
18
23
return (
@@ -22,26 +27,16 @@ const ForceOrganizationSelectionFlows = () => {
22
27
) ;
23
28
}
24
29
25
- // Do not render the organization selection flow when organization memberships
26
- // get invalidated after the create organization mutation
27
- if ( hasData && currentFlow !== 'create-organization' ) {
28
- return < OrganizationSelectionPage setCurrentFlow = { setCurrentFlow } /> ;
30
+ if ( hasData ) {
31
+ return < OrganizationSelectionPage /> ;
29
32
}
30
33
31
- return < CreateOrganizationPage setCurrentFlow = { setCurrentFlow } /> ;
32
- } ;
34
+ return < CreateOrganizationPage /> ;
35
+ } ) ;
33
36
34
- const OrganizationSelectionPage = ( { setCurrentFlow } : CommonPageProps ) => {
37
+ const OrganizationSelectionPage = ( ) => {
35
38
const [ showCreateOrganizationForm , setShowCreateOrganizationForm ] = useState ( false ) ;
36
39
37
- useEffect ( ( ) => {
38
- setCurrentFlow ( 'organization-selection' ) ;
39
- } , [ setCurrentFlow ] ) ;
40
-
41
- if ( showCreateOrganizationForm ) {
42
- return < CreateOrganizationPage setCurrentFlow = { setCurrentFlow } /> ;
43
- }
44
-
45
40
return (
46
41
< OrganizationListContext . Provider
47
42
value = { {
@@ -50,20 +45,28 @@ const OrganizationSelectionPage = ({ setCurrentFlow }: CommonPageProps) => {
50
45
} }
51
46
>
52
47
< FlowCard >
53
- < OrganizationListPageList onCreateOrganizationClick = { ( ) => setShowCreateOrganizationForm ( true ) } />
48
+ { showCreateOrganizationForm ? (
49
+ < Box
50
+ sx = { t => ( {
51
+ padding : `${ t . space . $none } ${ t . space . $5 } ${ t . space . $5 } ` ,
52
+ } ) }
53
+ >
54
+ < CreateOrganizationForm
55
+ flow = 'default'
56
+ startPage = { { headerTitle : localizationKeys ( 'organizationList.createOrganization' ) } }
57
+ skipInvitationScreen
58
+ onCancel = { ( ) => setShowCreateOrganizationForm ( false ) }
59
+ />
60
+ </ Box >
61
+ ) : (
62
+ < OrganizationListPageList onCreateOrganizationClick = { ( ) => setShowCreateOrganizationForm ( true ) } />
63
+ ) }
54
64
</ FlowCard >
55
65
</ OrganizationListContext . Provider >
56
66
) ;
57
67
} ;
58
68
59
- const CreateOrganizationPage = ( {
60
- onCancel,
61
- setCurrentFlow,
62
- } : CommonPageProps & Pick < ComponentProps < typeof CreateOrganizationForm > , 'onCancel' > ) => {
63
- useEffect ( ( ) => {
64
- setCurrentFlow ( 'create-organization' ) ;
65
- } , [ setCurrentFlow ] ) ;
66
-
69
+ const CreateOrganizationPage = ( ) => {
67
70
return (
68
71
< FlowCard >
69
72
< Box
@@ -75,7 +78,6 @@ const CreateOrganizationPage = ({
75
78
flow = 'default'
76
79
startPage = { { headerTitle : localizationKeys ( 'organizationList.createOrganization' ) } }
77
80
skipInvitationScreen
78
- onCancel = { onCancel }
79
81
/>
80
82
</ Box >
81
83
</ FlowCard >
@@ -112,29 +114,3 @@ const FlowLoadingState = () => (
112
114
/>
113
115
</ Flex >
114
116
) ;
115
-
116
- type Flow = 'create-organization' | 'organization-selection' ;
117
-
118
- type CommonPageProps = {
119
- setCurrentFlow : React . Dispatch < React . SetStateAction < Flow | undefined > > ;
120
- } ;
121
-
122
- const useForceOrganizationSelectionFlows = ( ) => {
123
- const [ currentFlow , setCurrentFlow ] = useState < Flow | undefined > ( ) ;
124
- const { userMemberships, userInvitations, userSuggestions } = useOrganizationList ( organizationListParams ) ;
125
-
126
- const isLoading = userMemberships ?. isLoading || userInvitations ?. isLoading || userSuggestions ?. isLoading ;
127
- const hasData = ! ! ( userMemberships ?. count || userInvitations ?. count || userSuggestions ?. count ) ;
128
-
129
- return {
130
- currentFlow,
131
- setCurrentFlow,
132
- hasData,
133
- isLoading,
134
- } ;
135
- } ;
136
-
137
- /**
138
- * @internal
139
- */
140
- export const ForceOrganizationSelectionTask = withCardStateProvider ( ForceOrganizationSelectionFlows ) ;
0 commit comments