Skip to content

Commit 4b67a33

Browse files
committed
fix(admin-ui): add toggle switch back in identity brokering form #1596
Signed-off-by: Jeet Viramgama <[email protected]>
1 parent be0c08e commit 4b67a33

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

admin-ui/plugins/saml/components/SamlIdpForm.js

+55-12
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
1919
import GluuToggleRow from 'Routes/Apps/Gluu/GluuToggleRow'
2020
import GluuUploadFile from 'Routes/Apps/Gluu/GluuUploadFile'
2121
import GluuSelectRow from 'Routes/Apps/Gluu/GluuSelectRow'
22+
import { Box } from '@mui/material'
23+
import Toggle from 'react-toggle'
2224

2325
const SamlIdpForm = ({ configs, viewOnly }) => {
26+
const [showUploadBtn, setShowUploadBtn] = useState(false)
27+
const [fileError, setFileError] = useState(false)
2428
const savedForm = useSelector((state) => state.idpSamlReducer.savedForm)
2529
const loading = useSelector((state) => state.idpSamlReducer.loading)
2630
const { t } = useTranslation()
@@ -66,6 +70,7 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
6670
Yup.string().required(`${t('fields.name_policy_format')} is Required!`),
6771
}),
6872
name: Yup.string().required(`${t('fields.name')} is Required!`),
73+
displayName: Yup.string().required(`${t('fields.displayName')} is Required!`),
6974
})
7075

7176
const toggle = () => {
@@ -135,6 +140,7 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
135140
if (file) {
136141
formik.setFieldValue('importMetadataFile', true)
137142
setMetadaDataFile(file)
143+
setFileError('')
138144
} else formik.setFieldValue('importMetadataFile', false)
139145
}
140146

@@ -158,7 +164,15 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
158164
<Card>
159165
<CardBody className=''>
160166
<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+
}}
162176
className='mt-4'
163177
>
164178
<FormGroup row>
@@ -184,6 +198,7 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
184198
formik={formik}
185199
lsize={4}
186200
rsize={8}
201+
required
187202
showError={
188203
formik.errors.displayName && formik.touched.displayName
189204
}
@@ -221,20 +236,48 @@ const SamlIdpForm = ({ configs, viewOnly }) => {
221236
size={4}
222237
/>
223238
<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+
)}
234277
</Col>
235278
</FormGroup>
236279
</Col>
237-
{!metaDataFile && (
280+
{!showUploadBtn && (
238281
<>
239282
<Col sm={10}>
240283
<GluuInputRow

0 commit comments

Comments
 (0)