-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #PS-1333 fix: Select Topic Sub-topic modal UI Implementation
- Loading branch information
Showing
15 changed files
with
914 additions
and
860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,194 +1,106 @@ | ||
import * as React from 'react'; | ||
import DynamicForm from '@/components/DynamicForm'; | ||
import React, { useEffect } from 'react'; | ||
import { | ||
GenerateSchemaAndUiSchema, | ||
customFields, | ||
} from '@/components/GeneratedSchemas'; | ||
import { IChangeEvent } from '@rjsf/core'; | ||
import ISubmitEvent from '@rjsf/core'; | ||
import { Box } from '@mui/material'; | ||
import { RJSFSchema } from '@rjsf/utils'; | ||
import SendCredentialModal from '@/components/SendCredentialModal'; | ||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; | ||
import { getFormRead } from '@/services/CreateUserService'; | ||
import { FormData } from '@/utils/Interfaces'; | ||
import { FormContext, FormContextType } from '@/utils/app.constant'; | ||
import SimpleModal from '@/components/SimpleModal'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Checkbox, Divider, InputAdornment, TextField } from '@mui/material'; | ||
interface AddLearnerModalProps { | ||
open: boolean; | ||
onClose: () => void; | ||
} | ||
const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => { | ||
const [schema, setSchema] = React.useState<any>(); | ||
const [uiSchema, setUiSchema] = React.useState<any>(); | ||
const { t } = useTranslation(); | ||
|
||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import CheckBoxOutlinedIcon from '@mui/icons-material/CheckBoxOutlined'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
import { Height } from '@mui/icons-material'; | ||
import IndeterminateCheckBoxOutlinedIcon from '@mui/icons-material/IndeterminateCheckBoxOutlined'; | ||
import Modal from '@mui/material/Modal'; | ||
import SearchIcon from '@mui/icons-material/Search'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useTheme } from '@mui/material/styles'; | ||
import { useTranslation } from 'next-i18next'; | ||
useEffect(() => { | ||
const getAddLearnerFormData = async () => { | ||
try { | ||
const response: FormData = await getFormRead( | ||
FormContext.USERS, | ||
FormContextType.STUDENT | ||
); | ||
console.log('sortedFields', response); | ||
|
||
interface ManageUsersModalProps { | ||
learnersName: string[]; | ||
} | ||
if (response) { | ||
const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t); | ||
setSchema(schema); | ||
setUiSchema(uiSchema); | ||
} | ||
} catch (error) { | ||
console.error('Error fetching form data:', error); | ||
} | ||
}; | ||
getAddLearnerFormData(); | ||
}, []); | ||
|
||
const AddLeanerModal: React.FC<ManageUsersModalProps> = ({ learnersName }) => { | ||
const theme = useTheme<any>(); | ||
const { t } = useTranslation(); | ||
const [open, setOpen] = React.useState(false); | ||
const handleOpen = () => setOpen(true); | ||
const handleClose = () => setOpen(false); | ||
const handleSubmit = ( | ||
data: IChangeEvent<any, RJSFSchema, any>, | ||
event: React.FormEvent<any> | ||
) => { | ||
// setOpenModal(true); | ||
const target = event.target as HTMLFormElement; | ||
const elementsArray = Array.from(target.elements); | ||
|
||
const style = { | ||
position: 'absolute', | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
width: '85%', | ||
bgcolor: theme.palette.warning['A400'], | ||
boxShadow: 24, | ||
borderRadius: '16px', | ||
height: '526px', | ||
'@media (min-width: 600px)': { | ||
width: '450px', | ||
}, | ||
for (const element of elementsArray) { | ||
if ( | ||
(element instanceof HTMLInputElement || | ||
element instanceof HTMLSelectElement || | ||
element instanceof HTMLTextAreaElement) && | ||
(element.value === '' || | ||
(Array.isArray(element.value) && element.value.length === 0)) | ||
) { | ||
element.focus(); | ||
return; | ||
} | ||
} | ||
console.log('Form data submitted:', data.formData); | ||
}; | ||
|
||
const handleChange = (event: IChangeEvent<any>) => { | ||
console.log('Form data changed:', event.formData); | ||
}; | ||
|
||
const handleError = (errors: any) => { | ||
console.log('Form errors:', errors); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{/* <Button onClick={handleOpen}>Open modal</Button> */} | ||
<Modal | ||
<> | ||
<SimpleModal | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby="modal-modal-title" | ||
aria-describedby="modal-modal-description" | ||
onClose={onClose} | ||
showFooter={false} | ||
modalTitle={t('COMMON.NEW_LEARNER')} | ||
> | ||
<Box sx={style}> | ||
<Box | ||
display={'flex'} | ||
justifyContent={'space-between'} | ||
sx={{ padding: '20px' }} | ||
> | ||
<Box marginBottom={'0px'}> | ||
<Typography | ||
variant="h2" | ||
sx={{ | ||
color: theme.palette.warning['A200'], | ||
fontSize: '16px', | ||
}} | ||
component="h2" | ||
> | ||
{t('COMMON.ADD_LEARNER')} | ||
</Typography> | ||
</Box> | ||
<CloseIcon | ||
sx={{ | ||
cursor: 'pointer', | ||
color: theme.palette.warning['A200'], | ||
}} | ||
onClick={() => handleClose()} | ||
/> | ||
</Box> | ||
<Divider /> | ||
<Box sx={{ display: 'flex', justifyContent: 'center', p: '20px' }}> | ||
<TextField | ||
className="input_search" | ||
placeholder="Search Facilitators.." | ||
color="secondary" | ||
focused | ||
sx={{ | ||
borderRadius: '100px', | ||
height: '40px', | ||
}} | ||
InputProps={{ | ||
endAdornment: ( | ||
<InputAdornment position="end"> | ||
<SearchIcon /> | ||
</InputAdornment> | ||
), | ||
}} | ||
/> | ||
</Box> | ||
<Box mx={'20px'}> | ||
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<Box sx={{ display: 'flex', alignItems: 'center', gap: '6px' }}> | ||
<Box | ||
sx={{ | ||
fontSize: '14px', | ||
color: theme.palette.warning['A200'], | ||
fontWeight: '500', | ||
}} | ||
> | ||
{t('COMMON.DESELECT_ALL')} | ||
</Box> | ||
|
||
<IndeterminateCheckBoxOutlinedIcon | ||
sx={{ | ||
fontSize: '18px', | ||
color: theme.palette.warning['A200'], | ||
marginBottom: '2px', | ||
}} | ||
/> | ||
</Box> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '6px', | ||
marginRight: '10px', | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
fontSize: '14px', | ||
color: theme.palette.warning['A200'], | ||
fontWeight: '500', | ||
}} | ||
> | ||
{t('COMMON.SELECT_ALL')} | ||
</Box> | ||
<CheckBoxOutlinedIcon | ||
sx={{ | ||
fontSize: '18px', | ||
color: theme.palette.warning['A200'], | ||
marginBottom: '2px', | ||
}} | ||
/> | ||
</Box> | ||
</Box> | ||
<Box sx={{ height: '35vh', mt: '10px', overflowY: 'auto' }}> | ||
{learnersName?.map((name, index) => { | ||
return ( | ||
<React.Fragment key={index}> | ||
<Box | ||
borderBottom={theme.palette.warning['A100']} | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
fontSize: '16px', | ||
color: theme.palette.warning['300'], | ||
pb: '20px', | ||
}} | ||
> | ||
{name} | ||
</Box> | ||
<Box> | ||
<Checkbox | ||
sx={{ pb: '20px' }} | ||
className="checkBox_svg" | ||
/> | ||
</Box> | ||
</Box> | ||
</React.Fragment> | ||
); | ||
})} | ||
</Box> | ||
</Box> | ||
<Divider /> | ||
<Box p={'20px'}> | ||
<Button | ||
className="w-100" | ||
sx={{ boxShadow: 'none' }} | ||
variant="contained" | ||
> | ||
{t('COMMON.ADD')} | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Modal> | ||
</div> | ||
{schema && uiSchema && ( | ||
<DynamicForm | ||
schema={schema} | ||
uiSchema={uiSchema} | ||
onSubmit={handleSubmit} | ||
onChange={handleChange} | ||
onError={handleError} | ||
widgets={{}} | ||
showErrorList={true} | ||
customFields={customFields} | ||
showTwoButtons={true} | ||
/> | ||
)} | ||
</SimpleModal> | ||
</> | ||
); | ||
}; | ||
|
||
export default AddLeanerModal; | ||
export default AddLearnerModal; |
Oops, something went wrong.