Skip to content

Commit

Permalink
Issue #PS-1333 fix: Select Topic Sub-topic modal UI Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas143shinde committed Jul 18, 2024
2 parents c666311 + 816231a commit fe11575
Show file tree
Hide file tree
Showing 15 changed files with 914 additions and 860 deletions.
23 changes: 13 additions & 10 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@
"NO_SESSIONS_SCHEDULED": "No sessions scheduled",
"TO_BE_TAUGHT": "What is going to be taught:",
"SELECT_TOPIC": "Select Topic, Sub-topic",
"PAGE_NOT_FOUND": "पृष्ठ नहीं मिला",
"ACCESS_DENIED": "पहुंच निषेधित",
"YOU_DONT_HAVE_PERMISSION_TO_ACCESS_THIS_PAGE": "आपके पास इस पृष्ठ तक पहुंचने की अनुमति नहीं है"
"PAGE_NOT_FOUND": "Page not found",
"ACCESS_DENIED": "Access Denied",
"YOU_DONT_HAVE_PERMISSION_TO_ACCESS_THIS_PAGE": "You don't have access to this page",
"NEW_LEARNER": "New Learner",
"SUBMIT": "Submit"
},
"LOGIN_PAGE": {
"USERNAME": "Username",
Expand Down Expand Up @@ -148,7 +150,7 @@
"AS_OF_TODAY_DATE": "As of Today, {{day_date}}",
"LEARNER": "Learners",
"ATTENDANCE_COMPARISON": "Attendance Comparison",
"CENTER_TYPE":"Center Type",
"CENTER_TYPE": "Center Type",
"BLOCK_AVERAGE_ATTENDANCE": "Block Average Attendance"
},
"ATTENDANCE": {
Expand Down Expand Up @@ -327,18 +329,17 @@
},
"MANAGE_USERS": {
"CENTERS_REQUESTED_SUCCESSFULLY": "Center Requested Successfully"

},
"FORM": {
"FULL_NAME":"Full Name",
"FULL_NAME": "Full Name",
"ENTER_FULL_NAME": "Enter FUll Name",
"CONTACT_NUMBER":"Contact Number",
"CONTACT_NUMBER": "Contact Number",
"ENTER_CONTACT_NUMBER": "Enter Contact Number",
"HOW_WAS_LEARNER_MOBILISED": "How Was the Learner Mobilised?",
"SECOND_CHANCE_ALUMNI": "Second Chance Alumni",
"PRATHAM_TEAM_MEMBER": "Pratham Team Member",
"OTHER": "Other",
"AGE":"Age",
"AGE": "Age",
"GENDER": "Gender",
"MALE": "Male",
"FEMALE": "Female",
Expand Down Expand Up @@ -367,7 +368,7 @@
"STARTED_VOCATIONAL_COURSE": "Started vocational course",
"STARTED_A_JOB": "Started a job",
"SCHOOL_CLOSURE_DUE_TO_COVID": "School closure due to covid",
"MARITAL_STATUS":"Marital Status",
"MARITAL_STATUS": "Marital Status",
"UNMARRIED": "Unmarried",
"MARRIED": "Married",
"DIVORCED": "Divorced",
Expand All @@ -377,7 +378,9 @@
"NO_PHONE": "No Phone",
"IS_IT_YOUR_OWN_PHONE": "Is it your own phone?",
"YES": "Yes",
"NO": "No"
"NO": "No",
"TYPE_OF_PHONE_AVAILABLE": "Type of Phone Available",
"REASON_FOR_DROP_OUT_FROM_SCHOOL": "Reason for drop out from School"
},
"FORM_ERROR_MESSAGES": {
"INVALID_INPUT": "Invalid Input.",
Expand Down
274 changes: 93 additions & 181 deletions src/components/AddLeanerModal.tsx
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;
Loading

0 comments on commit fe11575

Please sign in to comment.