remove duplicated notification handling code
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
export const adminNotificationsListener = (echo, userData, setNotifications, setunreadNotification, updatePendingMembers) => {
|
||||
export const adminNotificationsListener = (echo, userData, setNotifications, setUnreadNotification, updatePendingMembers) => {
|
||||
if (userData.isAdmin) {
|
||||
const channelName = "users.admin";
|
||||
|
||||
const handleNotification = (content) => {
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
content,
|
||||
created_at: Date.now(),
|
||||
pivot: { unread: 1 }
|
||||
};
|
||||
setNotifications(prev => [newNotification, ...prev]);
|
||||
setUnreadNotification(true);
|
||||
};
|
||||
|
||||
echo.private(channelName)
|
||||
.listen(".users.registration", (event) => {
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
content: `Nouvelle demande d'inscription : ${event.user.name} ${event.user.lastname}`,
|
||||
created_at: Date.now(),
|
||||
pivot: { unread: 1 }
|
||||
};
|
||||
setNotifications(prev => [newNotification, ...prev]);
|
||||
setunreadNotification(true);
|
||||
handleNotification(`Nouvelle demande d'inscription : ${event.user.name} ${event.user.lastname}`);
|
||||
updatePendingMembers();
|
||||
});
|
||||
return channelName;
|
||||
|
||||
Reference in New Issue
Block a user