From 7c7b86fde1c6552132af8d69daa1cdd0749aff80 Mon Sep 17 00:00:00 2001 From: Rushikesh-Sonawane99 Date: Thu, 16 May 2024 17:00:18 +0530 Subject: [PATCH] Issue #PS-387 feat: Added functionality for mark and update learner backdated attendance along with retention feature if attendance already marked --- public/locales/en/common.json | 2 +- public/locales/hi/common.json | 2 +- public/locales/mr/common.json | 2 +- src/pages/dashboard.tsx | 38 ++++++++++++++--------------- src/services/AttendanceService.ts | 40 +++++++++++++++---------------- src/utils/Helper.ts | 18 ++++++++++++++ 6 files changed, 59 insertions(+), 43 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index e7fb9378..e5bf26e9 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -4,7 +4,7 @@ "LOADING": "Loading", "MARK": "Mark", "MARK_MY_ATTENDANCE": "Mark My Attendance", - "MARK_STUDENT_ATTENDANCE": "Mark Student Attendance", + "MARK_CENTER_ATTENDANCE": "Mark Center Attendance", "MARK_ATTENDANCE": "Mark Attendance", "UPDATE_ATTENDANCE": "Update Attendance", "SAVE": "Save", diff --git a/public/locales/hi/common.json b/public/locales/hi/common.json index 5e7849aa..c25aff4b 100644 --- a/public/locales/hi/common.json +++ b/public/locales/hi/common.json @@ -3,7 +3,7 @@ "LANGUAGE": "भाषा", "MARK": "मार्क", "MARK_MY_ATTENDANCE": "मेरी उपस्थिति चिह्नित करें", - "MARK_STUDENT_ATTENDANCE": "छात्र उपस्थिति चिह्नित करें", + "MARK_CENTER_ATTENDANCE": "केंद्र पर उपस्थिति दर्ज करें", "MARK_ATTENDANCE": "उपस्थिति चिह्नित करें", "UPDATE_ATTENDANCE": "उपस्थिति अपडेट करें", "LOADING": "लोडिंग", diff --git a/public/locales/mr/common.json b/public/locales/mr/common.json index ee9e2ed0..b91369d2 100644 --- a/public/locales/mr/common.json +++ b/public/locales/mr/common.json @@ -3,7 +3,7 @@ "LANGUAGE": "भाषा", "MARK": "मार्क", "MARK_MY_ATTENDANCE": "माझ्या उपस्थितीचा चिन्ह करा", - "MARK_STUDENT_ATTENDANCE": "विद्यार्थी उपस्थितीचा चिन्ह करा", + "MARK_CENTER_ATTENDANCE": "केंद्र उपस्थिती चिन्हांकित करा", "LOADING": "लोड होत आहे", "SAVE": "साठवा", "CLEAR_ALL": "सर्व काढा", diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 53f06317..00ea4087 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -23,8 +23,7 @@ import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar'; import { attendanceInPercentageStatusList, attendanceStatusList, - bulkAttendance, - markAttendance, + bulkAttendance } from '../services/AttendanceService'; import { formatDate, @@ -92,7 +91,7 @@ const Dashboard: React.FC = () => { const [openMarkAttendance, setOpenMarkAttendance] = React.useState(false); const [openMarkUpdateAttendance, setOpenMarkUpdateAttendance] = React.useState(false); - const [cohortMemberList, setCohortMemberList] = React.useState>( + const [cohortMemberList, setCohortMemberList] = React.useState>( [] ); const [showDetails, setShowDetails] = React.useState(false); @@ -191,6 +190,7 @@ const Dashboard: React.FC = () => { //API for getting student list useEffect(() => { + submitBulkAttendanceAction(true, '', '') const getCohortMemberList = async () => { setLoading(true); // const parentCohortId = localStorage.getItem('parentCohortId'); @@ -274,16 +274,12 @@ const Dashboard: React.FC = () => { name: string; attendance: string; }[] = []; - - // Iterate over nameUserIdArray nameUserIdArray.forEach((user) => { const userId = user.userId; - // Find corresponding entry in userAttendanceArray const attendanceEntry = userAttendanceArray.find( (entry) => entry.userId === userId ); if (attendanceEntry) { - // If found, merge properties and push to newArray newArray.push({ userId, name: user.name, @@ -291,16 +287,18 @@ const Dashboard: React.FC = () => { }); } }); - // setCohortMemberList(newArray); //Getting issue updating attendance regardless of cohort id for mark all + if(newArray.length !=0){ + setCohortMemberList(newArray); + setNumberOfCohortMembers(newArray?.length); + }else{ + setCohortMemberList(nameUserIdArray); + setNumberOfCohortMembers(nameUserIdArray?.length); + } return newArray; }; mergeArrays(nameUserIdArray, userAttendanceArray); } } - - //Add logic to merge response2 and nameUserIdArray - setCohortMemberList(nameUserIdArray); //check where to set cohort member list - setNumberOfCohortMembers(nameUserIdArray?.length); setLoading(false); }; userAttendanceStatusList(); @@ -334,7 +332,7 @@ const Dashboard: React.FC = () => { if (classId.length) { getCohortMemberList(); } - }, [classId]); + }, [classId, selectedDate]); const showDetailsHandle = (dayStr: string) => { setSelectedDate(formatSelectedDate(dayStr)); @@ -638,9 +636,9 @@ const Dashboard: React.FC = () => { - {/* {loading && ( + {loading && ( - )} */} + )} = () => { fontSize={'16px'} sx={{ color: theme.palette.warning['A200'] }} > - {t('COMMON.MARK_STUDENT_ATTENDANCE')} + {t('COMMON.MARK_CENTER_ATTENDANCE')} = () => { - {/* {loading && ( + {loading && ( - )} */} + )} = () => { - {/* {loading && ( + {loading && ( - )} */} + )} {userType == 'Students' ? ( diff --git a/src/services/AttendanceService.ts b/src/services/AttendanceService.ts index 4f2f0b38..286d227e 100644 --- a/src/services/AttendanceService.ts +++ b/src/services/AttendanceService.ts @@ -9,26 +9,26 @@ import { AttendancePercentageProps, } from '../utils/Interfaces'; -export const markAttendance = async ({ - userId, - attendanceDate, - attendance, - contextId, -}: AttendanceParams): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/attendance`; - try { - const response = await post(apiUrl, { - userId, - attendanceDate, - attendance, - contextId, - }); - return response?.data; - } catch (error) { - console.error('error in marking attendance', error); - throw error; - } -}; +// export const markAttendance = async ({ +// userId, +// attendanceDate, +// attendance, +// contextId, +// }: AttendanceParams): Promise => { +// const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/attendance`; +// try { +// const response = await post(apiUrl, { +// userId, +// attendanceDate, +// attendance, +// contextId, +// }); +// return response?.data; +// } catch (error) { +// console.error('error in marking attendance', error); +// throw error; +// } +// }; export const bulkAttendance = async ({ attendanceDate, diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index e08e63c6..4bc488b1 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -81,3 +81,21 @@ export const truncateURL = ( } return url; }; + +// debounce function +export const debounce = any>( + func: T, + wait: number, + immediate?: boolean +) => { + let timeout: ReturnType | undefined; + return function (this: ThisParameterType, ...args: Parameters) { + const context = this; + clearTimeout(timeout!); + if (immediate && !timeout) func.apply(context, args); + timeout = setTimeout(() => { + timeout = undefined; + if (!immediate) func.apply(context, args); + }, wait); + }; +}; \ No newline at end of file