Skip to content

Commit

Permalink
Issue #0000 fixes:dashboard event list issue fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
suvarnakale committed Sep 25, 2024
1 parent f7ef613 commit d945a2b
Showing 1 changed file with 95 additions and 88 deletions.
183 changes: 95 additions & 88 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ const Dashboard: React.FC<DashboardProps> = () => {
after: afterDate,
before: beforeDate,
},
cohortId: classId,
// cohortId: classId,
createdBy: userId,
status: ['live'],
};
const response = await getEventList({ limit, offset, filters });
Expand All @@ -675,27 +676,32 @@ const Dashboard: React.FC<DashboardProps> = () => {
// });

const sessionArray: any[] = [];
const extraSessionArray: any[] = [];
if (response?.events.length > 0) {
response?.events.forEach((event: any) => {
console.log('myCohortList', myCohortList);
let cohortList;
if (myCohortList.length > 0) {
if (myCohortList[0].type === cohortHierarchy.BLOCK) {
cohortList = myCohortList[0].childData;
} else {
cohortList = myCohortList;
}
}

const cohort = cohortList?.find(
(cohort: any) => cohort?.cohortId === event?.metadata?.cohortId
);
if (cohort && event.isRecurring) {
// console.log('myCohortList', myCohortList);
// let cohortList;
// if (myCohortList.length > 0) {
// if (myCohortList[0].type === cohortHierarchy.BLOCK) {
// cohortList = myCohortList[0].childData;
// } else {
// cohortList = myCohortList;
// }
// }

// const cohort = cohortList?.find(
// (cohort: any) => cohort?.cohortId === event?.metadata?.cohortId
// );
if (event.isRecurring) {
sessionArray.push(event);
}
if (!event.isRecurring) {
extraSessionArray.push(event);
}
});
}
setSessions(sessionArray);
setExtraSessions(extraSessionArray);
setEventUpdated(false);
setEventDeleted(false);
} catch (error) {
Expand All @@ -715,80 +721,81 @@ const Dashboard: React.FC<DashboardProps> = () => {
eventDeleted,
]);

useEffect(() => {
const getExtraSessionsData = async () => {
try {
const date = new Date();
const startDate = shortDateFormat(new Date());
const lastDate = new Date(
date.setDate(date.getDate() + modifyAttendanceLimit)
);
const endDate = shortDateFormat(lastDate);
const afterDate = getAfterDate(timeTableDate);
const beforeDate = getBeforeDate(timeTableDate);
const limit = 0;
const offset = 0;
const filters = {
startDate: {
after: afterDate,
},
endDate: {
before: beforeDate,
},
cohortId: classId,
status: ['live'],
};
const response = await getEventList({ limit, offset, filters });

// check if cohort's membership is active

// const myCohortList = await queryClient.fetchQuery({
// queryKey: [QueryKeys.MY_COHORTS, userId],
// queryFn: () => getCohortList(userId as string, { filter: 'true' }),
// });

const extraSessionArray: any[] = [];
if (response?.events.length > 0) {
response?.events.forEach((event: any) => {
console.log('myCohortList', myCohortList);

let cohortList;
if (myCohortList.length > 0) {
if (myCohortList[0].type === cohortHierarchy.BLOCK) {
cohortList = myCohortList[0].childData;
} else {
cohortList = myCohortList;
}
}

const cohort = cohortList?.find(
(cohort: any) => cohort?.cohortId === event?.metadata?.cohortId
);

if (cohort && !event.isRecurring) {
extraSessionArray.push(event);
}
});
}
setExtraSessions(extraSessionArray);
setEventUpdated(false);
setEventDeleted(false);
} catch (error) {
setExtraSessions([]);
}
};
// useEffect(() => {
// const getExtraSessionsData = async () => {
// try {
// const date = new Date();
// const startDate = shortDateFormat(new Date());
// const lastDate = new Date(
// date.setDate(date.getDate() + modifyAttendanceLimit)
// );
// const endDate = shortDateFormat(lastDate);
// const afterDate = getAfterDate(timeTableDate);
// const beforeDate = getBeforeDate(timeTableDate);
// const limit = 0;
// const offset = 0;
// const filters = {
// startDate: {
// after: afterDate,
// },
// endDate: {
// before: beforeDate,
// },
// createdBy: userId,
// // cohortId: classId,
// status: ['live'],
// };
// const response = await getEventList({ limit, offset, filters });

// // check if cohort's membership is active

// // const myCohortList = await queryClient.fetchQuery({
// // queryKey: [QueryKeys.MY_COHORTS, userId],
// // queryFn: () => getCohortList(userId as string, { filter: 'true' }),
// // });

// const extraSessionArray: any[] = [];
// if (response?.events.length > 0) {
// response?.events.forEach((event: any) => {
// console.log('myCohortList', myCohortList);

// // let cohortList;
// // if (myCohortList.length > 0) {
// // if (myCohortList[0].type === cohortHierarchy.BLOCK) {
// // cohortList = myCohortList[0].childData;
// // } else {
// // cohortList = myCohortList;
// // }
// // }

// // const cohort = cohortList?.find(
// // (cohort: any) => cohort?.cohortId === event?.metadata?.cohortId
// // );

// if (!event.isRecurring) {
// extraSessionArray.push(event);
// }
// });
// }
// setExtraSessions(extraSessionArray);
// setEventUpdated(false);
// setEventDeleted(false);
// } catch (error) {
// setExtraSessions([]);
// }
// };

if (userId && myCohortList) {
getExtraSessionsData();
}
}, [
timeTableDate,
userId,
myCohortList,
classId,
eventUpdated,
eventDeleted,
]);
// if (userId && myCohortList) {
// getExtraSessionsData();
// }
// }, [
// timeTableDate,
// userId,
// myCohortList,
// classId,
// eventUpdated,
// eventDeleted,
// ]);

const handleEventDeleted = () => {
setEventDeleted(true);
Expand Down

0 comments on commit d945a2b

Please sign in to comment.