diff --git a/src/pages/attendance-history.tsx b/src/pages/attendance-history.tsx index 044b78d21..20d6ab430 100644 --- a/src/pages/attendance-history.tsx +++ b/src/pages/attendance-history.tsx @@ -22,6 +22,7 @@ import { AttendanceStatusListProps, ICohort, CohortMemberList, + user, } from '../utils/Interfaces'; import AttendanceStatus from '@/components/AttendanceStatus'; @@ -54,14 +55,6 @@ import { attendanceStatusList } from '../services/AttendanceService'; import { telemetryFactory } from '@/utils/telemetry'; import NoDataFound from '@/components/common/NoDataFound'; -interface user { - memberStatus: string; - userId: string; - name: string; - attendance?: string; - key?: string; -} - const UserAttendanceHistory = () => { const theme = useTheme(); const { t } = useTranslation(); diff --git a/src/pages/board-enrollment/index.tsx b/src/pages/board-enrollment/index.tsx index be9a85e2f..9d3be55d6 100644 --- a/src/pages/board-enrollment/index.tsx +++ b/src/pages/board-enrollment/index.tsx @@ -26,6 +26,11 @@ import PieChartGraph from '@/components/PieChartGraph'; import { boardEnrollment } from '@/services/BoardEnrollmentServics'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import { useRouter } from 'next/router'; +import CohortSelectionSection from '@/components/CohortSelectionSection'; +import { ICohort, user } from '@/utils/Interfaces'; +import { toPascalCase } from '@/utils/Helper'; +import { showToastMessage } from '@/components/Toastify'; +import { getMyCohortMemberList } from '@/services/MyClassDetailsService'; const BoardEnrollment = () => { const theme = useTheme(); @@ -33,11 +38,85 @@ const BoardEnrollment = () => { const router = useRouter(); const [boardEnrollmentList, setBoardEnrollmentList] = useState([]); const [activeStep, setActiveStep] = React.useState(0); + const [classId, setClassId] = React.useState(''); + const [cohortsData, setCohortsData] = React.useState>([]); + const [manipulatedCohortData, setManipulatedCohortData] = + React.useState>(cohortsData); + const [isAuthenticated, setIsAuthenticated] = React.useState(false); + const [userId, setUserId] = React.useState(null); + const [blockName, setBlockName] = React.useState(''); + const [displayStudentList, setDisplayStudentList] = React.useState< + Array +>([]); + const [loading, setLoading] = React.useState(false); + useEffect(() => { const res = boardEnrollment(); setBoardEnrollmentList(res); }, []); + useEffect(() => { + if (typeof window !== 'undefined' && window.localStorage) { + const token = localStorage.getItem('token'); + setClassId(localStorage.getItem('classId') ?? ''); + const classId = localStorage.getItem('classId') ?? ''; + localStorage.setItem('cohortId', classId); + setLoading(false); + if (token) { + router.push('/board-enrollment'); + } else { + router.push('/login', undefined, { locale: 'en' }); + } + } + }, []); + + useEffect(()=>{ + const getCohortMemberList = async () => { + setLoading(true); + try { + if (classId) { + const limit = 300; + const page = 0; + const filters = { cohortId: classId }; + const response = await getMyCohortMemberList({ + limit, + page, + filters, + }); + const resp = response?.result?.userDetails || []; + + if (resp) { + const selectedDateStart = new Date(); + selectedDateStart.setHours(0, 0, 0, 0); + const nameUserIdArray = resp + .filter((entry: any) => { + const createdAtDate = new Date(entry.createdAt); + createdAtDate.setHours(0, 0, 0, 0); + return createdAtDate <= selectedDateStart; + }) + .map((entry: any) => ({ + userId: entry.userId, + name: toPascalCase(entry.name), + memberStatus: entry.status, + createdAt: entry.createdAt, + })); + console.log(`nameUserIdArray`, nameUserIdArray) + setDisplayStudentList(nameUserIdArray) + } else { + setDisplayStudentList([]); + } + } + } catch (error) { + console.error('Error fetching cohort list:', error); + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); + setLoading(false); + } finally { + setLoading(false); + } + }; + getCohortMemberList() + },[classId]) + return ( <>
@@ -83,7 +162,7 @@ const BoardEnrollment = () => { - + {/* - + */} +