Skip to content

Commit

Permalink
Merge pull request #94 from Rushikesh-Sonawane99/shiksha-2.0
Browse files Browse the repository at this point in the history
Issue #000 chore: Fixed issue for cohort member list rendering
  • Loading branch information
itsvick authored May 10, 2024
2 parents d9594e3 + 046c7df commit 7e77b04
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 22 deletions.
85 changes: 68 additions & 17 deletions src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const Dashboard: React.FC<DashboardProps> = () => {
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({
Expand All @@ -185,33 +185,84 @@ const Dashboard: React.FC<DashboardProps> = () => {
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);
Expand Down
4 changes: 2 additions & 2 deletions src/services/AttendanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ export const getTeacherAttendanceByDate = async ({
export const attendanceStatusList = async ({
limit,
page,
filters: { contextId, scope },
filters: { fromDate, toDate },
}: AttendanceStatusListProps): Promise<any> => {
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) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface cohortListParam {
}

export interface cohortMemberList {
limit: string;
limit: number;
page: number;
filters: {
cohortId: string;
Expand Down Expand Up @@ -140,7 +140,7 @@ export interface AttendanceStatusListProps {
limit: number;
page: number;
filters: {
contextId: string;
scope: string;
fromDate: string;
toDate: string;
};
}

0 comments on commit 7e77b04

Please sign in to comment.