diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index 213d83ab..73b3779e 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -174,7 +174,7 @@ const Dashboard: React.FC = () => { try { if (classId) { //userId && parentCohortId - let limit = '100'; + let limit = 100; let page = 0; let filters = { cohortId: classId }; //Hard coded for testing replace it with classId const response = await getMyCohortMemberList({ @@ -185,33 +185,84 @@ const Dashboard: React.FC = () => { const resp = response?.data?.userDetails; console.log(`classlist`, resp); - if (resp[0]?.userDetails) { - const nameUserIdArray = resp[0].userDetails.map( - ({ userId, name }: any) => ({ - userId, - name, + if (resp) { + const nameUserIdArray = resp?.map( + (entry: any) => ({ + "userId": entry.userId, + "name": entry.name }) ); - if (nameUserIdArray && contextId) { + console.log('name..........', nameUserIdArray) + if (nameUserIdArray && currentDate) { const userAttendanceStatusList = async () => { const attendanceStatusData: AttendanceStatusListProps = { - limit: 150, - page: 10, + limit: 200, + page: 1, filters: { - contextId: contextId, - scope: 'student', + fromDate: currentDate, + toDate: currentDate, }, }; - const response2 = + const res = await attendanceStatusList(attendanceStatusData); + const response = res?.data?.attendanceList; + console.log('attendanceStatusList', response); + if(nameUserIdArray && response){ + const getUserAttendanceStatus = ( + nameUserIdArray: any[], + response: any[] + ) => { + const userAttendanceArray: { + userId: any; + attendance: any; + }[] = []; + + nameUserIdArray.forEach((user) => { + const userId = user.userId; + const attendance = response.find( + (status) => status.userId === userId + ); + if (attendance) { + userAttendanceArray.push({ + userId, + attendance: attendance.attendance, + }); + } + }); + + return userAttendanceArray; + } + const userAttendanceArray = getUserAttendanceStatus( + nameUserIdArray, + response + ); + console.log('userAttendanceArray', userAttendanceArray); + if (nameUserIdArray && userAttendanceArray){ + const mergeArrays = (nameUserIdArray: {userId: string, + name: string}[], userAttendanceArray: {userId: string, + attendance: string}[]): {userId: string, + name: string, attendance: string}[] => { + const newArray: {userId: string, + name: string, attendance: string}[] = []; - if (response?.data?.length === 0) { - setAttendanceStatus(ATTENDANCE_ENUM.NOT_MARKED); - } else { - setAttendanceStatus(response2?.data?.[0]?.attendance); + // 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, attendance: attendanceEntry.attendance }); + } + }); + // setCohortMemberList(newArray); //Getting issue updating attendance regardless of cohort id for mark all + return newArray; + } + mergeArrays(nameUserIdArray, userAttendanceArray); + } } - //Add logic to merge response2 and nameUserIdArray + //Add logic to merge response2 and nameUserIdArray setCohortMemberList(nameUserIdArray); setNumberOfCohortMembers(nameUserIdArray?.length); setLoading(false); diff --git a/src/services/AttendanceService.ts b/src/services/AttendanceService.ts index 2115387d..70a0306f 100644 --- a/src/services/AttendanceService.ts +++ b/src/services/AttendanceService.ts @@ -72,14 +72,14 @@ export const getTeacherAttendanceByDate = async ({ export const attendanceStatusList = async ({ limit, page, - filters: { contextId, scope }, + filters: { fromDate, toDate }, }: AttendanceStatusListProps): Promise => { const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/attendance/list`; try { const response = await post(apiUrl, { limit, page, - filters: { contextId, scope }, + filters: { fromDate, toDate }, }); return response?.data; } catch (error) { diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 0c105956..9a9dcb8d 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -58,7 +58,7 @@ export interface cohortListParam { } export interface cohortMemberList { - limit: string; + limit: number; page: number; filters: { cohortId: string; @@ -140,7 +140,7 @@ export interface AttendanceStatusListProps { limit: number; page: number; filters: { - contextId: string; - scope: string; + fromDate: string; + toDate: string; }; }