use pendingMembers context
This commit is contained in:
@@ -10,6 +10,7 @@ import { userNotificationsListener } from "../../utils/echo/listeners/userNotifi
|
|||||||
import NotificationCard from "../NotificationCard/NotificationCard.jsx";
|
import NotificationCard from "../NotificationCard/NotificationCard.jsx";
|
||||||
import { EventContext } from "../../contexts/events/EventContext.js";
|
import { EventContext } from "../../contexts/events/EventContext.js";
|
||||||
import {AuthContext} from "../../contexts/auth/AuthContext.js";
|
import {AuthContext} from "../../contexts/auth/AuthContext.js";
|
||||||
|
import { PendingMembersContext } from "../../contexts/pendingMembers/PendingMembersContext";
|
||||||
|
|
||||||
function Header() {
|
function Header() {
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ function Header() {
|
|||||||
const [mobileMenu, setMobileMenu] = useState(false);
|
const [mobileMenu, setMobileMenu] = useState(false);
|
||||||
const [notifications, setNotifications] = useState([]);
|
const [notifications, setNotifications] = useState([]);
|
||||||
const notificationRef = useRef(null);
|
const notificationRef = useRef(null);
|
||||||
|
const { updatePendingMembers } = useContext(PendingMembersContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@ function Header() {
|
|||||||
echoInstance = echo;
|
echoInstance = echo;
|
||||||
|
|
||||||
const activeChannels = [
|
const activeChannels = [
|
||||||
userCreatedListener(echo, user, setNotifications, setunreadNotification),
|
userCreatedListener(echo, user, setNotifications, setunreadNotification, updatePendingMembers),
|
||||||
userNotificationsListener(echo, user, setNotifications, setunreadNotification),
|
userNotificationsListener(echo, user, setNotifications, setunreadNotification),
|
||||||
];
|
];
|
||||||
channelsToLeave = activeChannels.filter(name => name !== null);
|
channelsToLeave = activeChannels.filter(name => name !== null);
|
||||||
@@ -86,7 +88,7 @@ function Header() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erreur suppression notification :', err);
|
console.error('Erreur pour ouvrir/fermer le menu de notifications :', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import React, {useState, useEffect} from "react";
|
import React, {useState, useEffect, useContext} from "react";
|
||||||
import Button from "../../../../components/ui/button/button.tsx";
|
import Button from "../../../../components/ui/button/button.tsx";
|
||||||
import styles from "./PendingMembers.module.css";
|
import styles from "./PendingMembers.module.css";
|
||||||
import Modal from "../../../../components/ui/modal/modal.tsx";
|
import Modal from "../../../../components/ui/modal/modal.tsx";
|
||||||
import getUserToValidate from "../../../../utils/users/getUserToValidate.js";
|
|
||||||
import getUserById from "../../../../utils/users/getUserById.js";
|
|
||||||
import validateUser from "../../../../utils/users/validateUser.js";
|
import validateUser from "../../../../utils/users/validateUser.js";
|
||||||
import deleteOtherUser from "../../../../utils/users/deleteOtherUser.js";
|
import deleteOtherUser from "../../../../utils/users/deleteOtherUser.js";
|
||||||
|
import { PendingMembersContext } from "../../../../contexts/pendingMembers/PendingMembersContext";
|
||||||
|
|
||||||
function PendingMembers() {
|
function PendingMembers() {
|
||||||
|
|
||||||
@@ -13,23 +12,10 @@ function PendingMembers() {
|
|||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
|
const { pendingMembers, updatePendingMembers } = useContext(PendingMembersContext);
|
||||||
const [pendingMembers, setPendingMembers] = useState([]);
|
|
||||||
|
|
||||||
const fetchUsers = async () => {
|
|
||||||
|
|
||||||
const result = await getUserToValidate();
|
|
||||||
const userIds = result.data;
|
|
||||||
|
|
||||||
if (userIds && userIds.length > 0) {
|
|
||||||
const users = await Promise.all(userIds.map(id => getUserById(id)));
|
|
||||||
const usersData = users.map(u => u.data);
|
|
||||||
setPendingMembers(usersData);
|
|
||||||
} else setPendingMembers([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchUsers();
|
updatePendingMembers();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleValidate = async (id, name) => {
|
const handleValidate = async (id, name) => {
|
||||||
@@ -38,14 +24,12 @@ function PendingMembers() {
|
|||||||
if(result.status === 200) {
|
if(result.status === 200) {
|
||||||
setTitle("Utilisateur accepté avec succès")
|
setTitle("Utilisateur accepté avec succès")
|
||||||
setMessage(`L'utilisateur ${name} a été accepté avec succès`)
|
setMessage(`L'utilisateur ${name} a été accepté avec succès`)
|
||||||
setOpen(true);
|
|
||||||
} else {
|
} else {
|
||||||
setTitle("Erreur")
|
setTitle("Erreur")
|
||||||
setMessage(`Une erreur est survenue durant l'acceptation de l'utilisateur ${name}`)
|
setMessage(`Une erreur est survenue durant l'acceptation de l'utilisateur ${name}`)
|
||||||
setOpen(true);
|
|
||||||
}
|
}
|
||||||
|
setOpen(true);
|
||||||
fetchUsers();
|
updatePendingMembers();
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRefuse = async (id, name) => {
|
const handleRefuse = async (id, name) => {
|
||||||
@@ -61,7 +45,7 @@ function PendingMembers() {
|
|||||||
setOpen(true);
|
setOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchUsers();
|
updatePendingMembers();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const userCreatedListener = (echo, userData, setNotifications, setunreadNotification) => {
|
export const userCreatedListener = (echo, userData, setNotifications, setunreadNotification, updatePendingMembers) => {
|
||||||
if (userData.isAdmin) {
|
if (userData.isAdmin) {
|
||||||
const channelName = "users.registration";
|
const channelName = "users.registration";
|
||||||
echo.private(channelName)
|
echo.private(channelName)
|
||||||
@@ -11,6 +11,10 @@ export const userCreatedListener = (echo, userData, setNotifications, setunreadN
|
|||||||
};
|
};
|
||||||
setNotifications(prev => [newNotification, ...prev]);
|
setNotifications(prev => [newNotification, ...prev]);
|
||||||
setunreadNotification(true);
|
setunreadNotification(true);
|
||||||
|
|
||||||
|
if (typeof updatePendingMembers === "function") {
|
||||||
|
updatePendingMembers();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return channelName;
|
return channelName;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user