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 committed Oct 7, 2024
1 parent 213831b commit f5b537c
Show file tree
Hide file tree
Showing 14 changed files with 1,285 additions and 1,047 deletions.
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
34 changes: 27 additions & 7 deletions src/components/ModalAttendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,22 @@ function ModalAttendance({
if (data) {
toast.success('Attendance recorded successfully.');
}
setAttendanceData((prev) => [...prev, data.recordAttendance]);

setAttendanceData((prev) =>
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
) {
return {
...attendance,
teams: [data.recordAttendance],
};
}
return attendance;
}),
);
setTraineesAttendance([]);
setRecordTrainees([]);
onClose();
Expand All @@ -90,10 +105,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 +130,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 @@ -255,6 +272,7 @@ function ModalAttendance({
day,
);
}}
className="cursor-pointer hover:brightness-75"
data-testid="test-score-2"
>
<AttendanceSymbols status={2} />
Expand All @@ -269,6 +287,7 @@ function ModalAttendance({
day,
);
}}
className="cursor-pointer hover:brightness-75"
data-testid="test-score-1"
>
<AttendanceSymbols status={1} />
Expand All @@ -283,6 +302,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 f5b537c

Please sign in to comment.