validate + delete user + last event + prototype chart

This commit is contained in:
p2405951
2026-01-13 11:49:11 +01:00
parent 263e7fea46
commit b0f0aec16e
7 changed files with 194 additions and 233 deletions
+28
View File
@@ -0,0 +1,28 @@
import { useEffect, useState } from "react";
import getAllEvents from "../../utils/events/getAllEvents";
function EventsCounter() {
const [eventsCount, setEventsCount] = useState(0);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchEvents = async () => {
try {
const events = await getAllEvents();
if (Array.isArray(events)) {
setEventsCount(events.length);
} else {
setEventsCount(0);
}
} catch (err) {
console.error(err);
setEventsCount(0);
} finally {
setLoading(false);
}
};
fetchEvents();
}, []);
if (loading) return <p>Chargement...</p>;
return <p>Nombre dévénements : {eventsCount}</p>;
}
export default EventsCounter;
+33 -12
View File
@@ -1,14 +1,35 @@
export default async function deleteUser(userId) {
const res = await fetch(
`http://${import.meta.env.VITE_API_URL}/api/users/${userId}`,
{
method: "DELETE",
credentials: "include",
headers: {
Accept: "application/json",
},
}
);
import getXSRFToken from "../getXSRF";
return res.ok;
export default async function deleteUser(userId) {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(
`http://${import.meta.env.VITE_API_URL}/api/users/${userId}`,
{
method: "DELETE",
credentials: "include",
headers: {
Accept: "application/json",
"X-XSRF-TOKEN": csrfToken,
},
}
);
if (!res.ok) {
let message = "Erreur backend";
try {
const errorData = await res.json();
message = errorData.message || message;
} catch {}
return { success: false, message };
}
return { success: true };
} catch (err) {
console.error(err);
return { success: false, message: "Erreur réseau" };
}
}
-14
View File
@@ -1,14 +0,0 @@
export default async function validateUser(userId) {
const res = await fetch(
`http://${import.meta.env.VITE_API_URL}/api/users/${userId}/validate`,
{
method: "POST",
credentials: "include",
headers: {
Accept: "application/json",
},
}
);
return res.ok;
}
+27
View File
@@ -0,0 +1,27 @@
import getXSRFToken from "../getXSRF.js";
export default async function validateUser(userId) {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(
`http://${import.meta.env.VITE_API_URL}/api/users/${userId}/validate`,
{
method: "POST",
credentials: "include",
headers: {
Accept: "application/json",
'X-XSRF-TOKEN': csrfToken,
},
}
);
if (!res.ok) {
const errorData = await res.json();
console.error("Erreur backend:", errorData);
return false;
}
return true;
} catch (err) {
console.error("Erreur réseau:", err);
return false;
}
}