@@ -19,8 +19,12 @@ import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
19
19
import GluuToggleRow from 'Routes/Apps/Gluu/GluuToggleRow'
20
20
import GluuUploadFile from 'Routes/Apps/Gluu/GluuUploadFile'
21
21
import GluuSelectRow from 'Routes/Apps/Gluu/GluuSelectRow'
22
+ import { Box } from '@mui/material'
23
+ import Toggle from 'react-toggle'
22
24
23
25
const SamlIdpForm = ( { configs, viewOnly } ) => {
26
+ const [ showUploadBtn , setShowUploadBtn ] = useState ( false )
27
+ const [ fileError , setFileError ] = useState ( false )
24
28
const savedForm = useSelector ( ( state ) => state . idpSamlReducer . savedForm )
25
29
const loading = useSelector ( ( state ) => state . idpSamlReducer . loading )
26
30
const { t } = useTranslation ( )
@@ -66,6 +70,7 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
66
70
Yup . string ( ) . required ( `${ t ( 'fields.name_policy_format' ) } is Required!` ) ,
67
71
} ) ,
68
72
name : Yup . string ( ) . required ( `${ t ( 'fields.name' ) } is Required!` ) ,
73
+ displayName : Yup . string ( ) . required ( `${ t ( 'fields.displayName' ) } is Required!` ) ,
69
74
} )
70
75
71
76
const toggle = ( ) => {
@@ -135,6 +140,7 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
135
140
if ( file ) {
136
141
formik . setFieldValue ( 'importMetadataFile' , true )
137
142
setMetadaDataFile ( file )
143
+ setFileError ( '' )
138
144
} else formik . setFieldValue ( 'importMetadataFile' , false )
139
145
}
140
146
@@ -158,7 +164,15 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
158
164
< Card >
159
165
< CardBody className = '' >
160
166
< Form
161
- onSubmit = { formik . handleSubmit }
167
+ onSubmit = { ( event ) => {
168
+ event . preventDefault ( )
169
+ if ( ! metaDataFile && showUploadBtn ) {
170
+ setFileError ( true )
171
+ return
172
+ }
173
+ setFileError ( false )
174
+ formik . handleSubmit ( event )
175
+ } }
162
176
className = 'mt-4'
163
177
>
164
178
< FormGroup row >
@@ -184,6 +198,7 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
184
198
formik = { formik }
185
199
lsize = { 4 }
186
200
rsize = { 8 }
201
+ required
187
202
showError = {
188
203
formik . errors . displayName && formik . touched . displayName
189
204
}
@@ -221,20 +236,48 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
221
236
size = { 4 }
222
237
/>
223
238
< Col sm = { 8 } >
224
- < GluuUploadFile
225
- accept = { {
226
- 'text/xml' : [ '.xml' ] ,
227
- 'application/json' : [ '.json' ] ,
228
- } }
229
- placeholder = { `Drag 'n' drop .xml/.json file here, or click to select file` }
230
- onDrop = { handleDrop }
231
- onClearFiles = { handleClearFiles }
232
- disabled = { viewOnly }
233
- />
239
+ < Box
240
+ display = 'flex'
241
+ flexWrap = { { sm : 'wrap' , md : 'nowrap' } }
242
+ gap = { 1 }
243
+ alignItems = 'center'
244
+ >
245
+ < Toggle
246
+ onChange = { ( event ) => {
247
+ if ( event . target . checked ) {
248
+ setShowUploadBtn ( true )
249
+ } else {
250
+ setMetadaDataFile ( null )
251
+ formik . setFieldValue ( 'importMetadataFile' , false )
252
+ setShowUploadBtn ( false )
253
+ setFileError ( '' )
254
+ }
255
+ } }
256
+ checked = { showUploadBtn }
257
+ disabled = { viewOnly }
258
+ />
259
+ { showUploadBtn && (
260
+ < GluuUploadFile
261
+ accept = { {
262
+ 'text/xml' : [ '.xml' ] ,
263
+ 'application/json' : [ '.json' ] ,
264
+ } }
265
+ placeholder = { `Drag 'n' drop .xml/.json file here, or click to select file` }
266
+ onDrop = { handleDrop }
267
+ onClearFiles = { handleClearFiles }
268
+ disabled = { viewOnly }
269
+ />
270
+ ) }
271
+ </ Box >
272
+ { fileError && (
273
+ < div style = { { color : 'red' } } >
274
+ { t ( 'messages.import_metadata_file' ) }
275
+ </ div >
276
+ ) }
234
277
</ Col >
235
278
</ FormGroup >
236
279
</ Col >
237
- { ! metaDataFile && (
280
+ { ! showUploadBtn && (
238
281
< >
239
282
< Col sm = { 10 } >
240
283
< GluuInputRow
0 commit comments