Skip to content

Commit

Permalink
Merge pull request #14 from Aar-if/deleteCohortUpdate
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 18, 2024
2 parents e46b15f + faa591a commit e440d36
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 36 deletions.
1 change: 1 addition & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"SURE_REASSIGN_CENTER": "Are you sure you want to re-assign Center to this user?",
"SURE_CLOSE": "Are you sure you want to close?",
"LEARNER_LIST": "Learners List",
"FACILITATOR_LIST": "Facilitators List",
"FILTERS": "Filters",
"MANAGE_USERS": "Manage Users",
"FACILITATORS": "Facilitators",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"SURE_REMOVE": "क्या आप वाकई इस शिक्षार्थी को हटाना चाहते हैं?",
"SURE_CLOSE": "क्या आप वाकई बंद करना चाहते हैं?",
"LEARNER_LIST": "अभियांत्रिकी सूची",
"FACILITATOR_LIST": "प्रशिक्षकों की सूची",
"FILTERS": "फिल्टर्स",
"MANAGE_USERS": "उपयोगकर्ताओं का प्रबंधन",
"FACILITATORS": "सुविधाकर्ता",
Expand Down
1 change: 1 addition & 0 deletions public/locales/mr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"SURE_REMOVE": "आपण खरोखरच या विद्यार्थ्याला काढून टाकू इच्छिता का?",
"SURE_CLOSE": "तुम्हाला हे बंद करायचं आहे का?",
"LEARNER_LIST": "शिक्षार्थ्यांची यादी",
"FACILITATOR_LIST": "सुविधादारांची यादी",
"FILTERS": "फिल्टर्स",
"MANAGE_USERS": "वापरकर्ते व्यवस्थापित करा",
"FACILITATORS": "सुविधासंचालक",
Expand Down
1 change: 1 addition & 0 deletions public/locales/or/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"CUSTOM_RANGE": "ଅନୁକୂଳିତ/କଷ୍ଟମ ସୀମା",
"NONE": "କିଛି ନାହି",
"LEARNERS": "ଶିକ୍ଷାର୍ଥୀ",
"FACILITATOR_LIST": "ସୁବିଧାଦାର ତାଲିକ",
"LEARNER_NAME": "ଶିକ୍ଷାର୍ଥୀ ନାମ",
"DATE_RANGE": "ସମୟ ସୀମା",
"SELECT_AN_OPTION": "ଏକ ବିକଳ୍ପ ବାଛ",
Expand Down
123 changes: 123 additions & 0 deletions src/components/CohortFacilitatorList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import React, { useEffect } from 'react';
import { getMyCohortFacilitatorList, getMyCohortMemberList } from '@/services/MyClassDetailsService';
import {
capitalizeEachWord,
getFieldValue,
toPascalCase,
} from '@/utils/Helper';
import LearnersList from '@/components/LearnersList';
import { Status, limit } from '@/utils/app.constant';
import { showToastMessage } from './Toastify';
import { useTranslation } from 'next-i18next';
import { Box, Typography } from '@mui/material';
import Loader from './Loader';

interface UserDataProps {
name: string;
userId: string;
memberStatus: string;
cohortMembershipId: string;
enrollmentNumber: string;
}
interface CohortLearnerListProp {
cohortId: any;
reloadState: boolean;
setReloadState: React.Dispatch<React.SetStateAction<boolean>>;
}

const CohortLearnerList: React.FC<CohortLearnerListProp> = ({
cohortId,
reloadState,
setReloadState,
}) => {
const [loading, setLoading] = React.useState<boolean>(false);
const [userData, setUserData] = React.useState<UserDataProps[]>();

const { t } = useTranslation();

useEffect(() => {
const getCohortMemberList = async () => {
setLoading(true);
try {
if (cohortId) {
const page = 0;
const filters = { cohortId: cohortId };
const response = await getMyCohortFacilitatorList({
limit,
page,
filters,
});

console.log(response);

const resp = response?.result?.userDetails;

if (resp) {
const userDetails = resp.map((user: any) => ({
name: toPascalCase(user.name),
userId: user.userId,
memberStatus: user.status,
statusReason: user.statusReason,
cohortMembershipId: user.cohortMembershipId,
enrollmentNumber: capitalizeEachWord(
getFieldValue(user.customField, 'Enrollment Number')
),
}));
console.log(`userDetails`, userDetails);
setUserData(userDetails);
}
}
} catch (error) {
console.error('Error fetching cohort list:', error);
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
setLoading(false);
} finally {
setLoading(false);
}
};
getCohortMemberList();
}, [cohortId, reloadState]);

console.log('userData', userData);
return (
<div>
{loading ? (
<Loader showBackdrop={true} loadingText={t('COMMON.LOADING')} />
) : (
<>
{userData?.map((data: any) => {
return (
<LearnersList
key={data.userId}
userId={data.userId}
learnerName={data.name}
enrollmentId={data.enrollmentNumber}
cohortMembershipId={data.cohortMembershipId}
isDropout={data.memberStatus === Status.DROPOUT}
statusReason={data.statusReason}
reloadState={reloadState}
setReloadState={setReloadState}
/>
);
})}
{!userData?.length && (
<Box
sx={{
m: '1.125rem',
display: 'flex',
justifyContent: 'left',
alignItems: 'center',
}}
>
<Typography style={{ fontWeight: 'bold' }}>
{t('COMMON.NO_DATA_FOUND')}
</Typography>
</Box>
)}
</>
)}
</div>
);
};

export default CohortLearnerList;
76 changes: 49 additions & 27 deletions src/components/ManageUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
try {
const cohortId = cohortData
.map((block: any) => {
return block.blockId;
return block?.blockId;
})
.join('');

Expand All @@ -146,32 +146,52 @@ const manageUsers: React.FC<ManageUsersProps> = ({

const resp = await getMyUserList({ limit, page, filters, fields });
const facilitatorList = resp.result?.getUserDetails;
if (!facilitatorList || facilitatorList.length === 0) {

console.log(facilitatorList);


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) =>
const userIds = facilitatorList?.map((user: any) => user.userId);
console.log(userIds);

const cohortDetailsPromises = userIds?.map((userId: string) =>
getCohortList(userId, { filter: 'true' })
);
const cohortDetails = await Promise.all(cohortDetailsPromises);
const cohortDetailsResults = await Promise.allSettled(cohortDetailsPromises);

const cohortDetails = cohortDetailsResults.map((result) => {
if (result.status === 'fulfilled') {
return result.value;
} else {
console.error('Error fetching cohort details for a user:', result.reason);
return null; // or handle the error as needed
}
});

console.log('Cohort Details:', cohortDetails);

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

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


setTimeout(() => {
console.log('extractedData');

setUsers(extractedData);
});
}
Expand Down Expand Up @@ -201,9 +221,9 @@ const manageUsers: React.FC<ManageUsersProps> = ({

const cohortResponses = await Promise.all(fetchCohortPromises);
console.log('cohortResponses', cohortResponses);
const allCohortsData: CohortsData = cohortResponses.reduce(
const allCohortsData: CohortsData = cohortResponses?.reduce(
(acc: CohortsData, curr) => {
acc[curr.userId] = curr.cohorts.map((item: Cohort) => ({
acc[curr.userId] = curr?.cohorts?.map((item: Cohort) => ({
cohortId: item?.cohortId,
parentId: item?.parentId,
name: item?.name,
Expand Down Expand Up @@ -260,7 +280,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
(event: React.KeyboardEvent | React.MouseEvent) => {
setCohortDeleteId(user.userId);
setCenters(
cohortsData?.[user.userId]?.map((cohort) => cohort.name) || []
cohortsData?.[user?.userId]?.map((cohort) => cohort?.name) || []
);
setSelectedUser(user);

Expand All @@ -277,16 +297,17 @@ const manageUsers: React.FC<ManageUsersProps> = ({

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

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

if (cohortList && cohortList.length > 0) {
if (cohortList && cohortList?.length > 0 ) {
const cohortNames = cohortList
.map((cohort: { cohortName: any }) => cohort.cohortName)
.map((cohort: { cohortName: any }) => cohort?.cohortName)
.join(', ');

setOpenRemoveUserModal(true);
setRemoveCohortNames(cohortNames);
} else {
Expand Down Expand Up @@ -349,7 +370,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
?.filter(Boolean);
setCentersData(filteredData);
if (filteredData && Array.isArray(filteredData)) {
const teamLeaderCenters = filteredData?.map((center) => center.name);
const teamLeaderCenters = filteredData?.map((center) => center?.name);
setCenterList(teamLeaderCenters.concat(centers));
}
}
Expand All @@ -371,12 +392,12 @@ const manageUsers: React.FC<ManageUsersProps> = ({

const matchedCohortIdsFromCohortsData = Object.values(cohortsData!)
.flat()
.filter((cohort) => selectedCenters.includes(cohort.name))
.map((cohort) => cohort.cohortId);
.filter((cohort) => selectedCenters?.includes(cohort?.name))
.map((cohort) => cohort?.cohortId);

const matchedCohortIdsFromCentersData = centersData
.filter((center) => selectedCenters.includes(center.name))
.map((center) => center.cohortId);
.filter((center) => selectedCenters?.includes(center?.name))
.map((center) => center?.cohortId);

const matchedCohortIds = Array.from(
new Set([
Expand Down Expand Up @@ -599,7 +620,7 @@ const manageUsers: React.FC<ManageUsersProps> = ({
>
{user?.cohortNames
? `${user.cohortNames}`
: 'N/A'}
: 'N/a'}
</Box>
</Box>
</Box>
Expand Down Expand Up @@ -741,12 +762,13 @@ const manageUsers: React.FC<ManageUsersProps> = ({
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 mt={1.5} mb={1.5}>
<Typography>
{t('CENTERS.THE_USER_BELONGS_TO_THE_FOLLOWING_COHORT')}{' '}
<strong>{removeCohortNames}</strong>
<br />
{t('CENTERS.PLEASE_REMOVE_THE_USER_FROM_COHORT')}
</Typography>
</Box>
</SimpleModal>
</>
Expand Down
12 changes: 3 additions & 9 deletions src/components/SimpleModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,22 @@ const SimpleModal: React.FC<SimpleModalProps> = ({
<Box sx={{ ...style }}>
<Box
display={'flex'}
justifyContent={'space-between'}
justifyContent={'center'}
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}
Expand Down
Loading

0 comments on commit e440d36

Please sign in to comment.