Merge branch 'features/createTask' into 'dev'

Features/createtask

See merge request sae-but2/2025-26/gestion-benevoles-association/Frontend!62
This commit is contained in:
T'JAMPENS QUENTIN p2406187 committed 2026-01-13 22:39:08 +00:00
commit 12ea78a23a
6 files changed
+162 -5

No files matched your search

+103 -1
View File
@@ -9,6 +9,8 @@ import Modal from "../../components/ui/modal/modal.jsx";
import { AuthContext } from "../../contexts/auth/AuthContext.js"; import { AuthContext } from "../../contexts/auth/AuthContext.js";
import deleteEvent from "../../utils/events/deleteEvent.js"; import deleteEvent from "../../utils/events/deleteEvent.js";
import { useNavigate } from "react-router"; import { useNavigate } from "react-router";
import TextInput from "../../components/ui/input/input.jsx";
import createTaskApi from "../../utils/tasks/createTask.js";
function EventDetail() { function EventDetail() {
@@ -21,6 +23,14 @@ function EventDetail() {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [event, setEvent] = useState(null); const [event, setEvent] = useState(null);
const [openTaskModal, setOpenTaskModal] = useState(false);
const [taskName, setTaskName] = useState("");
const [taskDescription, setTaskDescription] = useState("");
const [taskLocation, setTaskLocation] = useState("");
const [maxParticipants, setMaxParticipants] = useState("");
const [startTime, setStartTime] = useState("");
const [endTime, setEndTime] = useState("");
useEffect(() => { useEffect(() => {
(async () => { (async () => {
@@ -42,6 +52,31 @@ function EventDetail() {
} }
} }
const createTask = async () => {
const success = await createTaskApi({
eventId: id,
name: taskName,
description: taskDescription,
start: startTime,
end: endTime,
location: taskLocation,
maxParticipants,
});
if (success) {
setOpenTaskModal(false);
setTaskName("");
setTaskDescription("");
setTaskLocation("");
setMaxParticipants("");
setStartTime("");
setEndTime("");
} else {
console.log("⚠️ Échec de la création de la task");
}
};
return ( return (
<div className={styles.allContent}> <div className={styles.allContent}>
<div className={`glassCard`}> <div className={`glassCard`}>
@@ -54,7 +89,10 @@ function EventDetail() {
<p>{event && formatDateLetter(event.start)}</p> <p>{event && formatDateLetter(event.start)}</p>
<p>{event?.description}</p> <p>{event?.description}</p>
</div> </div>
{user?.isAdmin && <Button variant={"danger"} className={styles.deleteEventBtn} onClick={handleDelete}>Supprimer</Button>} {user?.isAdmin && <div className={styles.manageEvent}>
<Button variant={"danger"} className={styles.manageBtn} onClick={handleDelete}>Supprimer</Button>
<Button variant={"default"} className={styles.manageBtn} onClick={() => setOpenTaskModal(true)}>Créer tâche</Button>
</div>}
</div> </div>
</div> </div>
</div> </div>
@@ -74,6 +112,70 @@ function EventDetail() {
<Button variant={"default"} onClick={delEvent}>Confirmer</Button> <Button variant={"default"} onClick={delEvent}>Confirmer</Button>
</div> </div>
</Modal> </Modal>
<Modal open={openTaskModal} onClose={() => setOpenTaskModal(false)} title={"Créer tâche"}>
<div className={styles.modalContent}>
<div>
<p>Nom de la tâche</p>
<TextInput
value={taskName}
onChange={(e) => setTaskName(e.target.value)}
placeholder="Nom de la tâche"
/>
</div>
<div>
<p>Description</p>
<TextInput
value={taskDescription}
onChange={(e) => setTaskDescription(e.target.value)}
placeholder="Description de la tâche"
/>
</div>
<div>
<p>Lieu</p>
<TextInput
value={taskLocation}
onChange={(e) => setTaskLocation(e.target.value)}
placeholder="Lieu"
/>
</div>
<div>
<p>Nombre maximum de participants</p>
<TextInput
type="number"
value={maxParticipants}
onChange={(e) => setMaxParticipants(e.target.value)}
placeholder="Participants max"
/>
</div>
<div>
<p>Heure de début</p>
<TextInput
type="datetime-local"
value={startTime}
onChange={(e) => setStartTime(e.target.value)}
/>
</div>
<div>
<p>Heure de fin</p>
<TextInput
type="datetime-local"
value={endTime}
onChange={(e) => setEndTime(e.target.value)}
/>
</div>
<Button variant="default" onClick={createTask}> Créer la tâche </Button>
</div>
</Modal>
</div> </div>
); );
} }
+7 -1
View File
@@ -52,7 +52,7 @@
justify-content: space-between; justify-content: space-between;
} }
.deleteEventBtn { .manageBtn {
height: fit-content; height: fit-content;
} }
@@ -61,4 +61,10 @@
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 24px; gap: 24px;
}
.manageEvent {
display: flex;
flex-direction: row;
gap: 10px;
} }
+49
View File
@@ -0,0 +1,49 @@
import getXSRFToken from "../getXSRF.js";
export default async function createTask({
eventId,
name,
description,
start,
end,
location,
maxParticipants,
}) {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(
`${import.meta.env.VITE_API_URL}/api/events/task`,
{
method: "POST",
credentials: "include",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-XSRF-TOKEN": csrfToken,
},
body: JSON.stringify({
event_id: eventId,
name,
description,
start,
end,
location,
max_participants: maxParticipants,
}),
}
);
if (!res.ok) {
const errorData = await res.json();
return false;
}
const data = await res.json();
return true;
} catch (err) {
console.log("❌ Erreur réseau :", err);
return false;
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ export default async function deleteUser(userId) {
const res = await fetch( const res = await fetch(
`http://${import.meta.env.VITE_API_URL}/api/users/${userId}`, `${import.meta.env.VITE_API_URL}/api/users/${userId}`,
{ {
method: "DELETE", method: "DELETE",
credentials: "include", credentials: "include",
+1 -1
View File
@@ -1,6 +1,6 @@
export default async function getUserToValidate() { export default async function getUserToValidate() {
try { try {
const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/invalid`, { const res = await fetch(`${import.meta.env.VITE_API_URL}/api/users/invalid`, {
method: 'GET', method: 'GET',
credentials: 'include', credentials: 'include',
headers: { headers: {
+1 -1
View File
@@ -4,7 +4,7 @@ export default async function validateUser(userId) {
const csrfToken = await getXSRFToken(); const csrfToken = await getXSRFToken();
try { try {
const res = await fetch( const res = await fetch(
`http://${import.meta.env.VITE_API_URL}/api/users/${userId}/validate`, `${import.meta.env.VITE_API_URL}/api/users/${userId}/validate`,
{ {
method: "POST", method: "POST",
credentials: "include", credentials: "include",