From 52f9feb72b2ddbe7bf952fb02e1b0aabddef5235 Mon Sep 17 00:00:00 2001 From: Arif Date: Mon, 12 Aug 2024 17:46:26 +0530 Subject: [PATCH] Issue #PS-1677 feat: Teaching Centers Page Inconsistencies --- src/components/CohortSelectionSection.tsx | 27 +++++++++++++++++------ src/components/ManageUser.tsx | 13 ++++++----- src/utils/Interfaces.ts | 1 + 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/components/CohortSelectionSection.tsx b/src/components/CohortSelectionSection.tsx index 2b752f15..0b3e398d 100644 --- a/src/components/CohortSelectionSection.tsx +++ b/src/components/CohortSelectionSection.tsx @@ -218,12 +218,22 @@ const CohortSelectionSection: React.FC = ({ } else if (response[0].type === cohortHierarchy.BLOCK) { setBlockName(response[0].name || response[0].cohortName); const filteredData = response[0].childData - ?.map((item: any) => ({ - cohortId: item?.cohortId, - parentId: item?.parentId, - name: item?.cohortName || item?.name, - })) + ?.map((item: any) => { + const typeOfCohort = item?.customField?.find( + (field: any) => field?.label === 'TYPE_OF_COHORT' + )?.value; + + return { + cohortId: item?.cohortId, + parentId: item?.parentId, + name: item?.cohortName || item?.name, + typeOfCohort: typeOfCohort || (t('ATTENDANCE.N/A')), + }; + }) ?.filter(Boolean); + + console.log(filteredData); + setCohortsData(filteredData); if (filteredData.length > 0) { @@ -333,7 +343,10 @@ const CohortSelectionSection: React.FC = ({ }, }} IconComponent={(props) => ( - + )} > {cohortsData?.length !== 0 ? ( @@ -348,7 +361,7 @@ const CohortSelectionSection: React.FC = ({ textTransform: 'capitalize', }} > - {cohort.name} + {cohort.name} ({cohort?.typeOfCohort}) )) ) : ( diff --git a/src/components/ManageUser.tsx b/src/components/ManageUser.tsx index eb910147..33b03d11 100644 --- a/src/components/ManageUser.tsx +++ b/src/components/ManageUser.tsx @@ -318,17 +318,18 @@ const ManageUser: React.FC = ({ const cohortList = await getCohortList(userId); console.log('Cohort List:', cohortList); - if (cohortList && cohortList?.length > 0) { + const hasActiveCohorts = cohortList && cohortList.length > 0 && cohortList.some((cohort: { status: string; }) => cohort.status === 'active'); + + if (hasActiveCohorts) { const cohortNames = cohortList - .map((cohort: { cohortName: any }) => cohort?.cohortName) + .filter((cohort: { status: string }) => cohort.status === 'active') + .map((cohort: { cohortName: string }) => cohort.cohortName) .join(', '); - + setOpenRemoveUserModal(true); 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); } diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index df9b49d2..be77af4b 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -221,6 +221,7 @@ export interface UpdateCustomField { order: number; } export interface ICohort { + typeOfCohort: string; presentPercentage: number; cohortId: string; name: string;