From 86a5afe22443df70f8e8fd24eefe58c286bf28cd Mon Sep 17 00:00:00 2001 From: Rushikesh-Sonawane99 Date: Mon, 16 Dec 2024 17:07:40 +0530 Subject: [PATCH] Issue #PS-000 chore: Fixed Issue for modify learner attendance on day-wise-attendance page impacted due to re-assign functionality --- src/pages/learner-attendance-history.tsx | 43 +++++++++++++++++------- src/utils/Interfaces.ts | 5 ++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/pages/learner-attendance-history.tsx b/src/pages/learner-attendance-history.tsx index 6462efed..0fd72197 100644 --- a/src/pages/learner-attendance-history.tsx +++ b/src/pages/learner-attendance-history.tsx @@ -39,6 +39,7 @@ const LearnerAttendanceHistory = () => { const { push } = useRouter(); const store = useStore(); const isActiveYear = store.isActiveYearSelected; + const userCohorts = store.cohorts; const [loading, setLoading] = React.useState(false); const [selectedDate, setSelectedDate] = useState(new Date()); const [open, setOpen] = useState(false); @@ -46,6 +47,7 @@ const LearnerAttendanceHistory = () => { const [learnerAttendance, setLearnerAttendance] = useState< LearnerAttendanceData | undefined >(undefined); + const [extractedAttendanceDates, setExtractedAttendanceDates] = useState([]); useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { @@ -59,7 +61,7 @@ const LearnerAttendanceHistory = () => { } } else { push('/login', undefined, { locale: 'en' }); - } + } } }, []); @@ -124,7 +126,7 @@ const LearnerAttendanceHistory = () => { limit: 300, page: 0, filters: { - contextId: classId, + // contextId: classId, fromDate: fromDateFormatted, toDate: toDateFormatted, scope: 'student', @@ -133,16 +135,32 @@ const LearnerAttendanceHistory = () => { }; const response = await getLearnerAttendanceStatus(attendanceRequest); const attendanceStats = response?.data?.attendanceList; - const attendanceData = attendanceStats?.reduce( - (acc: LearnerAttendanceData, record: AttendanceRecord) => { - acc[record.attendanceDate] = { - attendanceStatus: record.attendance, - }; - return acc; - }, - {} - ); - setLearnerAttendance(attendanceData); + if (userCohorts && attendanceStats) { + const filteredAttendanceStats = attendanceStats.filter( + (stat: { contextId: any }) => + userCohorts.some( + (cohort: { cohortId: any }) => + cohort.cohortId === stat.contextId + ) + ); + if (filteredAttendanceStats) { + const attendanceData = filteredAttendanceStats?.reduce( + (acc: LearnerAttendanceData, record: AttendanceRecord) => { + acc[record.attendanceDate] = { + attendanceStatus: record.attendance, + }; + return acc; + }, + {} + ); + setLearnerAttendance(attendanceData); + const extractedData = filteredAttendanceStats.map((item: { attendanceDate: any; contextId: any; }) => ({ + attendanceDate: item.attendanceDate, + contextId: item.contextId + })); + setExtractedAttendanceDates(extractedData) + } + } setLoading(false); } } catch (err) { @@ -244,6 +262,7 @@ const LearnerAttendanceHistory = () => { } handleClose={handleModalClose} onAttendanceUpdate={() => setAttendanceUpdated(!attendanceUpdated)} + attendanceDates = {extractedAttendanceDates} /> ); diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 640680ae..edce1b63 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -21,6 +21,7 @@ export interface MarkAttendanceProps { currentStatus: string; handleClose: () => void; onAttendanceUpdate: () => void; + attendanceDates?: any[] } export interface AttendanceStatusListViewProps { @@ -37,6 +38,7 @@ export interface AttendanceStatusListViewProps { bulkAttendanceStatus?: string; presentCount?: number; absentCount?: number; + attendanceDate?: Date; } export interface UserAttendanceObj { @@ -45,6 +47,7 @@ export interface UserAttendanceObj { name?: string; attendanceDate?: Date | string; memberStatus?: string; + updatedAt?: string | number | Date; } export interface user { @@ -234,7 +237,7 @@ export interface LearnerAttendanceProps { limit?: number; page?: number; filters: { - contextId: string; + contextId?: string; scope: string; toDate: string | Date; fromDate: string | Date;