From 73414a86e450af61d8ee3ff850f934a3cb4ebd8f Mon Sep 17 00:00:00 2001 From: sarobidy-23 Date: Tue, 10 Dec 2024 14:13:29 +0300 Subject: [PATCH 1/2] chore: export unpaginated event participant lists --- .../events/EventParticipantList.tsx | 63 +++++++++++++++---- src/operations/events/utils.ts | 25 ++++++++ 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/operations/events/EventParticipantList.tsx b/src/operations/events/EventParticipantList.tsx index c0085d522..1a73f9f84 100644 --- a/src/operations/events/EventParticipantList.tsx +++ b/src/operations/events/EventParticipantList.tsx @@ -7,7 +7,12 @@ import { useRefresh, useUpdate, } from "react-admin"; -import {Event as EventIcon, Add, Save as SaveIcon} from "@mui/icons-material"; +import { + Event as EventIcon, + Add, + Save as SaveIcon, + UploadFile as UploadFileIcon, +} from "@mui/icons-material"; import {Box, Stack, Typography, Button} from "@mui/material"; import {HaList} from "@/ui/haList"; import {ButtonBase} from "@/ui/haToolbar"; @@ -27,6 +32,10 @@ import { StatusActionStatus, } from "./components"; import {useRole} from "@/security/hooks"; +import {exportData} from "../utils"; +import {participantHeaders, participantMapper} from "./utils"; +import {MAX_ITEM_PER_PAGE} from "@/providers/dataProvider"; +import {eventsApi} from "@/providers/api"; export function EventParticipantList() { const {eventId} = useParams(); @@ -74,6 +83,7 @@ export function EventParticipantList() { const ListContent = ({eventId}: {eventId: string}) => { const [participants, setParticipants] = useState([] as EventParticipant[]); + const [isExport, setExport] = useState(false); const notify = useNotify(); const [show, _, toggle] = useToggle(); const [updateStatus, {isLoading: editStatus}] = useUpdate(); @@ -117,6 +127,21 @@ const ListContent = ({eventId}: {eventId: string}) => { ); }; + const exportParticipants = async () => { + setExport(true); + try { + const lists = ( + await eventsApi().getEventParticipants(eventId, 1, MAX_ITEM_PER_PAGE) + ).data; + exportData( + lists.map(participantMapper) || [], + participantHeaders, + "participants" + ); + } catch (ignored) {} + setExport(false); + }; + return ( { }, }} hasDatagrid={false} - actions={ - (isManager() || isAdmin()) && ( - } - label="Ajout groupe" - onClick={() => toggle()} - children={<>} - /> - ) - } + actions={(() => { + const actions = [ + (isManager() || isAdmin()) && ( + } + label="Ajout groupe" + onClick={() => toggle()} + children={<>} + /> + ), + (isManager() || isAdmin() || isTeacher()) && ( + } + label="Export" + onClick={() => exportParticipants()} + children={isExport ? : <>} + /> + ), + ]; + return ( + actions.some((action) => action) && ( + <>{actions.map((action) => action)} + ) + ); + })()} datagridProps={{ rowClick: false, }} diff --git a/src/operations/events/utils.ts b/src/operations/events/utils.ts index 72cd08f9d..7b6acc71c 100644 --- a/src/operations/events/utils.ts +++ b/src/operations/events/utils.ts @@ -1,3 +1,5 @@ +import {EventParticipant} from "@haapi/typescript-client"; + export const EVENT_TYPE_VALUE = { COURSE: "Cours", INTEGRATION: "Intégration", @@ -17,3 +19,26 @@ export const ATTENDANCE_STATUS_COLOR = { LATE: "info", PRESENT: "success", }; + +export const participantMapper = (participant: EventParticipant) => ({ + "Réf": participant.ref, + "Prénom": participant.last_name, + "Nom": participant.first_name, + "Groupe": participant.group_name, + "Status": ATTENDANCE_STATUS_VALUE[participant.event_status!], + "A. Justifié": + participant.event_status === "MISSING" + ? participant.letter?.some((letter) => letter.status === "RECEIVED") + ? "Oui" + : "Non" + : "", +}); + +export const participantHeaders = [ + "Réf", + "Prénom", + "Nom", + "Groupe", + "Status", + "A. Justifé", +]; From 0099d1b9a7843e75302b0604180368c27cfff3ba Mon Sep 17 00:00:00 2001 From: sarobidy-23 Date: Tue, 10 Dec 2024 14:38:04 +0300 Subject: [PATCH 2/2] chore: isExport state name in event participant --- src/operations/events/EventParticipantList.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/operations/events/EventParticipantList.tsx b/src/operations/events/EventParticipantList.tsx index 1a73f9f84..9a7e7dc46 100644 --- a/src/operations/events/EventParticipantList.tsx +++ b/src/operations/events/EventParticipantList.tsx @@ -83,7 +83,7 @@ export function EventParticipantList() { const ListContent = ({eventId}: {eventId: string}) => { const [participants, setParticipants] = useState([] as EventParticipant[]); - const [isExport, setExport] = useState(false); + const [isExport, setIsExport] = useState(false); const notify = useNotify(); const [show, _, toggle] = useToggle(); const [updateStatus, {isLoading: editStatus}] = useUpdate(); @@ -128,7 +128,7 @@ const ListContent = ({eventId}: {eventId: string}) => { }; const exportParticipants = async () => { - setExport(true); + setIsExport(true); try { const lists = ( await eventsApi().getEventParticipants(eventId, 1, MAX_ITEM_PER_PAGE) @@ -139,7 +139,7 @@ const ListContent = ({eventId}: {eventId: string}) => { "participants" ); } catch (ignored) {} - setExport(false); + setIsExport(false); }; return (