Merge branch 'features/export' into 'dev'

Features/export

See merge request sae-but2/2025-26/gestion-benevoles-association/Frontend!85
This commit is contained in:
ORDONNEAU ANTOINE p2405376
2026-03-06 08:29:26 +00:00
2 changed files with 33 additions and 12 deletions
+29 -12
View File
@@ -1,11 +1,14 @@
import {useState, useMemo, useEffect, useContext} from "react"; import {useState, useMemo, useEffect, useContext} from "react";
import styles from "./calendar.module.css"; import styles from "./calendar.module.css";
import { formatDateLetterJS } from "../../../../utils/date/formatDateLetter.js"; import {formatDateLetterJS} from "../../../../utils/date/formatDateLetter.js";
import {EventContext} from "../../../../contexts/events/EventContext.js"; import {EventContext} from "../../../../contexts/events/EventContext.js";
import Button from "../../../../components/ui/button/button.jsx";
import {AuthContext} from "../../../../contexts/auth/AuthContext.ts";
function Calendar() { function Calendar() {
const { events=[] } = useContext(EventContext); const { user } = useContext(AuthContext);
const monthNames = [ const monthNames = [
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
@@ -19,15 +22,15 @@ function Calendar() {
const [selectedDay, setSelectedDay] = useState(null); const [selectedDay, setSelectedDay] = useState(null);
const eventsByDate = useMemo(() => { const eventsByDate = useMemo(() => {
return events.reduce((acc, ev) => { if (!user?.tasks) return {};
if (!ev?.start) return acc; return user.tasks.reduce((acc, task) => {
if (!task?.start) return acc;
const dateKey = ev.start.split(" ")[0]; // YYYY-MM-DD const dateKey = task.start.split(" ")[0];
if (!acc[dateKey]) acc[dateKey] = []; if (!acc[dateKey]) acc[dateKey] = [];
acc[dateKey].push(ev); acc[dateKey].push(task);
return acc; return acc;
}, {}); }, {});
}, [events]); }, [user]);
useEffect(() => { useEffect(() => {
const key = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`; const key = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
@@ -72,12 +75,17 @@ function Calendar() {
<table className={styles.calendar}> <table className={styles.calendar}>
<thead> <thead>
<tr> <tr>
<th>Lun</th><th>Mar</th><th>Mer</th> <th>Lun</th>
<th>Jeu</th><th>Ven</th><th>Sam</th><th>Dim</th> <th>Mar</th>
<th>Mer</th>
<th>Jeu</th>
<th>Ven</th>
<th>Sam</th>
<th>Dim</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{Array.from({ length: Math.ceil(days.length / 7) }).map((_, w) => ( {Array.from({length: Math.ceil(days.length / 7)}).map((_, w) => (
<tr key={w}> <tr key={w}>
{days.slice(w * 7, w * 7 + 7).map((day, i) => { {days.slice(w * 7, w * 7 + 7).map((day, i) => {
if (!day) return <td key={i}></td>; if (!day) return <td key={i}></td>;
@@ -111,7 +119,7 @@ function Calendar() {
<ul> <ul>
{selectedDay.events.map(ev => ( {selectedDay.events.map(ev => (
<li key={ev.id}> <li key={ev.id}>
<strong>{ev.name}</strong><br /> <strong>{ev.name}</strong><br/>
{ev.description} {ev.description}
</li> </li>
))} ))}
@@ -121,6 +129,15 @@ function Calendar() {
)} )}
</div> </div>
)} )}
<Button className={styles.exportbtn}
variant={"primary"}
onClick={() => {
window.location.href =
`http://localhost/api/export/ics/${user.id}`;
}}
>
Exporter mon agenda
</Button>
</div> </div>
</div> </div>
); );
@@ -150,6 +150,10 @@
display: none; display: none;
} }
.exportbtn{
margin-top: 16px;
}
@media (max-width: 768px) { @media (max-width: 768px) {
.glassCard { .glassCard {
width: 100%; width: 100%;