Create task btn

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2026-01-13 23:30:04 +01:00
parent 4600879c6e
commit 4688cd1757
3 changed files with 159 additions and 2 deletions
+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;
}
}