From dbed1148439dd1df793f046f23f247daad831a04 Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Thu, 19 Mar 2026 16:42:09 +0100 Subject: [PATCH] remove duplicated notification handling code --- .../listeners/adminNotificationsListener.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/utils/echo/listeners/adminNotificationsListener.js b/src/utils/echo/listeners/adminNotificationsListener.js index d9cc07c..7617b49 100644 --- a/src/utils/echo/listeners/adminNotificationsListener.js +++ b/src/utils/echo/listeners/adminNotificationsListener.js @@ -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;