Skip to content

Commit

Permalink
Merge pull request #526 from Rushikesh-Sonawane99/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-000 chore: Fixed Issue for modify learner attendance on day-wise-attendance page impacted due to re-assign functionality by passing correct cohortId as per selectedDate
  • Loading branch information
itsvick authored Dec 16, 2024
2 parents 06c9d02 + 4647972 commit d76a98a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
43 changes: 31 additions & 12 deletions src/pages/learner-attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ 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<Date>(new Date());
const [open, setOpen] = useState(false);
const [attendanceUpdated, setAttendanceUpdated] = useState(false);
const [learnerAttendance, setLearnerAttendance] = useState<
LearnerAttendanceData | undefined
>(undefined);
const [extractedAttendanceDates, setExtractedAttendanceDates] = useState([]);

useEffect(() => {
if (typeof window !== 'undefined' && window.localStorage) {
Expand All @@ -59,7 +61,7 @@ const LearnerAttendanceHistory = () => {
}
} else {
push('/login', undefined, { locale: 'en' });
}
}
}
}, []);

Expand Down Expand Up @@ -124,7 +126,7 @@ const LearnerAttendanceHistory = () => {
limit: 300,
page: 0,
filters: {
contextId: classId,
// contextId: classId,
fromDate: fromDateFormatted,
toDate: toDateFormatted,
scope: 'student',
Expand All @@ -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) {
Expand Down Expand Up @@ -244,6 +262,7 @@ const LearnerAttendanceHistory = () => {
}
handleClose={handleModalClose}
onAttendanceUpdate={() => setAttendanceUpdated(!attendanceUpdated)}
attendanceDates = {extractedAttendanceDates}
/>
</Box>
);
Expand Down
5 changes: 4 additions & 1 deletion src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface MarkAttendanceProps {
currentStatus: string;
handleClose: () => void;
onAttendanceUpdate: () => void;
attendanceDates?: any[]
}

export interface AttendanceStatusListViewProps {
Expand All @@ -37,6 +38,7 @@ export interface AttendanceStatusListViewProps {
bulkAttendanceStatus?: string;
presentCount?: number;
absentCount?: number;
attendanceDate?: Date;
}

export interface UserAttendanceObj {
Expand All @@ -45,6 +47,7 @@ export interface UserAttendanceObj {
name?: string;
attendanceDate?: Date | string;
memberStatus?: string;
updatedAt?: string | number | Date;
}

export interface user {
Expand Down Expand Up @@ -234,7 +237,7 @@ export interface LearnerAttendanceProps {
limit?: number;
page?: number;
filters: {
contextId: string;
contextId?: string;
scope: string;
toDate: string | Date;
fromDate: string | Date;
Expand Down

0 comments on commit d76a98a

Please sign in to comment.