Skip to content

Commit

Permalink
Merge pull request #10 from Aar-if/deleteCohort
Browse files Browse the repository at this point in the history
Issue #PS-1282 feat: Implement the delete center
  • Loading branch information
itsvick authored Jul 17, 2024
2 parents bab7cd4 + 0896654 commit d42cad3
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 33 deletions.
5 changes: 4 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@
"CENTER_RENAMED": "Center Renamed Successfully!",
"SEND_REQUEST": "Send Request",
"REQUEST_TO_DELETE_HAS_BEEN_SENT": "Request to Delete has been sent",
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "You are sending a request to the State Admin to delete this Center"
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "You are sending a request to the State Admin to delete this Center",
"THE_USER_BELONGS_TO_THE_FOLLOWING_COHORT": "The user belongs to the following cohort: ",
"PLEASE_REMOVE_THE_USER_FROM_COHORT": "Please remove the user from these cohorts before proceeding with deletion."
},
"CENTER_SESSION": {
"THIS_SESSION": "This session",
Expand All @@ -324,6 +326,7 @@
},
"MANAGE_USERS": {
"CENTERS_REQUESTED_SUCCESSFULLY": "Center Requested Successfully"

},
"FORM": {
"FULL_NAME":"Full Name",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/hi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@
"CENTER_RENAMED": "केंद्र का नाम सफलतापूर्वक बदल दिया गया!",
"SEND_REQUEST": "अनुरोध भेजें",
"REQUEST_TO_DELETE_HAS_BEEN_SENT": " हटाने का अनुरोध भेजा गया है",
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "आप राज्य प्रशासन को इस केंद्र को हटाने का अनुरोध भेज रहे हैं"
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "आप राज्य प्रशासन को इस केंद्र को हटाने का अनुरोध भेज रहे हैं",
"THE_USER_BELONGS_TO_THE_FOLLOWING_COHORT": "उपयोगकर्ता निम्नलिखित समूह का सदस्य है: ",
"PLEASE_REMOVE_THE_USER_FROM_COHORT": "कृपया हटाने से पहले उपयोगकर्ता को इन समूहों से हटा दें।"
},
"CENTER_SESSION": {
"THIS_SESSION": "यह सत्र",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/mr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@
"CENTER_RENAMED": "केंद्राचे नाव यशस्वीरित्या बदलले गेले!",
"SEND_REQUEST": "विनंती पाठवा",
"REQUEST_TO_DELETE_HAS_BEEN_SENT": "हटवण्याची विनंती पाठवली आहे",
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "आपण या केंद्राला हटविण्याचे विनंती राज्य प्रशासनाला पाठवत आहात"
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "आपण या केंद्राला हटविण्याचे विनंती राज्य प्रशासनाला पाठवत आहात",
"THE_USER_BELONGS_TO_THE_FOLLOWING_COHORT": "वापरकर्ता खालील गटाचा सदस्य आहे: ",
"PLEASE_REMOVE_THE_USER_FROM_COHORT": "हटविण्यापूर्वी कृपया वापरकर्त्याला या गटांमधून काढून टाका।"
},
"CENTER_SESSION": {
"THIS_SESSION": "हे सत्र",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/or/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@
"CENTER_RENAMED": "କେନ୍ଦ୍ରର ନାମ ସଫଳତାର ସହ ଚାଲିଛି!",
"SEND_REQUEST":"ଅନୁରୋଧ ପଠାନ୍ତୁ",
"REQUEST_TO_DELETE_HAS_BEEN_SENT": "ହଟାଇବାକୁ ଅନୁରୋଧ ପଠାଯାଇଛି",
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "ଆପଣ ଏହି କେନ୍ଦ୍ରଟିକୁ ବିଲୋପ କରିବା ପାଇଁ ରାଜ୍ୟ ପ୍ରଶାସନକୁ ଅନୁରୋଧ ପଠାଉଛନ୍ତି"
"YOU_ARE_SENDING_REQUEST_TO_THE_STATE_ADMIN": "ଆପଣ ଏହି କେନ୍ଦ୍ରଟିକୁ ବିଲୋପ କରିବା ପାଇଁ ରାଜ୍ୟ ପ୍ରଶାସନକୁ ଅନୁରୋଧ ପଠାଉଛନ୍ତି",
"THE_USER_BELONGS_TO_THE_FOLLOWING_COHORT": "ୟୁଜର ନିମ୍ନଲିଖିତ ସମୁହର ସଦସ୍ୟ: ",
"PLEASE_REMOVE_THE_USER_FROM_COHORT": "ଦୟାକରି ହଟାଇବା ପୂର୍ବରୁ ୟୁଜରକୁ ଏହି ସମୁହଗୁଡିକରୁ କାଢ଼ି ଦିଅନ୍ତୁ।"

}
}
Expand Down
11 changes: 3 additions & 8 deletions src/components/DeleteUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import CloseIcon from '@mui/icons-material/Close';
import { showToastMessage } from './Toastify';
import manageUserStore from '@/store/manageUserStore';
import { getCohortList } from '@/services/CohortServices';

interface DeleteUserModalProps {
open: boolean;
onClose: () => void;
}
const DeleteUserModal: React.FC<DeleteUserModalProps> = ({ open, onClose }) => {
const { t } = useTranslation();
const store = manageUserStore();
const theme = useTheme<any>();
const style = {
position: 'absolute',
Expand Down Expand Up @@ -53,16 +56,8 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({ open, onClose }) => {
};

const handleDeleteAction = () => {





// setOtherReason('');
setSelectedValue('');



onClose();
showToastMessage(t('COMMON.USER_DELETED_PERMANENTLY'), 'success');
};
Expand Down
85 changes: 65 additions & 20 deletions src/components/ManageUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { getMyUserList } from '@/services/MyClassDetailsService';
import DeleteUserModal from './DeleteUserModal';
import Image from 'next/image';
import profileALT from '../assets/images/Profile.png';
import RemoveFacilitatorAlert from './SimpleModal';
import SimpleModal from './SimpleModal';
interface Cohort {
cohortId: string;
parentId: string;
Expand Down Expand Up @@ -82,7 +84,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
const { t } = useTranslation();
const theme = useTheme<any>();
const router = useRouter();
const store = manageUserStore();
const store = manageUserStore();
const [value, setValue] = React.useState(1);
const [users, setUsers] = useState<
{
Expand Down Expand Up @@ -112,13 +114,14 @@ const store = manageUserStore();
const [reassignBlockRequestModalOpen, setReassignBlockRequestModalOpen] =
React.useState<boolean>(false);
const [openDeleteUserModal, setOpenDeleteUserModal] = React.useState(false);

const [openRemoveUserModal, setOpenRemoveUserModal] = React.useState(false);
const [removeCohortNames, setRemoveCohortNames] = React.useState('');
const CustomLink = styled(Link)(({ theme }) => ({
textDecoration: 'underline',
textDecorationColor: theme?.palette?.secondary.main,
textDecorationThickness: '1px',
}));
const setDeleteId = manageUserStore((state) => state.setDeleteId);
const setCohortDeleteId = manageUserStore((state) => state.setCohortDeleteId);

useEffect(() => {
const getFacilitator = async () => {
Expand Down Expand Up @@ -148,22 +151,26 @@ const store = manageUserStore();
return;
}
const userIds = facilitatorList.map((user: any) => user.userId);
const cohortDetailsPromises = userIds.map((userId: string) =>
const cohortDetailsPromises = userIds.map((userId: string) =>
getCohortList(userId, { filter: 'true' })
);
const cohortDetails = await Promise.all(cohortDetailsPromises);
console.log('Cohort Details:', cohortDetails);

const extractedData = facilitatorList.map((user: any, index: number) => {
const cohorts = cohortDetails[index] || [];
const cohortNames = cohorts.map((cohort: any) => cohort.cohortName).join(', ');

return {
userId: user.userId,
name: user.name,
cohortNames: cohortNames || null,
};
});

const extractedData = facilitatorList.map(
(user: any, index: number) => {
const cohorts = cohortDetails[index] || [];
const cohortNames = cohorts
.map((cohort: any) => cohort.cohortName)
.join(', ');

return {
userId: user.userId,
name: user.name,
cohortNames: cohortNames || null,
};
}
);
setTimeout(() => {
setUsers(extractedData);
});
Expand Down Expand Up @@ -244,10 +251,14 @@ const store = manageUserStore();
setState({ ...state, bottom: false });
};

const handleCloseRemoveModal = () => {
setOpenRemoveUserModal(false);
};

const toggleDrawer =
(anchor: Anchor, open: boolean, user: any) =>
(event: React.KeyboardEvent | React.MouseEvent) => {
setDeleteId(user.userId);
setCohortDeleteId(user.userId);
setCenters(
cohortsData?.[user.userId]?.map((cohort) => cohort.name) || []
);
Expand All @@ -266,7 +277,24 @@ const store = manageUserStore();

const listItemClick = async (event: React.MouseEvent, name: string) => {
if (name === 'delete-User') {
setOpenDeleteUserModal(true);
const userId = store.deleteId;
console.log(userId);

const cohortList = await getCohortList(userId);
console.log('Cohort List:', cohortList);

if (cohortList && cohortList.length > 0) {
const cohortNames = cohortList
.map((cohort: { cohortName: any }) => cohort.cohortName)
.join(', ');
setOpenRemoveUserModal(true);
setRemoveCohortNames(cohortNames);
} else {
console.log(
'User does not belong to any cohorts, proceed with deletion'
);
setOpenDeleteUserModal(true);
}

// const name = selectedUser?.name || '';
// const userId = selectedUser?.userId || '';
Expand Down Expand Up @@ -565,11 +593,13 @@ const store = manageUserStore();
borderRadius: '5px',
fontSize: '12px',
fontWeight: '600',
color: 'black',
marginBottom: '10px',
color: 'black',
marginBottom: '10px',
}}
>
{user?.cohortNames ? `${user.cohortNames}` : 'N/A'}
{user?.cohortNames
? `${user.cohortNames}`
: 'N/A'}
</Box>
</Box>
</Box>
Expand Down Expand Up @@ -704,6 +734,21 @@ const store = manageUserStore();
open={openDeleteUserModal}
onClose={handleCloseModal}
/>
<SimpleModal
primaryText="Ok"
primaryActionHandler={handleCloseRemoveModal}
open={openRemoveUserModal}
onClose={handleCloseRemoveModal}
>
{' '}
<Box mt={1.5}>
<Typography>
{t('CENTERS.THE_USER_BELONGS_TO_THE_FOLLOWING_COHORT')}{' '}
{removeCohortNames}.{' '}
{t('CENTERS.PLEASE_REMOVE_THE_USER_FROM_COHORT')}
</Typography>
</Box>
</SimpleModal>
</>
)}

Expand Down
140 changes: 140 additions & 0 deletions src/components/SimpleModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import {
Box,
Button,
Divider,
FormControl,
FormControlLabel,
InputLabel,
Modal,
Radio,
RadioGroup,
TextField,
Typography,
} from '@mui/material';
import React, { ReactNode, useState } from 'react';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import CloseIcon from '@mui/icons-material/Close';
import { showToastMessage } from './Toastify';
import manageUserStore from '@/store/manageUserStore';
import { getCohortList } from '@/services/CohortServices';

interface SimpleModalProps {
secondaryActionHandler?: () => void;
primaryActionHandler: () => void;
secondaryText?: string;
primaryText: string;
children: ReactNode;
open: boolean;
onClose: () => void;
}
const SimpleModal: React.FC<SimpleModalProps> = ({
open,
onClose,
primaryText,
secondaryText,
primaryActionHandler,
secondaryActionHandler,
children,
}) => {
const { t } = useTranslation();
const store = manageUserStore();
const theme = useTheme<any>();
const style = {
padding: '20px',
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: '85%',
boxShadow: 24,
bgcolor: '#fff',
borderRadius: '16px',
'@media (min-width: 600px)': {
width: '450px',
},
};

return (
<Modal
open={open}
aria-labelledby="child-modal-title"
aria-describedby="child-modal-description"
>
<Box sx={{ ...style }}>
<Box
display={'flex'}
justifyContent={'space-between'}
sx={{ padding: '18px 16px' }}
>
<Box marginBottom={'0px'}>
<Typography
variant="h2"
sx={{
color: theme.palette.warning['A200'],
fontSize: '14px',
}}
component="h2"
>
{t('COMMON.DELETE_USER')}
</Typography>
</Box>
<CloseIcon
sx={{
cursor: 'pointer',
color: theme.palette.warning['A200'],
}}
onClick={onClose}
/>
</Box>
<Divider />
{children}
<Divider />

<Box sx={{ padding: '20px 16px' }}>
{primaryText && (
<Button
variant="contained"
color="primary"
sx={{
'&.Mui-disabled': {
backgroundColor: theme?.palette?.primary?.main,
},
minWidth: '84px',
height: '2.5rem',
padding: theme.spacing(1),
fontWeight: '500',
width: '100%',
}}
onClick={primaryActionHandler}
>
{primaryText}
</Button>
)}

{secondaryText && (
<Button
variant="contained"
color="primary"
sx={{
'&.Mui-disabled': {
backgroundColor: theme?.palette?.primary?.main,
},
minWidth: '84px',
height: '2.5rem',
padding: theme.spacing(1),
fontWeight: '500',
width: '100%',
}}
onClick={secondaryActionHandler}
>
{secondaryText}
</Button>
)}
</Box>
</Box>
</Modal>
);
};

export default SimpleModal;
2 changes: 1 addition & 1 deletion src/store/manageUserStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const manageUserStore = create(
persist(
(set) => ({
deleteId: '',
setDeleteId: (newDeleteId) => set((state) => ({ deleteId: newDeleteId })),
setCohortDeleteId: (newCohortDeleteId) => set((state) => ({ deleteId: newCohortDeleteId })),
}),
{
name: 'teacherApp',
Expand Down

0 comments on commit d42cad3

Please sign in to comment.