Skip to content

Commit

Permalink
Merge pull request #446 from NIAEFEUP/fix/admin-person-exchanges
Browse files Browse the repository at this point in the history
Fix/admin person exchanges
  • Loading branch information
tomaspalma authored Feb 7, 2025
2 parents d36987d + b321786 commit 4fb6f08
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
32 changes: 12 additions & 20 deletions src/components/admin/requests/cards/MultipleStudentExchangeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParticipantEntry, Array<DirectExchangeParticipant>>();
const map = new Map<string, Array<DirectExchangeParticipant>>();

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]);
}
})

Expand Down Expand Up @@ -100,15 +90,17 @@ export const MultipleStudentExchangeCard = ({

<CardContent className="w-full flex flex-col flex-wrap gap-y-4">
{open &&
Array.from(participantExchangesMap(exchange).entries()).map(([participant, exchanges]) => (
<PersonExchanges
key={"multiple-student-person-exchanges-" + participant.nmec}
Array.from(participantExchangesMap(exchange).entries()).map(([participant, exchanges]) => {
const nmec = participant.split(",")[0];
const name = participant.split(",")[1];
return <PersonExchanges
key={"multiple-student-person-exchanges-" + nmec}
exchanges={exchanges}
participant_name={participant.name}
participant_nmec={participant.nmec}
participant_name={name}
participant_nmec={nmec}
showTreatButton={true}
/>
))
})
}
</CardContent>

Expand Down
20 changes: 9 additions & 11 deletions src/components/exchange/enrollments/Enrollments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const Enrollments = ({

const [enrollCourses, setEnrollCourses] = useLocalStorage<CourseInfo[]>("enrollCourses", []);
const [enrollmentChoices, setEnrollmentChoices] = useState<Map<number, EnrollmentOption>>(new Map());
const [disenrollmentChoices, setDisenrollmentChoices] = useState<Map<number, EnrollmentOption>>(new Map());
const [coursesInfo, setCoursesInfo] = useState<CourseInfo[]>([]);
const { setMajors } = useContext(MajorContext);

Expand All @@ -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 (
<CourseContext.Provider value={{
Expand Down Expand Up @@ -108,8 +106,8 @@ export const Enrollments = ({
<AlreadyEnrolledCourseUnitCard
key={"already-enrolled-" + courseUnit.id}
courseUnit={courseUnit}
enrollmentChoices={enrollmentChoices}
setEnrollmentChoices={setEnrollmentChoices}
enrollmentChoices={disenrollmentChoices}
setEnrollmentChoices={setDisenrollmentChoices}
/>
))}
</div>
Expand All @@ -118,7 +116,7 @@ export const Enrollments = ({
<form onSubmit={async (e) => {
e.preventDefault();

const res = await courseUnitEnrollmentService.submitEnrollmentRequest(enrollmentChoices);
const res = await courseUnitEnrollmentService.submitEnrollmentRequest(new Map([...enrollmentChoices, ...disenrollmentChoices]));

if (res.ok) {
setExchangeSidebarStatus(ExchangeSidebarStatus.SHOWING_REQUESTS);
Expand Down
11 changes: 7 additions & 4 deletions src/components/exchange/requests/issue/PreviewRequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ const PreviewRequestForm = ({ requests, requestSubmitHandler, previewingFormHook
render={({ field }) => (
<FormItem className="w-full">
<FormControl>
<Textarea
{...field}
placeholder="Justifica a urgência do teu pedido de troca."
/>
<>
<Textarea
{...field}
placeholder="Justifica a urgência do teu pedido de troca. Irá ser enviado diretamente para a comissão de inscrição de turmas."
/>
<p className="text-sm font-bold">Se quiseres enviar ficheiros como comprovativo, podes enviar para a comissão de inscrição de turmas.</p>
</>
</FormControl>
<FormMessage />
</FormItem>
Expand Down

0 comments on commit 4fb6f08

Please sign in to comment.