Skip to content

Commit

Permalink
Issue #PS-1450 feat: UI for reassign Facilitators with centres List A…
Browse files Browse the repository at this point in the history
…PI and Search functionality
  • Loading branch information
Aar-if committed Jul 30, 2024
1 parent 8e10f3b commit 221f9d2
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 2 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"FACILITATORS": "Facilitators",
"CENTERS_ASSIGNED": "Centers Assigned in {{block}}",
"REASSIGN_CENTERS": "Re-assign Center",
"REASSIGN_BLOCKS_REQUEST": "Request to Re-assign Block",
"REASSIGN_BLOCKS": "Add or Re-assign Centers",
"REASSIGN_BLOCKS_REQUEST": "Request to Re-assign Blocks",
"ASSIGN": "Assign",
"SEARCH_FACILITATORS": "Search Facilitators..",
"ADD_LEARNER": "Add Learners",
Expand Down
27 changes: 26 additions & 1 deletion src/components/ManageUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import profileALT from '../assets/images/Profile.png';
import RemoveFacilitatorAlert from './SimpleModal';
import SimpleModal from './SimpleModal';
import AddFacilitatorModal from './AddFacilitator';
import ReassignModal from './ReassignModal';

interface Cohort {
cohortId: string;
Expand Down Expand Up @@ -112,6 +113,8 @@ const manageUsers: React.FC<ManageUsersProps> = ({
});
const [confirmationModalOpen, setConfirmationModalOpen] =
React.useState<boolean>(false);
const [reassignModalOpen, setReassignModalOpen] =
React.useState<boolean>(false);
const [learnerData, setLearnerData] = React.useState<LearnerDataProps[]>();
const [reassignBlockRequestModalOpen, setReassignBlockRequestModalOpen] =
React.useState<boolean>(false);
Expand Down Expand Up @@ -280,6 +283,10 @@ const manageUsers: React.FC<ManageUsersProps> = ({
setState({ ...state, bottom: false });
};

const handleCloseReassignModal = () => {
setReassignModalOpen(false);
};

const handleCloseRemoveModal = () => {
setOpenRemoveUserModal(false);
};
Expand Down Expand Up @@ -342,13 +349,16 @@ const manageUsers: React.FC<ManageUsersProps> = ({
// console.log(error);
// showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
// }
}if (name === 'reassign-block') {
setReassignModalOpen(true);
getTeamLeadersCenters();
}
if (name === 'reassign-centers') {
setOpenCentersModal(true);
getTeamLeadersCenters();
}
if (name === 'reassign-block-request') {
setConfirmationModalOpen(true);
setReassignModalOpen(true);
getTeamLeadersCenters();
}
};
Expand Down Expand Up @@ -687,6 +697,15 @@ const manageUsers: React.FC<ManageUsersProps> = ({
state={state}
listItemClick={listItemClick}
optionList={[
{
label: t('COMMON.REASSIGN_BLOCKS'),
icon: (
<LocationOnOutlinedIcon
sx={{ color: theme.palette.warning['300'] }}
/>
),
name: 'reassign-block',
},
{
label: t('COMMON.REASSIGN_BLOCKS_REQUEST'),
icon: (
Expand Down Expand Up @@ -771,6 +790,12 @@ const manageUsers: React.FC<ManageUsersProps> = ({
handleCloseModal={handleCloseModal}
modalOpen={confirmationModalOpen}
/>
<ReassignModal
message={t('COMMON.REASSIGN_BLOCKS')}
handleAction={handleRequestBlockAction}
handleCloseReassignModal={handleCloseReassignModal}
modalOpen={reassignModalOpen}
/>

<DeleteUserModal
type={Role.TEACHER}
Expand Down
189 changes: 189 additions & 0 deletions src/components/ReassignModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import { Divider, TextField, Checkbox, InputAdornment, IconButton } from '@mui/material';
import Modal from '@mui/material/Modal';
import { useTheme } from '@mui/material/styles';
import useStore from '@/store/store';
import SearchIcon from '@mui/icons-material/Search';
import CloseIcon from '@mui/icons-material/Close';
import { useTranslation } from 'next-i18next';


interface ReassignModalProps {
message: string;
handleAction?: () => void;
buttonNames?: ButtonNames;
handleCloseReassignModal: () => void;
modalOpen: boolean;
}

interface ButtonNames {
primary: string;
secondary: string;
}

const ReassignModal: React.FC<ReassignModalProps> = ({
modalOpen,
message,
handleAction,
buttonNames,
handleCloseReassignModal,
}) => {
const theme = useTheme<any>();
const { t } = useTranslation();
const store = useStore();
const cohorts = store.cohorts;
const centerList = cohorts.map((cohort: { name: string }) => cohort.name);

const [searchInput, setSearchInput] = React.useState('');
const [checkedCenters, setCheckedCenters] = React.useState<string[]>([]);

const handleSearchInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchInput(event.target.value);
};

const handleToggle = (name: string) => {
setCheckedCenters((prevCheckedCenters) => {
const currentIndex = prevCheckedCenters.indexOf(name);
const isCurrentlyChecked = currentIndex !== -1;
const newChecked = [...prevCheckedCenters];

if (isCurrentlyChecked) {
newChecked.splice(currentIndex, 1);
} else {
newChecked.push(name);
}
return newChecked;
});
};

const filteredCenters = centerList.filter((center: string) =>
center.toLowerCase().includes(searchInput.toLowerCase())
);

const style = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: '75%',
bgcolor: '#fff',
boxShadow: 24,
borderRadius: '16px',
'@media (min-width: 600px)': {
width: '350px',
},
};

return (
<Modal
open={modalOpen}
onClose={handleCloseReassignModal}
aria-labelledby="confirmation-modal-title"
aria-describedby="confirmation-modal-description"
>
<Box sx={style}>
<Box
sx={{
p: 3,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
}}
id="confirmation-modal-title"
>
<span>{message}</span>
<IconButton
edge="end"
color="inherit"
onClick={handleCloseReassignModal}
aria-label="close"
>
<CloseIcon />
</IconButton>
</Box>
<Divider />
<Box sx={{ p: 3}}>
<TextField
sx={{
backgroundColor: theme.palette.warning['A700'],
borderRadius: 8,
'& .MuiOutlinedInput-root': {
'& fieldset': {
border: 'none',
},
},
'& .MuiOutlinedInput-input': {
borderRadius: 8,
},
}}
placeholder={t('CENTERS.SEARCH_CENTERS')}
value={searchInput}
onChange={handleSearchInputChange}
fullWidth
InputProps={{
endAdornment: (
<InputAdornment position="end">
<SearchIcon />
</InputAdornment>
),
}}
/>
</Box>
<Box sx={{ p: 3, maxHeight: '300px', overflowY: 'auto' }}>
{filteredCenters.map((center: string, index: number) => (
<Box
key={index}
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
mb: 2,
}}
>
<span>{center}</span>
<Checkbox
checked={checkedCenters.includes(center)}
onChange={() => handleToggle(center)}
/>
</Box>
))}
</Box>
<Divider />
<Box
sx={{
display: 'flex',
justifyContent: 'center',
gap: '18px',
p: 2,
}}
>
<Button
sx={{
width: '100%',
height: '40px',
fontSize: '14px',
fontWeight: '500',
}}
variant="contained"
color="primary"
onClick={() => {
if (handleAction !== undefined) {
handleAction();
handleCloseReassignModal();
} else {
handleCloseReassignModal();
}
}}
>
{buttonNames?.primary || 'Re-assign'}
</Button>

</Box>
</Box>
</Modal>
);
};

export default ReassignModal;

0 comments on commit 221f9d2

Please sign in to comment.