use fetchWrapper for getUserToValidate.js
This commit is contained in:
1 parent
c11bb849c5
commit
c43b411bac
2 files changed
+5
-20
No files matched your search
@@ -16,7 +16,8 @@ function PendingMembers() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPendingMembers = async () => {
|
const fetchPendingMembers = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const userIds = await getUserToValidate();
|
const result = await getUserToValidate();
|
||||||
|
const userIds = result.data
|
||||||
if (userIds && userIds.length > 0) {
|
if (userIds && userIds.length > 0) {
|
||||||
const users = await Promise.all(userIds.map((id) => getUserById(id)));
|
const users = await Promise.all(userIds.map((id) => getUserById(id)));
|
||||||
setPendingMembers(users.filter(Boolean));
|
setPendingMembers(users.filter(Boolean));
|
||||||
|
|||||||
@@ -1,21 +1,5 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper.js";
|
||||||
|
|
||||||
export default async function getUserToValidate() {
|
export default async function getUserToValidate() {
|
||||||
try {
|
return fetchWrapper("/api/users/invalid");
|
||||||
const res = await fetch(`${import.meta.env.VITE_API_URL}/api/users/invalid`, {
|
|
||||||
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