1
- import React , { useState } from 'react'
1
+ import React , { useEffect , useState } from 'react'
2
2
import { Col , Container , FormGroup , InputGroup , CustomInput } from 'Components'
3
3
import GluuBooleanSelectBox from 'Routes/Apps/Gluu/GluuBooleanSelectBox'
4
4
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
@@ -20,23 +20,19 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
20
20
const request_uri_id = 'request_uri_id'
21
21
const requestUris = [ ]
22
22
23
- const [ expirable , setExpirable ] = useState (
24
- client . expirationDate ? client . expirationDate : false ,
23
+ const [ expirable ] = useState (
24
+ formik . values . expirationDate ? formik . values . expirationDate : false ,
25
25
)
26
26
const [ scopesModal , setScopesModal ] = useState ( false )
27
27
const [ expirationDate , setExpirationDate ] = useState ( expirable ? dayjs ( expirable ) : undefined )
28
28
const handler = ( ) => {
29
29
setScopesModal ( ! scopesModal )
30
30
}
31
31
32
- function handleExpirable ( ) {
33
- setExpirable ( ! expirable )
34
- }
35
-
36
- scripts = scripts
37
- . filter ( ( item ) => item . scriptType == 'person_authentication' )
38
- . filter ( ( item ) => item . enabled )
39
- . map ( ( item ) => ( item . name ) )
32
+ const filteredScripts = scripts
33
+ ?. filter ( ( item ) => item . scriptType == 'person_authentication' )
34
+ ?. filter ( ( item ) => item . enabled )
35
+ ?. map ( ( item ) => ( item . name ) )
40
36
function uriValidator ( uri ) {
41
37
return uri
42
38
}
@@ -46,26 +42,15 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
46
42
}
47
43
return total . filter ( ( item ) => partial . includes ( item ) )
48
44
}
49
- const [ softwareSection , setSoftwareSection ] = useState ( false )
50
- const [ cibaSection , setCibaSection ] = useState ( false )
51
45
52
- function handleCibaSection ( ) {
53
- setCibaSection ( ! cibaSection )
54
- }
55
- function handleSoftwareSection ( ) {
56
- setSoftwareSection ( ! softwareSection )
57
- }
58
- function emailValidator ( email ) {
59
- return / ^ [ a - z A - Z 0 - 9 . ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 - ] + (?: \. [ a - z A - Z 0 - 9 - ] + ) * $ / . test (
60
- email ,
61
- )
62
- }
63
- function getScopeMapping ( exitingScopes , scopes ) {
64
- if ( ! exitingScopes ) {
65
- exitingScopes = [ ]
46
+ useEffect ( ( ) => {
47
+ // Listen for changes on expirable input switch
48
+ if ( ! formik . values . expirable ) {
49
+ formik . setFieldValue ( 'expirationDate' , null )
50
+ setExpirationDate ( null )
66
51
}
67
- return scopes . filter ( ( item ) => exitingScopes . includes ( item . dn ) )
68
- }
52
+ } , [ formik . values . expirable ] )
53
+
69
54
return (
70
55
< Container >
71
56
< ClientShowSpontaneousScopes handler = { handler } isOpen = { scopesModal } />
@@ -78,7 +63,7 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
78
63
id = "subjectType"
79
64
name = "subjectType"
80
65
disabled = { viewOnly }
81
- defaultValue = { client . subjectType }
66
+ defaultValue = { formik . values . subjectType }
82
67
onChange = { formik . handleChange }
83
68
>
84
69
< option value = "" > { t ( 'actions.choose' ) } ...</ option >
@@ -91,18 +76,18 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
91
76
92
77
< GluuToogleRow
93
78
name = "persistClientAuthorizations"
94
- lsize = { 9 }
95
- rsize = { 3 }
79
+ lsize = { 3 }
80
+ rsize = { 9 }
96
81
formik = { formik }
97
82
label = "fields.persist_client_authorizations"
98
- value = { client . persistClientAuthorizations }
83
+ value = { formik . values . persistClientAuthorizations }
99
84
doc_category = { DOC_CATEGORY }
100
85
disabled = { viewOnly }
101
86
/>
102
87
< GluuBooleanSelectBox
103
88
name = "allowSpontaneousScopes"
104
89
label = "fields.allow_spontaneous_scopes"
105
- value = { client . allowSpontaneousScopes }
90
+ value = { formik . values . allowSpontaneousScopes }
106
91
formik = { formik }
107
92
lsize = { 3 }
108
93
rsize = { 9 }
@@ -142,7 +127,7 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
142
127
label = "fields.initiateLoginUri"
143
128
name = "initiateLoginUri"
144
129
formik = { formik }
145
- value = { client . initiateLoginUri }
130
+ value = { formik . values . initiateLoginUri }
146
131
doc_category = { DOC_CATEGORY }
147
132
disabled = { viewOnly }
148
133
/>
@@ -151,7 +136,7 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
151
136
label = "fields.requestUris"
152
137
formik = { formik }
153
138
placeholder = { t ( 'Enter a valid request uri eg' ) + ' https://...' }
154
- value = { client . requestUris || [ ] }
139
+ value = { formik . values . requestUris || [ ] }
155
140
options = { requestUris }
156
141
validator = { uriValidator }
157
142
inputId = { request_uri_id }
@@ -164,8 +149,8 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
164
149
name = "defaultAcrValues"
165
150
label = "fields.defaultAcrValues"
166
151
formik = { formik }
167
- value = { getMapping ( client . defaultAcrValues , scripts ) }
168
- options = { scripts }
152
+ value = { getMapping ( formik . values . defaultAcrValues , filteredScripts ) }
153
+ options = { filteredScripts }
169
154
doc_category = { DOC_CATEGORY }
170
155
lsize = { 3 }
171
156
rsize = { 9 }
@@ -175,8 +160,8 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
175
160
name = "authorizedAcrValues"
176
161
label = "fields.authorizedAcrValues"
177
162
formik = { formik }
178
- value = { getMapping ( client . authorizedAcrValues , scripts ) }
179
- options = { scripts }
163
+ value = { getMapping ( formik . values . authorizedAcrValues , filteredScripts ) }
164
+ options = { filteredScripts }
180
165
doc_category = { DOC_CATEGORY }
181
166
lsize = { 3 }
182
167
rsize = { 9 }
@@ -188,43 +173,41 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
188
173
rsize = { 9 }
189
174
formik = { formik }
190
175
label = "fields.defaultPromptLogin"
191
- value = { client . jansDefaultPromptLogin }
176
+ value = { formik . values . jansDefaultPromptLogin }
192
177
doc_category = { DOC_CATEGORY }
193
178
disabled = { viewOnly }
194
179
/>
195
180
< GluuInputRow
196
181
label = "fields.tls_client_auth_subject_dn"
197
182
name = "tlsClientAuthSubjectDn"
198
183
formik = { formik }
199
- value = { client . tlsClientAuthSubjectDn }
184
+ value = { formik . values . tlsClientAuthSubjectDn }
200
185
doc_category = { DOC_CATEGORY }
201
186
disabled = { viewOnly }
202
187
/>
203
188
204
189
< FormGroup row >
205
190
< Col sm = { 6 } >
206
- { client . expirable && (
207
191
< GluuToogleRow
208
192
name = "expirable"
209
193
formik = { formik }
210
194
label = "fields.is_expirable_client"
211
- value = { client . expirable ?. length ? true : false }
212
- handler = { handleExpirable }
195
+ value = { formik . values . expirable }
213
196
doc_category = { DOC_CATEGORY }
214
197
lsize = { 6 }
215
198
rsize = { 6 }
216
199
disabled = { viewOnly }
217
200
/>
218
- ) }
219
201
</ Col >
220
202
< Col sm = { 6 } >
221
- { client . expirable ?. length ? (
203
+ { formik . values . expirable ? (
222
204
< FormGroup row >
223
205
< Col sm = { 12 } >
224
206
< LocalizationProvider dateAdapter = { AdapterDayjs } >
225
207
< DateTimePicker
226
208
id = "expirationDate"
227
209
name = "expirationDate"
210
+ disablePast
228
211
value = { expirationDate }
229
212
onChange = { ( date ) => {
230
213
formik . setFieldValue ( 'expirationDate' , new Date ( date ) )
0 commit comments