Skip to content

Commit

Permalink
fix(schedules): some dates not showing on weekend meeting actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Sep 20, 2023
1 parent 83746a7 commit 0f8d781
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
19 changes: 17 additions & 2 deletions src/features/schedules/WeekendMeetingWeekSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ const WeekendMeetingWeekSelect = ({ actionType, open, setOpen }) => {
const schedules = useMemo(
() =>
Schedules.list
.filter((record) => record.weekOf >= '06/05/2023')
.filter((record) => {
const startDate = new Date(2023, 5, 6);
const tmp = record.weekOf.split('/');
const recordDate = new Date(tmp[2], +tmp[0] - 1, tmp[1]);

return recordDate >= startDate;
})
.sort((a, b) => {
const dateA = a.weekOf.split('/')[2] + '/' + a.weekOf.split('/')[0] + '/' + a.weekOf.split('/')[1];
const dateB = b.weekOf.split('/')[2] + '/' + b.weekOf.split('/')[0] + '/' + b.weekOf.split('/')[1];
Expand Down Expand Up @@ -98,7 +104,16 @@ const WeekendMeetingWeekSelect = ({ actionType, open, setOpen }) => {
}

if (startWeek !== '') {
setEndWeekOptions(schedules.filter((record) => record.weekOf >= startWeek));
setEndWeekOptions(
schedules.filter((record) => {
const tmpStart = startWeek.split('/');
const startDate = new Date(tmpStart[2], +tmpStart[0] - 1, tmpStart[1]);
const tmpEnd = record.weekOf.split('/');
const recordDate = new Date(tmpEnd[2], +tmpEnd[0] - 1, tmpEnd[1]);

return recordDate >= startDate;
})
);
}
}, [startWeek, schedules]);

Expand Down
25 changes: 10 additions & 15 deletions src/utils/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,17 @@ export const getPersonAutofillNoPartWithinMonth = (persons, week, assClass, assT

for (const person of persons) {
const assignments = Schedules.history.filter((record) => {
const tmpDate = new Date(
`${record.weekOf.split('/')[2]}/${record.weekOf.split('/')[0]}/${record.weekOf.split('/')[1]}`
);
const tmpArray = record.weekOf.split('/');
const tmpDate = new Date(`${tmpArray[2]}/${tmpArray('/')[0]}/${tmpArray('/')[1]}`);

return tmpDate > lastMonth && tmpDate < nextMonth && record.studentID === person.person_uid;
});

if (assignments.length === 0) {
if (assClass) {
const lastAssignment = Schedules.history.find((record) => {
const tmpDate = new Date(
`${record.weekOf.split('/')[2]}/${record.weekOf.split('/')[0]}/${record.weekOf.split('/')[1]}`
);
const tmpArray = record.weekOf.split('/');
const tmpDate = new Date(`${tmpArray[2]}/${tmpArray('/')[0]}/${tmpArray('/')[1]}`);

return tmpDate < currentDate && record.studentID === person.person_uid;
});
Expand Down Expand Up @@ -434,19 +432,17 @@ export const getPersonAutofillNoPartWithin2Weeks = (persons, week, assClass, ass

for (const person of persons) {
const assignments = Schedules.history.filter((record) => {
const tmpDate = new Date(
`${record.weekOf.split('/')[2]}/${record.weekOf.split('/')[0]}/${record.weekOf.split('/')[1]}`
);
const tmpArray = record.weekOf.split('/');
const tmpDate = new Date(`${tmpArray[2]}/${tmpArray('/')[0]}/${tmpArray('/')[1]}`);

return tmpDate > lastMonth && tmpDate < nextMonth && record.studentID === person.person_uid;
});

if (assignments.length === 0) {
if (assClass) {
const lastAssignment = Schedules.history.find((record) => {
const tmpDate = new Date(
`${record.weekOf.split('/')[2]}/${record.weekOf.split('/')[0]}/${record.weekOf.split('/')[1]}`
);
const tmpArray = record.weekOf.split('/');
const tmpDate = new Date(`${tmpArray[2]}/${tmpArray('/')[0]}/${tmpArray('/')[1]}`);

return tmpDate < currentDate && record.studentID === person.person_uid;
});
Expand Down Expand Up @@ -484,9 +480,8 @@ export const getPersonAutofillNoPartSameWeek = (persons, week, assClass, assType
if (assignments.length === 0) {
if (assClass) {
const lastAssignment = Schedules.history.find((record) => {
const tmpDate = new Date(
`${record.weekOf.split('/')[2]}/${record.weekOf.split('/')[0]}/${record.weekOf.split('/')[1]}`
);
const tmpArray = record.weekOf.split('/');
const tmpDate = new Date(`${tmpArray[2]}/${tmpArray('/')[0]}/${tmpArray('/')[1]}`);

return tmpDate < currentDate && record.studentID === person.person_uid;
});
Expand Down

0 comments on commit 0f8d781

Please sign in to comment.