Skip to content

Commit

Permalink
fix(attendance): fixes recording attendance bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aimedivin authored and Calebgisa72 committed Oct 8, 2024
1 parent 213831b commit 56744d0
Show file tree
Hide file tree
Showing 17 changed files with 1,398 additions and 1,076 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"jest": "^28.1.3",
"jest-axe": "^8.0.0",
"jest-environment-jsdom": "^28.1.3",
"jest-fetch-mock": "^3.0.3",
"jest-image-snapshot": "^6.1.0",
"lint-staged": "^13.2.3",
"mini-css-extract-plugin": "^2.7.6",
Expand Down
5 changes: 5 additions & 0 deletions src/Mutations/Attendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ export const RECORD_ATTENDANCE = gql`
id
name
cohort {
id
name
phase {
name
id
}
}
}
trainees {
Expand Down
20 changes: 20 additions & 0 deletions src/Mutations/teamMutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ export const GET_ALL_TEAMS = gql`
id
}
}
members {
id
email
status {
date
reason
status
}
profile {
firstName
lastName
city
country
phoneNumber
biography
avatar
id
name
}
}
}
}
`;
Expand Down
55 changes: 47 additions & 8 deletions src/components/ModalAttendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,41 @@ function ModalAttendance({
if (data) {
toast.success('Attendance recorded successfully.');
}
setAttendanceData((prev) => [...prev, data.recordAttendance]);

setAttendanceData((prev) => {
let isSet = false;
const result = prev.map((attendance) => {
if (
attendance.week.toString() === week.toString() &&
attendance.cohort.id === data.recordAttendance.team.cohort.id &&
attendance.phase.id === data.recordAttendance.team.cohort.phase.id
) {
isSet = true;
return {
...attendance,
teams: [data.recordAttendance],
};
}
return attendance;
});

if (!isSet && team === data.recordAttendance.team.id) {
result.push({
week: week.toString(),
id: Math.random().toString(),
cohort: {
id: data.recordAttendance.team.cohort.id,
name: data.recordAttendance.team.cohort.name,
},
phase: {
id: data.recordAttendance.team.cohort.phase.id,
name: data.recordAttendance.team.cohort.phase.name,
},
teams: [data.recordAttendance],
});
}
return result;
});
setTraineesAttendance([]);
setRecordTrainees([]);
onClose();
Expand All @@ -90,10 +124,12 @@ function ModalAttendance({
}, [recordTrainees]);

useEffect(() => {
const sanitizedTrainees = trainees.getTeamTrainees.filter(
(trainee: any) => trainee.status.status !== 'drop',
);
setAllTrainees(sanitizedTrainees);
if (trainees) {
const sanitizedTrainees = trainees.filter(
(trainee: any) => trainee.status.status !== 'drop',
);
setAllTrainees(sanitizedTrainees);
}
}, [trainees]);
useEffect(() => {
setFilteredTrainees(
Expand All @@ -113,11 +149,11 @@ function ModalAttendance({
) => {
let updatedAttendance;
const updateAttendance = traineesAttendance.find(
(attendance) => attendance.name.toLowerCase() === name.toLowerCase(),
(attendance) => attendance.id === id,
);
if (updateAttendance) {
updatedAttendance = traineesAttendance.map((attendance) => {
if (attendance.name.toLowerCase() === name.toLowerCase()) {
if (attendance.id === id) {
return { ...attendance, score };
}
return attendance;
Expand Down Expand Up @@ -171,7 +207,7 @@ function ModalAttendance({
</p>
<div className="w-full min-h-[40px] max-h-[110px] overflow-auto custom-scrollbar">
{traineesAttendance.length ? (
<div className="grid grid-cols-2 gap-1 xmd:gap-4 justify-between">
<div className="grid grid-cols-2 gap-1 xmd:gap-3 justify-between">
{traineesAttendance.map((trainee) => (
<div
key={trainee.id}
Expand Down Expand Up @@ -255,6 +291,7 @@ function ModalAttendance({
day,
);
}}
className="cursor-pointer hover:brightness-75"
data-testid="test-score-2"
>
<AttendanceSymbols status={2} />
Expand All @@ -269,6 +306,7 @@ function ModalAttendance({
day,
);
}}
className="cursor-pointer hover:brightness-75"
data-testid="test-score-1"
>
<AttendanceSymbols status={1} />
Expand All @@ -283,6 +321,7 @@ function ModalAttendance({
day,
);
}}
className="cursor-pointer hover:brightness-75"
data-testid="test-score-0"
>
<AttendanceSymbols status={0} />
Expand Down
Loading

0 comments on commit 56744d0

Please sign in to comment.