Skip to content

Commit

Permalink
Merge pull request #8 from Aar-if/report
Browse files Browse the repository at this point in the history
Issue #PS-1098 feat: Show Facilitators list into the selected center
  • Loading branch information
itsvick authored Jul 17, 2024
2 parents 16a89c0 + 85b4137 commit ad31080
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
26 changes: 17 additions & 9 deletions src/components/DeleteUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({ open, onClose }) => {
};

const [selectedValue, setSelectedValue] = useState('');
const [otherReason, setOtherReason] = useState('');
// const [otherReason, setOtherReason] = useState('');

const reasons = [
{ value: 'Incorrect Data Entry', label: 'Incorrect Data Entry' },
{ value: 'Duplicated User', label: 'Duplicated User' },
{ value: 'Other', label: 'Other' },
// { value: 'Other', label: 'Other' },
];

const handleRadioChange = (value: string) => {
Expand All @@ -53,15 +53,23 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({ open, onClose }) => {
};

const handleDeleteAction = () => {





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



onClose();
showToastMessage(t('COMMON.USER_DELETED_PERMANENTLY'), 'success');
setOtherReason('');
setSelectedValue('');
};

const handleOtherReasonChange = (event: any) => {
setOtherReason(event.target.value);
};
// const handleOtherReasonChange = (event: any) => {
// setOtherReason(event.target.value);
// };

return (
<Modal
Expand Down Expand Up @@ -139,7 +147,7 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({ open, onClose }) => {
<Divider />
</>
))}
{selectedValue === 'Other' && (
{/* {selectedValue === 'Other' && (
<FormControl sx={{ mt: 2, width: '100%' }}>
<TextField
id="otherReason"
Expand All @@ -152,7 +160,7 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({ open, onClose }) => {
onChange={(e) => handleOtherReasonChange(e)}
/>
</FormControl>
)}
)} */}
</Box>
<Box mt={1.5}>
<Divider />
Expand Down
47 changes: 32 additions & 15 deletions src/components/ManageUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import { useEffect } from 'react';
import { assignCentersToFacilitator } from '@/services/ManageUser';
import { cohortList } from '@/services/CohortServices';
import { cohortList, getCohortList } from '@/services/CohortServices';
import { showToastMessage } from '@/components/Toastify';
import BottomDrawer from '@/components/BottomDrawer';
import ApartmentIcon from '@mui/icons-material/Apartment';
Expand All @@ -37,6 +37,7 @@ import AddIcon from '@mui/icons-material/Add';
import LearnersList from '@/components/LearnersList';
import Link from 'next/link';
import { styled } from '@mui/system';
import manageUserStore from '../store/manageUserStore';

import { getMyUserList } from '@/services/MyClassDetailsService';
import DeleteUserModal from './DeleteUserModal';
Expand Down Expand Up @@ -81,13 +82,13 @@ const manageUsers: React.FC<ManageUsersProps> = ({
const { t } = useTranslation();
const theme = useTheme<any>();
const router = useRouter();

const store = manageUserStore();
const [value, setValue] = React.useState(1);
const [users, setUsers] = useState<
{
name: string;
userId: string;
age?: number;
cohortNames?: string;
}[]
>();
const [loading, setLoading] = React.useState(false);
Expand Down Expand Up @@ -117,6 +118,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
textDecorationColor: theme?.palette?.secondary.main,
textDecorationThickness: '1px',
}));
const setDeleteId = manageUserStore((state) => state.setDeleteId);

useEffect(() => {
const getFacilitator = async () => {
Expand All @@ -132,26 +134,36 @@ const manageUsers: React.FC<ManageUsersProps> = ({
const limit = 0;
const page = 0;
const filters = {
state: 'MH',
district: 'PN',
block: 'BA',
states: 'MH',
districts: 'PN',
blocks: 'BA',
role: 'Teacher',
};
const fields = ['age'];

const resp = await getMyUserList({ limit, page, filters, fields });
const facilitatorList = resp.result?.getUserDetails;
const extractedData = facilitatorList?.map((user: any) => {
const ageField = user.customFields.find(
(field: any) => field.name === 'age'
);
if (!facilitatorList || facilitatorList.length === 0) {
console.log('No users found.');
return;
}
const userIds = facilitatorList.map((user: any) => user.userId);
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,
age: ageField ? ageField.value : null,
cohortNames: cohortNames || null,
};
});
console.log(extractedData);
setTimeout(() => {
setUsers(extractedData);
});
Expand Down Expand Up @@ -235,6 +247,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
const toggleDrawer =
(anchor: Anchor, open: boolean, user: any) =>
(event: React.KeyboardEvent | React.MouseEvent) => {
setDeleteId(user.userId);
setCenters(
cohortsData?.[user.userId]?.map((cohort) => cohort.name) || []
);
Expand Down Expand Up @@ -547,12 +560,16 @@ const manageUsers: React.FC<ManageUsersProps> = ({
</CustomLink>
<Box
sx={{
backgroundColor: '#FFF8F2',
padding: '5px',
borderRadius: '5px',
fontSize: '12px',
color: theme.palette.warning['400'],
marginBottom: '10px',
fontWeight: '600',
color: 'black',
marginBottom: '10px',
}}
>
{user?.age ? `${user.age} y/o` : 'N/A'}
{user?.cohortNames ? `${user.cohortNames}` : 'N/A'}
</Box>
</Box>
</Box>
Expand Down
17 changes: 17 additions & 0 deletions src/store/manageUserStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

const manageUserStore = create(
persist(
(set) => ({
deleteId: '',
setDeleteId: (newDeleteId) => set((state) => ({ deleteId: newDeleteId })),
}),
{
name: 'teacherApp',
getStorage: () => localStorage,
}
)
);

export default manageUserStore;
6 changes: 3 additions & 3 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export interface userList {
limit: number;
page: number;
filters: {
state: string;
district: string;
block: string;
states: string;
districts: string;
blocks: string;
role?: string;
};
fields: string[];
Expand Down

0 comments on commit ad31080

Please sign in to comment.