use fetchWrapper for getAllEvents.js
This commit is contained in:
@@ -10,8 +10,8 @@ export function EventProvider({ children }) {
|
|||||||
const [events, setEvents] = useState([]);
|
const [events, setEvents] = useState([]);
|
||||||
|
|
||||||
const updateEvent = async () => {
|
const updateEvent = async () => {
|
||||||
const data = await getAllEvents();
|
const result = await getAllEvents();
|
||||||
setEvents(data.data);
|
setEvents(result.data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const addEvent = async (name, description, start, end) => {
|
const addEvent = async (name, description, start, end) => {
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper.js";
|
||||||
|
|
||||||
export default async function getAllEvents() {
|
export default async function getAllEvents() {
|
||||||
|
return fetchWrapper("/api/events/", null, "GET");
|
||||||
try {
|
}
|
||||||
const res = await fetch(`${import.meta.env.VITE_API_URL}/api/events/`, {
|
|
||||||
method: 'GET',
|
|
||||||
credentials: 'include',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(`Erreur serveur : ${res.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await res.json();
|
|
||||||
return data;
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Erreur :', err);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user