Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: export unpaginated event participant lists #787

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions src/operations/events/EventParticipantList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -27,6 +32,10 @@ import {
StatusActionStatus,
} from "./components";
import {useRole} from "@/security/hooks";
import {exportData} from "../utils";
Sarobidy-23 marked this conversation as resolved.
Show resolved Hide resolved
import {participantHeaders, participantMapper} from "./utils";
import {MAX_ITEM_PER_PAGE} from "@/providers/dataProvider";
import {eventsApi} from "@/providers/api";

export function EventParticipantList() {
const {eventId} = useParams();
Expand Down Expand Up @@ -74,6 +83,7 @@ export function EventParticipantList() {

const ListContent = ({eventId}: {eventId: string}) => {
const [participants, setParticipants] = useState([] as EventParticipant[]);
const [isExport, setIsExport] = useState(false);
const notify = useNotify();
const [show, _, toggle] = useToggle();
const [updateStatus, {isLoading: editStatus}] = useUpdate();
Expand Down Expand Up @@ -117,6 +127,21 @@ const ListContent = ({eventId}: {eventId: string}) => {
);
};

const exportParticipants = async () => {
setIsExport(true);
try {
const lists = (
await eventsApi().getEventParticipants(eventId, 1, MAX_ITEM_PER_PAGE)
).data;
exportData(
lists.map(participantMapper) || [],
participantHeaders,
"participants"
);
} catch (ignored) {}
setIsExport(false);
};

return (
<Stack>
<HaList
Expand All @@ -133,16 +158,32 @@ const ListContent = ({eventId}: {eventId: string}) => {
},
}}
hasDatagrid={false}
actions={
(isManager() || isAdmin()) && (
<ButtonBase
icon={<Add />}
label="Ajout groupe"
onClick={() => toggle()}
children={<></>}
/>
)
}
actions={(() => {
const actions = [
(isManager() || isAdmin()) && (
<ButtonBase
icon={<Add />}
label="Ajout groupe"
onClick={() => toggle()}
children={<></>}
/>
),
(isManager() || isAdmin() || isTeacher()) && (
<ButtonBase
closeAction={false}
icon={<UploadFileIcon />}
label="Export"
onClick={() => exportParticipants()}
children={isExport ? <Loader /> : <></>}
/>
),
];
return (
actions.some((action) => action) && (
<>{actions.map((action) => action)}</>
)
);
})()}
datagridProps={{
rowClick: false,
}}
Expand Down
25 changes: 25 additions & 0 deletions src/operations/events/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {EventParticipant} from "@haapi/typescript-client";

export const EVENT_TYPE_VALUE = {
COURSE: "Cours",
INTEGRATION: "Intégration",
Expand All @@ -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é",
];
Loading