From 0fa99f0e19a9d2790be0b08004730a87c89c8292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Fri, 7 Feb 2025 02:50:51 +0000 Subject: [PATCH 1/2] fix: person exchanges now not duplicated and are correct --- .../cards/MultipleStudentExchangeCard.tsx | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/components/admin/requests/cards/MultipleStudentExchangeCard.tsx b/src/components/admin/requests/cards/MultipleStudentExchangeCard.tsx index 1b89e17a..a966fcc2 100644 --- a/src/components/admin/requests/cards/MultipleStudentExchangeCard.tsx +++ b/src/components/admin/requests/cards/MultipleStudentExchangeCard.tsx @@ -12,32 +12,22 @@ import { listEmailExchanges } from "../../../../utils/mail"; import { AdminRequestType } from "../../../../utils/exchange"; import { ValidateRequestButton } from "./ValidateRequestButton"; -export type ParticipantEntry = { - name: string, - nmec: string -} - type Props = { exchange: DirectExchangeRequest } const participantExchangesMap = (exchange: DirectExchangeRequest) => { const participants = exchange.options; - const map = new Map>(); + const map = new Map>(); participants.forEach((participant) => { - const existingEntry = map.get({ - "name": participant.participant_name, - "nmec": participant.participant_nmec - }); + const key = `${participant.participant_nmec},${participant.participant_name}`; + const existingEntry = map.get(key); if (existingEntry) { existingEntry.push(participant); } else { - map.set({ - "name": participant.participant_name, - "nmec": participant.participant_nmec - }, [participant]); + map.set(key, [participant]); } }) @@ -100,15 +90,17 @@ export const MultipleStudentExchangeCard = ({ {open && - Array.from(participantExchangesMap(exchange).entries()).map(([participant, exchanges]) => ( - { + const nmec = participant.split(",")[0]; + const name = participant.split(",")[1]; + return - )) + }) } From b321786d55d47272485a76045f18af620029305c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Fri, 7 Feb 2025 03:30:49 +0000 Subject: [PATCH 2/2] fix: enrollment is less buggy --- .../exchange/enrollments/Enrollments.tsx | 20 +++++++++---------- .../requests/issue/PreviewRequestForm.tsx | 11 ++++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/components/exchange/enrollments/Enrollments.tsx b/src/components/exchange/enrollments/Enrollments.tsx index 5582ece3..4e2d2330 100644 --- a/src/components/exchange/enrollments/Enrollments.tsx +++ b/src/components/exchange/enrollments/Enrollments.tsx @@ -34,6 +34,7 @@ export const Enrollments = ({ const [enrollCourses, setEnrollCourses] = useLocalStorage("enrollCourses", []); const [enrollmentChoices, setEnrollmentChoices] = useState>(new Map()); + const [disenrollmentChoices, setDisenrollmentChoices] = useState>(new Map()); const [coursesInfo, setCoursesInfo] = useState([]); const { setMajors } = useContext(MajorContext); @@ -48,18 +49,15 @@ export const Enrollments = ({ }, []) useEffect(() => { - if (!enrollCourses || enrollCourses.length === 0) return; + if (!enrollCourses) return; + const newEnrollmentChoices = new Map(); enrollCourses.forEach((course) => { - // if course is not in enrollmentChoices map, add it - if (!enrollmentChoices.has(course.id)) { - const newEnrollmentChoices = new Map(enrollmentChoices); - newEnrollmentChoices.set(course.id, { type: CourseUnitEnrollmentType.ENROLLING }); - setEnrollmentChoices(newEnrollmentChoices); - } + newEnrollmentChoices.set(course.id, { type: CourseUnitEnrollmentType.ENROLLING }); }); + setEnrollmentChoices(newEnrollmentChoices); - }, [enrollCourses, enrollmentChoices]); + }, [enrollCourses]); return ( ))} @@ -118,7 +116,7 @@ export const Enrollments = ({
{ e.preventDefault(); - const res = await courseUnitEnrollmentService.submitEnrollmentRequest(enrollmentChoices); + const res = await courseUnitEnrollmentService.submitEnrollmentRequest(new Map([...enrollmentChoices, ...disenrollmentChoices])); if (res.ok) { setExchangeSidebarStatus(ExchangeSidebarStatus.SHOWING_REQUESTS); diff --git a/src/components/exchange/requests/issue/PreviewRequestForm.tsx b/src/components/exchange/requests/issue/PreviewRequestForm.tsx index a6dfac03..739ac881 100644 --- a/src/components/exchange/requests/issue/PreviewRequestForm.tsx +++ b/src/components/exchange/requests/issue/PreviewRequestForm.tsx @@ -101,10 +101,13 @@ const PreviewRequestForm = ({ requests, requestSubmitHandler, previewingFormHook render={({ field }) => ( -