Skip to content

Commit

Permalink
Issue #PS-1282 feat: Implement the delete center
Browse files Browse the repository at this point in the history
  • Loading branch information
Aar-if committed Jul 17, 2024
1 parent 941404e commit 0896654
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 105 deletions.
37 changes: 23 additions & 14 deletions src/components/ManageUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +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 './RemoveFacilitatorAlert';
import RemoveFacilitatorAlert from './SimpleModal';
import SimpleModal from './SimpleModal';
interface Cohort {
cohortId: string;
parentId: string;
Expand Down Expand Up @@ -252,7 +253,6 @@ const manageUsers: React.FC<ManageUsersProps> = ({

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

};

const toggleDrawer =
Expand All @@ -279,21 +279,22 @@ const manageUsers: React.FC<ManageUsersProps> = ({
if (name === 'delete-User') {
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)
setRemoveCohortNames(cohortNames);
} else {
console.log('User does not belong to any cohorts, proceed with deletion');
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 @@ -733,13 +734,21 @@ const manageUsers: React.FC<ManageUsersProps> = ({
open={openDeleteUserModal}
onClose={handleCloseModal}
/>
<RemoveFacilitatorAlert
removeCohortNames={removeCohortNames}
open={openRemoveUserModal}
onClose={handleCloseRemoveModal}
/>


<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
91 changes: 0 additions & 91 deletions src/components/RemoveFacilitatorAlert.tsx

This file was deleted.

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;

0 comments on commit 0896654

Please sign in to comment.