diff --git a/src/components/AddFacilitator.tsx b/src/components/AddFacilitator.tsx index 0fc16527..fc15bbd6 100644 --- a/src/components/AddFacilitator.tsx +++ b/src/components/AddFacilitator.tsx @@ -94,12 +94,15 @@ const AddFacilitatorModal: React.FC = ({ if (typeof window !== 'undefined' && window.localStorage) { const CenterList = localStorage.getItem('CenterList'); const centerOptions = CenterList ? JSON.parse(CenterList) : []; - centerOptionsList = centerOptions.map( - (center: { cohortId: string; cohortName: string }) => ({ - value: center.cohortId, - label: center.cohortName, - }) - ); + console.log("centerOptions",centerOptions); + + centerOptionsList = centerOptions + .filter((center: { cohortStatus: string }) => center.cohortStatus === 'active') + .map((center: { cohortId: string; cohortName: string }) => ({ + value: center.cohortId, + label: center.cohortName, + })); + console.log(centerOptionsList); } const assignCentersField: Field = { diff --git a/src/components/CohortSelectionSection.tsx b/src/components/CohortSelectionSection.tsx index 0787a1bf..b80f0251 100644 --- a/src/components/CohortSelectionSection.tsx +++ b/src/components/CohortSelectionSection.tsx @@ -104,6 +104,9 @@ const CohortSelectionSection: React.FC = ({ const { t } = useTranslation(); const setCohorts = useStore((state) => state.setCohorts); const setBlock = useStore((state) => state.setBlock); + const [filteredCohortData, setFilteredCohortData] = React.useState(); + const [filteredManipulatedCohortData, setFilteredManipulatedCohortData] = React.useState(); + const store = manageUserStore(); @@ -140,6 +143,22 @@ const CohortSelectionSection: React.FC = ({ } }, [router, setClassId, setIsAuthenticated, setUserId]); + useEffect(() => { + const filteredData = cohortsData?.filter( + (cohort: any) => + + cohort?.status?.toLowerCase() === "active" + ); + setFilteredCohortData(filteredData); + const filteredManipulatedData = manipulatedCohortData?.filter( + (cohort: any) => + + cohort?.status?.toLowerCase() === "active" + ); + setFilteredManipulatedCohortData(filteredManipulatedData); + console.log(filteredData) + }, [manipulatedCohortData, cohortsData]); + useEffect(() => { if (userId) { setLoading(true); @@ -228,6 +247,7 @@ const CohortSelectionSection: React.FC = ({ cohortId: item?.cohortId, parentId: item?.parentId, name: item?.cohortName || item?.name, + status: item?.status, })) ?.filter(Boolean); setCohortsData(filteredData); @@ -274,6 +294,7 @@ const CohortSelectionSection: React.FC = ({ parentId: item?.parentId, name: item?.cohortName || item?.name, typeOfCohort: typeOfCohort || t('ATTENDANCE.UNKNOWN'), + status: item?.status, }; }) ?.filter(Boolean); @@ -368,7 +389,7 @@ const CohortSelectionSection: React.FC = ({ {loading && ( )} - {!loading && cohortsData && ( + {!loading && filteredCohortData && ( = ({ }, }} > - {!loading && cohortsData && ( + {!loading && filteredCohortData && ( {blockName ? ( @@ -394,7 +415,7 @@ const CohortSelectionSection: React.FC = ({ - {cohortsData?.length > 1 ? ( + {filteredCohortData?.length > 1 ? ( = ({ /> )} > - {cohortsData?.length !== 0 ? ( - manipulatedCohortData?.map((cohort) => ( + {filteredCohortData?.length !== 0 ? ( + filteredManipulatedCohortData?.map((cohort: any) => ( = ({ ) : ( - {toPascalCase(cohortsData[0]?.name)} + {toPascalCase(filteredCohortData[0]?.name)} )} @@ -489,7 +510,7 @@ const CohortSelectionSection: React.FC = ({ - {cohortsData?.length > 1 ? ( + {filteredCohortData?.length > 1 ? ( = ({ ) : ( - {cohortsData[0]?.name} + {filteredCohortData[0]?.name} )}