diff --git a/src/pages/course-planner-detail.tsx b/src/pages/course-planner-detail.tsx index 9422fc35f..088237d7c 100644 --- a/src/pages/course-planner-detail.tsx +++ b/src/pages/course-planner-detail.tsx @@ -34,6 +34,7 @@ import { AssessmentStatus, Role } from '@/utils/app.constant'; import Loader from '@/components/Loader'; import withAccessControl from '@/utils/hoc/withAccessControl'; import { accessControl } from '../../app.config'; +import taxonomyStore from '@/store/taxonomyStore'; import useDeterminePathColor from '@/hooks/useDeterminePathColor'; const CoursePlannerDetail = () => { @@ -42,6 +43,7 @@ const CoursePlannerDetail = () => { const { t } = useTranslation(); const setResources = useCourseStore((state) => state.setResources); const store = useCourseStore(); + const tStore = taxonomyStore(); const [loading, setLoading] = useState(false); const determinePathColor = useDeterminePathColor(); // Initialize the panels' state, assuming you have a known set of panel IDs @@ -58,23 +60,20 @@ const CoursePlannerDetail = () => { const [modalOpen, setModalOpen] = React.useState(false); const [userProjectDetails, setUserProjectDetails] = useState(); const [statusData, setStatusData] = useState(); + const [completionPercentage, setCompletionPercentage] = useState(0); - const { subject } = router.query; - const { state } = router.query; - const { medium } = router.query; - const { grade } = router.query; - const { board } = router.query; + const fetchCourseDetails = useCallback(async () => { try { setLoading(true); const response = await getTargetedSolutions({ - subject: subject, - class: grade, - state: state, - board: board, - type: 'mainCourse', - medium: medium, + subject: tStore?.taxonomySubject, + class: tStore?.grade, + state: tStore?.state, + board: tStore?.board, + type: tStore?.type, + medium: tStore?.medium, }); if (response?.result?.data == '') { @@ -132,12 +131,12 @@ const CoursePlannerDetail = () => { }); const updatedResponse = await getTargetedSolutions({ - subject: subject, - class: grade, - state: state, - board: board, - type: 'mainCourse', - medium: medium, + subject: tStore?.taxonomySubject, + class: tStore?.grade, + state: tStore?.state, + board: tStore?.board, + type: tStore?.type, + medium: tStore?.medium, }); setLoading(false); @@ -387,202 +386,196 @@ const CoursePlannerDetail = () => { ) : ( <> - {userProjectDetails?.tasks?.map((topic: any, index: number) => ( - - - setExpandedPanels((prev) => ({ - ...prev, - [`panel${index}-header`]: !prev[`panel${index}-header`], - })) - } + {userProjectDetails?.tasks?.length > 0 ? ( + userProjectDetails.tasks.map((topic: any, index: number) => ( + + + setExpandedPanels((prev) => ({ + ...prev, + [`panel${index}-header`]: !prev[`panel${index}-header`], + })) + } + sx={{ + boxShadow: 'none', + background: '#F1E7D9', + border: 'none', + transition: '0.3s', + }} + > + + } + aria-controls={`panel${index}-content`} + id={`panel${index}-header`} + className="accordion-summary" + sx={{ + px: '16px', + m: 0, + '&.Mui-expanded': { + minHeight: '48px', + }, + }} + > + + + + + {`Topic ${index + 1} - ${topic.name}`} + + + + {getAbbreviatedMonth(topic?.metaInformation?.startDate)},{' '} + {getAbbreviatedMonth(topic?.metaInformation?.endDate)} + + + + + {topic.children.map((subTopic: any) => ( + + + - - } - aria-controls={`panel${index}-content`} - id={`panel${index}-header`} - className="accordion-summary" + { + setResources(subTopic); + router.push(`/topic-detail-view`); + }} + > + {subTopic.name} + + - - - - {`Topic ${index + 1} - ${topic.name}`} - - - - {getAbbreviatedMonth( - topic?.metaInformation?.startDate - )} - ,{' '} - {getAbbreviatedMonth(topic?.metaInformation?.endDate)} - + {getAbbreviatedMonth( + subTopic?.metaInformation?.startDate + )} - - { + if (!isStatusCompleted(subTopic._id)) { + markStatus(userProjectDetails, topic._id, subTopic._id); + } + }} + sx={{ + fontSize: '20px', + color: isStatusCompleted(subTopic._id) + ? '#4CAF50' + : '#7C766e', + cursor: isStatusCompleted(subTopic._id) + ? 'default' + : 'pointer', + pointerEvents: isStatusCompleted(subTopic._id) + ? 'none' + : 'auto', + }} + /> + + + { + router.push(`/topic-detail-view`); + }} + > + { + setResources(subTopic); + router.push(`/topic-detail-view`); }} > - {topic.children.map((subTopic: any) => ( - - - - { - setResources(subTopic); - router.push(`/topic-detail-view`); - }} - > - {subTopic.name} - - - - {getAbbreviatedMonth( - subTopic?.metaInformation?.startDate - )} - - { - if (!isStatusCompleted(subTopic._id)) { - markStatus( - userProjectDetails, - topic._id, - subTopic._id - ); - } - }} - sx={{ - fontSize: '20px', - color: isStatusCompleted(subTopic._id) - ? '#4CAF50' - : '#7C766e', - cursor: isStatusCompleted(subTopic._id) - ? 'default' - : 'pointer', - pointerEvents: isStatusCompleted( - subTopic._id - ) - ? 'none' - : 'auto', - }} - /> - - - { - router.push(`/topic-detail-view`); - }} - > - { - setResources(subTopic); - router.push(`/topic-detail-view`); - }} - > - {`${subTopic?.learningResources?.length} ${t('COURSE_PLANNER.RESOURCES')}`} - - - - - - ))} - - + {`${subTopic?.learningResources?.length} ${t( + 'COURSE_PLANNER.RESOURCES' + )}`} + + + - ))} - + + ))} + + + + )) + ) : ( + + {t('ASSESSMENTS.NO_DATA_FOUND')} + + )} + + )} diff --git a/src/pages/course-planner.tsx b/src/pages/course-planner.tsx index ae5f82593..c9121534e 100644 --- a/src/pages/course-planner.tsx +++ b/src/pages/course-planner.tsx @@ -7,6 +7,7 @@ import { Grid, IconButton, InputBase, + InputLabel, MenuItem, Paper, Select, @@ -18,7 +19,7 @@ import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useRouter } from 'next/router'; -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { CircularProgressbar, buildStyles } from 'react-circular-progressbar'; import { getCoursePlanner } from '@/services/CoursePlannerService'; import { CoursePlannerData } from '@/utils/Interfaces'; @@ -26,29 +27,51 @@ import useCourseStore from '@/store/coursePlannerStore'; import { getCohortSearch } from '@/services/CohortServices'; import { CoursePlannerConstants } from '@/utils/app.constant'; import useStore from '@/store/store'; -import { accessControl } from '../../app.config'; +import { accessControl, frameworkId } from '../../app.config'; import withAccessControl from '@/utils/hoc/withAccessControl'; import NoDataFound from '@/components/common/NoDataFound'; -import { toPascalCase } from '@/utils/Helper'; - -// Define a type for the course planner data +import taxonomyStore from '@/store/taxonomyStore'; +import coursePlannerStore from '@/store/coursePlannerStore'; +import { + filterAndMapAssociationsNew, + findCommonAssociations, + getAssociationsByCodeNew, + getOptionsByCategory, + toPascalCase, +} from '@/utils/Helper'; const CoursePlanner = () => { - const [value, setValue] = React.useState(1); + const [value, setValue] = React.useState(); const [subjects, setSubjects] = React.useState([]); - const [state, setState] = React.useState(''); - const [board, setBoard] = React.useState(''); - const [medium, setMedium] = React.useState(''); - const [grade, setGrade] = React.useState(''); const [selectedValue, setSelectedValue] = React.useState(''); - + const setStateassociations = coursePlannerStore( + (state) => state.setStateassociations + ); const theme = useTheme(); const { t } = useTranslation(); const router = useRouter(); const inputRef = React.useRef(null); + const [framework, setFramework] = useState([]); const setSubject = useCourseStore((state) => state.setSubject); + const setState = taxonomyStore((state) => state.setState); + const setBoard = taxonomyStore((state) => state.setBoard); + const [boardOptions, setBoardOptions] = useState([]); + const [boardAssociations, setBoardAssociations] = useState([]); + const setMedium = taxonomyStore((state) => state.setMedium); + const [mediumOptions, setMediumOptions] = useState([]); + const [mediumAssociations, setMediumAssociations] = useState([]); + const setGrade = taxonomyStore((state) => state.setGrade); + const [gradeOptions, setGradeOptions] = useState([]); + const [gradeAssociations, setGradeAssociations] = useState([]); + const setType = taxonomyStore((state) => state.setType); + const [typeOptions, setTypeOptions] = useState([]); + const [typeAssociations, setTypeAssociations] = useState([]); + const userStateName = localStorage.getItem('stateName'); const store = useStore(); - + const tStore = taxonomyStore(); + const [stateOption, setStateOption] = useState([]); + const [stateAssociations, setStateAssociations] = useState([]); + const setTaxonomySubject = taxonomyStore((state) => state.setTaxonomySubject); const handleScrollDown = () => { if (inputRef.current) { const inputRect = inputRef.current.getBoundingClientRect(); @@ -59,6 +82,11 @@ const CoursePlanner = () => { } }; + const handleChange = (event: any) => { + setValue(event.target.value); + setType(event.target.value); + }; + const addQueryParams = (newParams: any) => { // Merge existing query params with new ones const updatedQuery = { ...router.query, ...newParams }; @@ -74,10 +102,6 @@ const CoursePlanner = () => { ); }; - const handleChange = (event: React.SyntheticEvent, newValue: number) => { - setValue(newValue); - }; - const handleCohortChange = (event: any) => { setSelectedValue(event.target.value); addQueryParams({ center: event.target.value }); @@ -88,7 +112,7 @@ const CoursePlanner = () => { const cohortId = router.query.center ? router.query.center : store.cohorts[0].cohortId; - + addQueryParams({ center: cohortId }); setSelectedValue(cohortId); } @@ -122,7 +146,7 @@ const CoursePlanner = () => { (field: any) => field.label === label ); - if (field?.value) { + if (field && field.value) { const valuesArray = field.value .split(',') .map((item: string) => item.trim()); @@ -137,20 +161,599 @@ const CoursePlanner = () => { (field: any) => field.label === label ); - if (field?.value) { + if (field && field.value) { setter(field.value.trim()); } }); + + const url = `${process.env.NEXT_PUBLIC_SUNBIRDSAAS_API_URL}/read/${frameworkId}`; + const boardData = await fetch(url).then((res) => res.json()); + console.log(boardData?.result?.framework); + const frameworks = boardData?.result?.framework; + const getStates = getOptionsByCategory(frameworks, 'state'); + + setFramework(frameworks); + const matchingState = getStates.find( + (state: any) => state.name === userStateName + ); + if (matchingState) { + setStateOption([matchingState]); + setStateAssociations(matchingState.associations); + + const getBoards = await getOptionsByCategory(frameworks, 'board'); + if (getBoards && matchingState) { + const commonBoards = getBoards + .filter((item1: { code: any }) => + matchingState.associations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && item2.category === 'board' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + setBoardOptions(commonBoards); + const getMedium = await getOptionsByCategory(framework, 'medium'); + const boardAssociations = getAssociationsByCodeNew( + boardOptions, + tStore?.board + ); + + setBoardAssociations(boardAssociations); + + const commonMediumInState = getMedium + .filter((item1: { code: string }) => + stateAssociations.some( + (item2: { code: string; category: string }) => + item2.code === item1.code && item2.category === 'medium' + ) + ) + .map( + (item1: { + name: string; + code: string; + associations: any[]; + }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + }) + ); + + const commonMediumInBoard = getMedium + .filter((item1: { code: any }) => + boardAssociations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && item2.category === 'medium' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + console.log(`commonMediumInState`, commonMediumInState); + console.log(`commonMediumInBoard`, commonMediumInBoard); + + const commonMediumData = findCommonAssociations( + commonMediumInState, + commonMediumInBoard + ); + setMediumOptions(commonMediumData); + + const getGrades = await getOptionsByCategory( + framework, + 'gradeLevel' + ); + const mediumAssociations = getAssociationsByCodeNew( + mediumOptions, + tStore?.medium + ); + console.log('boardAssociations', stateAssociations); + setMediumAssociations(mediumAssociations); + + const commonGradeInState = getGrades + .filter((item1: { code: string }) => + stateAssociations.some( + (item2: { code: string; category: string }) => + item2.code === item1.code && + item2.category === 'gradeLevel' + ) + ) + .map( + (item1: { + name: string; + code: string; + associations: any[]; + }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + }) + ); + + const commonGradeInBoard = getGrades + .filter((item1: { code: any }) => + boardAssociations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && + item2.category === 'gradeLevel' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + + const commonGradeInMedium = await getGrades + .filter((item1: { code: any }) => + mediumAssociations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && + item2.category === 'gradeLevel' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + console.log(`commonGradeInState`, commonGradeInState); + console.log(`commonGradeInMedium`, commonGradeInMedium); + + const commonGradeInStateBoard = findCommonAssociations( + commonGradeInState, + commonGradeInBoard + ); + const overAllCommonGrade = findCommonAssociations( + commonGradeInStateBoard, + commonGradeInMedium + ); + setGradeOptions(overAllCommonGrade); + + const gradeAssociations = await getAssociationsByCodeNew( + gradeOptions, + tStore?.grade + ); + setGradeAssociations(gradeAssociations); + const type = await getOptionsByCategory(framework, 'courseType'); + console.log(type); + + const commonTypeInState = filterAndMapAssociationsNew( + 'courseType', + type, + stateAssociations, + 'code' + ); + const commonTypeInBoard = filterAndMapAssociationsNew( + 'courseType', + type, + boardAssociations, + 'code' + ); + const commonTypeInMedium = filterAndMapAssociationsNew( + 'courseType', + type, + mediumAssociations, + 'code' + ); + const commonTypeInGrade = filterAndMapAssociationsNew( + 'courseType', + type, + gradeAssociations, + 'code' + ); + + const commonTypeData = findCommonAssociations( + commonTypeInState, + commonTypeInBoard + ); + const commonType2Data = findCommonAssociations( + commonTypeInMedium, + commonTypeInGrade + ); + const commonType3Data = findCommonAssociations( + commonTypeData, + commonType2Data + ); + + console.log(`commonTypeOverall`, commonType3Data); + setTypeOptions(commonType3Data); + // setType(commonType3Data); + + const typeAssociations = await getAssociationsByCodeNew( + typeOptions, + tStore?.type + ); + setTypeAssociations(typeAssociations); + const subject = await getOptionsByCategory(framework, 'subject'); + + console.log(subject); + + const commonSubjectInState = filterAndMapAssociationsNew( + 'subject', + subject, + stateAssociations, + 'code' + ); + const commonSubjectInBoard = filterAndMapAssociationsNew( + 'subject', + type, + boardAssociations, + 'code' + ); + const commonSubjectInMedium = filterAndMapAssociationsNew( + 'subject', + subject, + mediumAssociations, + 'code' + ); + const commonSubjectInGrade = filterAndMapAssociationsNew( + 'subject', + subject, + gradeAssociations, + 'code' + ); + const commonSubjectInType = filterAndMapAssociationsNew( + 'subject', + subject, + typeAssociations, + 'code' + ); + + const findCommonAssociationsNew = ( + array1: any[], + array2: any[] + ) => { + return array1.filter((item1: { code: any }) => + array2.some( + (item2: { code: any }) => item1.code === item2.code + ) + ); + }; + + const findOverallCommonSubjects = (arrays: any[]) => { + const nonEmptyArrays = arrays.filter( + (array: string | any[]) => array && array.length > 0 + ); + + if (nonEmptyArrays.length === 0) return []; + + let commonSubjects = nonEmptyArrays[0]; + + for (let i = 1; i < nonEmptyArrays.length; i++) { + commonSubjects = findCommonAssociationsNew( + commonSubjects, + nonEmptyArrays[i] + ); + + if (commonSubjects.length === 0) return []; + } + + return commonSubjects; + }; + + const arrays = [ + commonSubjectInState, + commonSubjectInBoard, + commonSubjectInMedium, + commonSubjectInGrade, + commonSubjectInType, + ]; + + const overallCommonSubjects = + await findOverallCommonSubjects(arrays); + + console.log(overallCommonSubjects); + + setSubjects(overallCommonSubjects); + } + } } } catch (error) { console.error('Failed to fetch cohort search results:', error); } }; - if (selectedValue) { - fetchCohortSearchResults(); - } - }, [selectedValue]); + fetchCohortSearchResults(); + }, []); + + useEffect(() => { + const fetchTaxonomyResults = async () => { + try { + const url = `${process.env.NEXT_PUBLIC_SUNBIRDSAAS_API_URL}/api/framework/v1/read/${frameworkId}`; + const boardData = await fetch(url).then((res) => res.json()); + console.log(boardData?.result?.framework); + const frameworks = boardData?.result?.framework; + const getStates = getOptionsByCategory(frameworks, 'state'); + + setFramework(frameworks); + const matchingState = getStates.find( + (state: any) => state.name === userStateName + ); + if (matchingState) { + setStateOption([matchingState]); + setStateAssociations(matchingState.associations); + + const getBoards = await getOptionsByCategory(frameworks, 'board'); + if (getBoards && matchingState) { + const commonBoards = getBoards + .filter((item1: { code: any }) => + matchingState.associations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && item2.category === 'board' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + setBoardOptions(commonBoards); + const getMedium = await getOptionsByCategory(framework, 'medium'); + const boardAssociations = getAssociationsByCodeNew( + boardOptions, + tStore?.board + ); + + setBoardAssociations(boardAssociations); + + const commonMediumInState = getMedium + .filter((item1: { code: string }) => + stateAssociations.some( + (item2: { code: string; category: string }) => + item2.code === item1.code && item2.category === 'medium' + ) + ) + .map( + (item1: { + name: string; + code: string; + associations: any[]; + }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + }) + ); + + const commonMediumInBoard = getMedium + .filter((item1: { code: any }) => + boardAssociations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && item2.category === 'medium' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + console.log(`commonMediumInState`, commonMediumInState); + console.log(`commonMediumInBoard`, commonMediumInBoard); + + const commonMediumData = findCommonAssociations( + commonMediumInState, + commonMediumInBoard + ); + setMediumOptions(commonMediumData); + + const getGrades = await getOptionsByCategory( + framework, + 'gradeLevel' + ); + const mediumAssociations = getAssociationsByCodeNew( + mediumOptions, + tStore?.medium + ); + console.log('boardAssociations', stateAssociations); + setMediumAssociations(mediumAssociations); + + const commonGradeInState = getGrades + .filter((item1: { code: string }) => + stateAssociations.some( + (item2: { code: string; category: string }) => + item2.code === item1.code && item2.category === 'gradeLevel' + ) + ) + .map( + (item1: { + name: string; + code: string; + associations: any[]; + }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + }) + ); + + const commonGradeInBoard = getGrades + .filter((item1: { code: any }) => + boardAssociations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && item2.category === 'gradeLevel' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + + const commonGradeInMedium = await getGrades + .filter((item1: { code: any }) => + mediumAssociations.some( + (item2: { code: any; category: string }) => + item2.code === item1.code && item2.category === 'gradeLevel' + ) + ) + .map((item1: { name: any; code: any; associations: any }) => ({ + name: item1.name, + code: item1.code, + associations: item1.associations, + })); + console.log(`commonGradeInState`, commonGradeInState); + console.log(`commonGradeInMedium`, commonGradeInMedium); + + const commonGradeInStateBoard = findCommonAssociations( + commonGradeInState, + commonGradeInBoard + ); + const overAllCommonGrade = findCommonAssociations( + commonGradeInStateBoard, + commonGradeInMedium + ); + setGradeOptions(overAllCommonGrade); + + const gradeAssociations = await getAssociationsByCodeNew( + gradeOptions, + tStore?.grade + ); + setGradeAssociations(gradeAssociations); + const type = await getOptionsByCategory(framework, 'courseType'); + console.log(type); + + const commonTypeInState = filterAndMapAssociationsNew( + 'courseType', + type, + stateAssociations, + 'code' + ); + const commonTypeInBoard = filterAndMapAssociationsNew( + 'courseType', + type, + boardAssociations, + 'code' + ); + const commonTypeInMedium = filterAndMapAssociationsNew( + 'courseType', + type, + mediumAssociations, + 'code' + ); + const commonTypeInGrade = filterAndMapAssociationsNew( + 'courseType', + type, + gradeAssociations, + 'code' + ); + + const commonTypeData = findCommonAssociations( + commonTypeInState, + commonTypeInBoard + ); + const commonType2Data = findCommonAssociations( + commonTypeInMedium, + commonTypeInGrade + ); + const commonType3Data = findCommonAssociations( + commonTypeData, + commonType2Data + ); + + console.log(`commonTypeOverall`, commonType3Data); + setTypeOptions(commonType3Data); + // setType(commonType3Data); + + const typeAssociations = getAssociationsByCodeNew( + typeOptions, + tStore?.type + ); + setTypeAssociations(typeAssociations); + const subject = await getOptionsByCategory(framework, 'subject'); + + console.log(subject); + + const commonSubjectInState = filterAndMapAssociationsNew( + 'subject', + subject, + stateAssociations, + 'code' + ); + const commonSubjectInBoard = filterAndMapAssociationsNew( + 'subject', + type, + boardAssociations, + 'code' + ); + const commonSubjectInMedium = filterAndMapAssociationsNew( + 'subject', + subject, + mediumAssociations, + 'code' + ); + const commonSubjectInGrade = filterAndMapAssociationsNew( + 'subject', + subject, + gradeAssociations, + 'code' + ); + const commonSubjectInType = filterAndMapAssociationsNew( + 'subject', + subject, + typeAssociations, + 'code' + ); + + const findCommonAssociationsNew = ( + array1: any[], + array2: any[] + ) => { + return array1.filter((item1: { code: any }) => + array2.some((item2: { code: any }) => item1.code === item2.code) + ); + }; + + const findOverallCommonSubjects = (arrays: any[]) => { + const nonEmptyArrays = arrays.filter( + (array: string | any[]) => array && array.length > 0 + ); + + if (nonEmptyArrays.length === 0) return []; + + let commonSubjects = nonEmptyArrays[0]; + + for (let i = 1; i < nonEmptyArrays.length; i++) { + commonSubjects = findCommonAssociationsNew( + commonSubjects, + nonEmptyArrays[i] + ); + + if (commonSubjects.length === 0) return []; + } + + return commonSubjects; + }; + + const arrays = [ + commonSubjectInState, + commonSubjectInBoard, + commonSubjectInMedium, + commonSubjectInGrade, + commonSubjectInType, + ]; + + const overallCommonSubjects = + await findOverallCommonSubjects(arrays); + + console.log(overallCommonSubjects); + + setSubjects(overallCommonSubjects); + } + } + } catch (error) { + console.error('Failed to fetch cohort search results:', error); + } + }; + + + fetchTaxonomyResults(); + + }, [value]); return ( @@ -191,7 +794,7 @@ const CoursePlanner = () => { MenuProps={{ style: { maxHeight: 400, - }, + } }} > {store.cohorts.map((cohort: any) => ( @@ -200,7 +803,7 @@ const CoursePlanner = () => { value={cohort.cohortId} className="text-truncate" > - {toPascalCase(cohort?.name)} + {toPascalCase(cohort?.name)} ))} @@ -234,172 +837,143 @@ const CoursePlanner = () => { - - - + + Course Type + + + + + - - - - - {value === 1 && ( - - - - {subjects?.length > 0 ? ( - subjects.map((item: any) => ( - + + {subjects?.length > 0 ? ( + subjects.map((item: any) => ( + + { + setTaxonomySubject(item.name); + router.push({ + pathname: '/course-planner-detail', + }); + }} + > { - setSubject(item); - router.push({ - pathname: '/course-planner-detail', - query: { - subject: item, - state: state, - board: board, - medium: medium, - grade: grade, - }, - }); + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center', }} > - - + + + {/* + + + - {/* - - - - - - {item.circular}% - - */} - + {item.circular || 0}% + + */} + - - {item} - + + {item.name} - - - + + + - - )) - ) : ( - - )} - - + + + )) + ) : ( + + + {t('ASSESSMENTS.NO_DATA_FOUND')} + + + )} + - )} - {value === 2 && ( - - )} + ); diff --git a/src/store/taxonomyStore.js b/src/store/taxonomyStore.js new file mode 100644 index 000000000..cc2f30f70 --- /dev/null +++ b/src/store/taxonomyStore.js @@ -0,0 +1,31 @@ +/* eslint-disable no-unused-vars */ +import { create } from 'zustand'; +import { persist } from 'zustand/middleware'; + +const taxonomyStore = create( + persist( + (set) => ({ + state: "", + board:"", + medium:"", + grade:"", + type:"", + taxonomySubject:"", + stateassociations: [], + setState: (newState) => set(() => ({ state: newState })), + setBoard: (newBoard) => set(() => ({ board: newBoard })), + setMedium: (newMedium) => set(() => ({ medium: newMedium })), + setGrade: (newGrade) => set(() => ({ grade: newGrade })), + setType: (newType) => set(() => ({ type: newType })), + setTaxonomySubject: (newTaxonomySubject) => set(() => ({ taxonomySubject: newTaxonomySubject })), + setStateassociations: (newStateassociations) => + set((state) => ({ stateassociations: newStateassociations })), + }), + { + name: 'taxonomyTeacher', + getStorage: () => localStorage, + } + ) +); + +export default taxonomyStore; diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index 41004758c..1ab158b8b 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -489,6 +489,14 @@ export const getAssociationsByName = (data: DataItem[], name: string): Associati return foundItem ? foundItem.associations : []; }; + +export const getAssociationsByCodeNew = (data: DataItem[], code: string): Association[] | [] => { + const foundItem = data.find(item => item.name === code); + return foundItem ? foundItem.associations : []; +}; + + + export const getAssociationsByCode = (data: DataItem[], code: string): Association[] | [] => { const foundItem = data.find(item => item.code === code); return foundItem ? foundItem.associations : []; @@ -509,4 +517,34 @@ export const findCommonAssociations = (data1: any[], data2: any[]) => { } return null; }).filter(Boolean); -}; \ No newline at end of file +}; + +export const filterAndMapAssociationsNew = ( + category: string, + options: any[], + associationsList?: any[], + codeKey: string = "code" +) => { + if (!Array.isArray(options)) { + console.error("Options is not an array:", options); + return []; + } + + if (!associationsList || associationsList.length === 0) { + return []; + } + + return options + .filter((option) => { + const optionCode = option[codeKey]; + + return associationsList.some( + (assoc) => assoc[codeKey] === optionCode && assoc.category === category + ); + }) + .map((option) => ({ + name: option.name, + code: option.code, + associations: option.associations || [], + })); +};