use fetchWrapper for getEventById.js
This commit is contained in:
1 parent
e9c8b7cda8
commit
4f184dd7c5
3 files changed
+7
-25
No files matched your search
@@ -9,7 +9,7 @@ const Task = ({ task }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const e = await getEventById(task.id);
|
const e = await getEventById(task.id);
|
||||||
setEvent(e);
|
setEvent(e.data);
|
||||||
}) ()
|
}) ()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export function EventDetailProvider({ children }) {
|
|||||||
|
|
||||||
const updateEventInfo = async (id) => {
|
const updateEventInfo = async (id) => {
|
||||||
const e = await getEventById(id);
|
const e = await getEventById(id);
|
||||||
setEventInfo(e);
|
setEventInfo(e.data);
|
||||||
setTasks(e.tasks)
|
setTasks(e.data.tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteTask = async (id, eventId) => {
|
const deleteTask = async (id, eventId) => {
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper.js";
|
||||||
|
|
||||||
export default async function GetEventById(id) {
|
export default async function GetEventById(id) {
|
||||||
|
return fetchWrapper(`/api/events/${id}`, null, "GET");
|
||||||
try {
|
}
|
||||||
const res = await fetch(`${import.meta.env.VITE_API_URL}/api/events/${id}`, {
|
|
||||||
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