1
1
import type { OrganizationEnrollmentMode } from '@clerk/types' ;
2
2
3
3
import { useCoreOrganization , useEnvironment } from '../../contexts' ;
4
- import { Col , descriptors , Flex , localizationKeys , Spinner } from '../../customizables' ;
5
- import {
6
- BlockWithAction ,
7
- ContentPage ,
8
- Form ,
9
- FormButtons ,
10
- Header ,
11
- useCardState ,
12
- withCardStateProvider ,
13
- } from '../../elements' ;
14
- import { useFetch } from '../../hooks' ;
4
+ import { Col , Flex , localizationKeys , Spinner } from '../../customizables' ;
5
+ import { ContentPage , Form , FormButtons , Header , useCardState , withCardStateProvider } from '../../elements' ;
6
+ import { useFetch , useNavigateToFlowStart } from '../../hooks' ;
15
7
import { useRouter } from '../../router' ;
16
8
import { handleError , useFormControl } from '../../utils' ;
17
- import { EnrollmentBadge } from './EnrollmentBadge' ;
18
9
import { OrganizationProfileBreadcrumbs } from './OrganizationProfileNavbar' ;
19
10
20
11
export const VerifiedDomainPage = withCardStateProvider ( ( ) => {
21
12
const card = useCardState ( ) ;
22
13
const { organizationSettings } = useEnvironment ( ) ;
23
14
const { organization } = useCoreOrganization ( ) ;
24
- const { params, navigate } = useRouter ( ) ;
15
+ const { domains } = useCoreOrganization ( {
16
+ domains : {
17
+ infinite : true ,
18
+ } ,
19
+ } ) ;
20
+ const { navigateToFlowStart } = useNavigateToFlowStart ( ) ;
21
+ const { params, navigate, queryParams } = useRouter ( ) ;
22
+ const mode = ( queryParams . mode ?? 'edit' ) as 'select' | 'edit' ;
25
23
26
- const title = localizationKeys ( 'organizationProfile.verifiedDomainPage.title' ) ;
24
+ const allowsEdit = mode === 'edit' ;
27
25
28
26
const enrollmentMode = useFormControl ( 'enrollmentMode' , '' , {
29
27
type : 'radio' ,
@@ -32,9 +30,11 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
32
30
? [
33
31
{
34
32
value : 'manual_invitation' ,
35
- label : localizationKeys ( 'organizationProfile.verifiedDomainPage.manualInvitationOption__label' ) ,
33
+ label : localizationKeys (
34
+ 'organizationProfile.verifiedDomainPage.enrollmentTab.manualInvitationOption__label' ,
35
+ ) ,
36
36
description : localizationKeys (
37
- 'organizationProfile.verifiedDomainPage.manualInvitationOption__description' ,
37
+ 'organizationProfile.verifiedDomainPage.enrollmentTab. manualInvitationOption__description' ,
38
38
) ,
39
39
} ,
40
40
]
@@ -43,9 +43,11 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
43
43
? [
44
44
{
45
45
value : 'automatic_invitation' ,
46
- label : localizationKeys ( 'organizationProfile.verifiedDomainPage.automaticInvitationOption__label' ) ,
46
+ label : localizationKeys (
47
+ 'organizationProfile.verifiedDomainPage.enrollmentTab.automaticInvitationOption__label' ,
48
+ ) ,
47
49
description : localizationKeys (
48
- 'organizationProfile.verifiedDomainPage.automaticInvitationOption__description' ,
50
+ 'organizationProfile.verifiedDomainPage.enrollmentTab. automaticInvitationOption__description' ,
49
51
) ,
50
52
} ,
51
53
]
@@ -54,16 +56,23 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
54
56
? [
55
57
{
56
58
value : 'automatic_suggestion' ,
57
- label : localizationKeys ( 'organizationProfile.verifiedDomainPage.automaticSuggestionOption__label' ) ,
59
+ label : localizationKeys (
60
+ 'organizationProfile.verifiedDomainPage.enrollmentTab.automaticSuggestionOption__label' ,
61
+ ) ,
58
62
description : localizationKeys (
59
- 'organizationProfile.verifiedDomainPage.automaticSuggestionOption__description' ,
63
+ 'organizationProfile.verifiedDomainPage.enrollmentTab. automaticSuggestionOption__description' ,
60
64
) ,
61
65
} ,
62
66
]
63
67
: [ ] ) ,
64
68
] ,
65
69
} ) ;
66
70
71
+ const deletePending = useFormControl ( 'deleteExistingInvitationsSuggestions' , '' , {
72
+ label : localizationKeys ( 'formFieldLabel__organizationDomainDeletePending' ) ,
73
+ type : 'checkbox' ,
74
+ } ) ;
75
+
67
76
const { data : domain , status : domainStatus } = useFetch (
68
77
organization ?. getDomain ,
69
78
{
@@ -76,6 +85,7 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
76
85
} ,
77
86
) ;
78
87
88
+ const isFormDirty = deletePending . checked || domain ?. enrollmentMode !== enrollmentMode . value ;
79
89
const updateEnrollmentMode = async ( ) => {
80
90
if ( ! domain || ! organization ) {
81
91
return ;
@@ -84,8 +94,11 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
84
94
try {
85
95
await domain . updateEnrollmentMode ( {
86
96
enrollmentMode : enrollmentMode . value as OrganizationEnrollmentMode ,
97
+ deletePending : deletePending . checked ,
87
98
} ) ;
88
99
100
+ await ( domains as any ) . unstable__mutate ( ) ;
101
+
89
102
await navigate ( '../../' ) ;
90
103
} catch ( e ) {
91
104
handleError ( e , [ enrollmentMode ] , card . setError ) ;
@@ -115,36 +128,23 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
115
128
) ;
116
129
}
117
130
131
+ if ( ! ( domain . verification && domain . verification . status === 'verified' ) ) {
132
+ void navigateToFlowStart ( ) ;
133
+ }
118
134
return (
119
135
< ContentPage
120
- headerTitle = { title }
136
+ headerTitle = { domain . name }
137
+ gap = { 4 }
121
138
Breadcrumbs = { OrganizationProfileBreadcrumbs }
122
139
>
123
- < BlockWithAction
124
- elementDescriptor = { descriptors . accordionTriggerButton }
125
- badge = { < EnrollmentBadge organizationDomain = { domain } /> }
126
- sx = { t => ( {
127
- backgroundColor : t . colors . $blackAlpha50 ,
128
- padding : `${ t . space . $3 } ${ t . space . $4 } ` ,
129
- minHeight : t . sizes . $10 ,
130
- } ) }
131
- actionSx = { t => ( {
132
- color : t . colors . $danger500 ,
133
- } ) }
134
- actionLabel = { localizationKeys ( 'organizationProfile.verifiedDomainPage.actionLabel__remove' ) }
135
- onActionClick = { ( ) => navigate ( `../../domain/${ domain . id } /remove` ) }
136
- >
137
- { domain . name }
138
- </ BlockWithAction >
139
-
140
140
< Col gap = { 2 } >
141
141
< Header . Root >
142
142
< Header . Title
143
- localizationKey = { localizationKeys ( 'organizationProfile.verifiedDomainPage.formTitle ' ) }
143
+ localizationKey = { localizationKeys ( 'organizationProfile.verifiedDomainPage.start.headerTitle__enrollment ' ) }
144
144
textVariant = 'largeMedium'
145
145
/>
146
146
< Header . Subtitle
147
- localizationKey = { localizationKeys ( 'organizationProfile.verifiedDomainPage.formSubtitle ' ) }
147
+ localizationKey = { localizationKeys ( 'organizationProfile.verifiedDomainPage.enrollmentTab.subtitle ' ) }
148
148
variant = 'regularRegular'
149
149
/>
150
150
</ Header . Root >
@@ -154,7 +154,16 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
154
154
< Form . Control { ...enrollmentMode . props } />
155
155
</ Form . ControlRow >
156
156
157
- < FormButtons isDisabled = { domainStatus . isLoading || ! domain } />
157
+ { allowsEdit && (
158
+ < Form . ControlRow elementId = { deletePending . id } >
159
+ < Form . Control { ...deletePending . props } />
160
+ </ Form . ControlRow >
161
+ ) }
162
+
163
+ < FormButtons
164
+ localizationKey = { localizationKeys ( 'organizationProfile.verifiedDomainPage.enrollmentTab.formButton__save' ) }
165
+ isDisabled = { domainStatus . isLoading || ! domain || ! isFormDirty }
166
+ />
158
167
</ Form . Root >
159
168
</ Col >
160
169
</ ContentPage >
0 commit comments