convert setting modals + associate function
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
/*export default async function fetchWrapper(path,data = null,method = "GET",headers = {}) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${import.meta.env.VITE_API_URL}${path}`,
|
||||
{
|
||||
method,
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
...headers,
|
||||
},
|
||||
body: data ? JSON.stringify(data) : null,
|
||||
}
|
||||
);
|
||||
|
||||
let responseData = null;
|
||||
|
||||
try {
|
||||
responseData = await res.json();
|
||||
} catch (_) {
|
||||
responseData = null;
|
||||
}
|
||||
|
||||
return {
|
||||
status: res.status,
|
||||
data: responseData,
|
||||
};
|
||||
|
||||
} catch (err) {
|
||||
console.error("❌ Erreur réseau :", err);
|
||||
|
||||
return {
|
||||
status: 0,
|
||||
data: {
|
||||
message: "Network error",
|
||||
},
|
||||
};
|
||||
}
|
||||
}*/
|
||||
|
||||
interface FetchResponse<T = any> {
|
||||
status: number;
|
||||
data: T | null;
|
||||
}
|
||||
|
||||
export default async function fetchWrapper(
|
||||
path: string,
|
||||
data: any = null,
|
||||
method: string = "GET",
|
||||
headers: Record<string, string> = {}
|
||||
): Promise<FetchResponse> {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${import.meta.env.VITE_API_URL}${path}`,
|
||||
{
|
||||
method,
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
...headers,
|
||||
},
|
||||
body: data ? JSON.stringify(data) : null,
|
||||
}
|
||||
);
|
||||
|
||||
let responseData = null;
|
||||
|
||||
try {
|
||||
responseData = await res.json();
|
||||
} catch (_) {
|
||||
responseData = null;
|
||||
}
|
||||
|
||||
return {
|
||||
status: res.status,
|
||||
data: responseData,
|
||||
};
|
||||
|
||||
} catch (err) {
|
||||
console.error("❌ Erreur réseau :", err);
|
||||
|
||||
return {
|
||||
status: 0,
|
||||
data: {
|
||||
message: "Network error",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user