From 371b38f3e799e606c458946147dd09cb6521e3bf Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sat, 28 Mar 2026 15:56:35 +0100 Subject: [PATCH] update user listener to use native laravel notifications --- .../listeners/userNotificationsListener.js | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/utils/echo/listeners/userNotificationsListener.js b/src/utils/echo/listeners/userNotificationsListener.js index f9ec96b..c23876a 100644 --- a/src/utils/echo/listeners/userNotificationsListener.js +++ b/src/utils/echo/listeners/userNotificationsListener.js @@ -1,37 +1,23 @@ -export const userNotificationsListener = (echo, userData, setNotifications, setUnreadNotification) => { +export const userNotificationsListener = (echo, userData, setNotifications, setUnreadNotification, updatePendingMembers) => { - const channelName = `user.${userData.id}`; + const channelName = `App.Models.User.${userData.id}`; - const handleNotification = (id, content) => { + echo.private(channelName) + .notification((notification) => { + const newNotification = { + id: notification.id, + content: notification.message, + created_at: new Date().toISOString(), + pivot: { unread: 1 } + }; - const newNotification = { - id, - content, - created_at: new Date().toISOString(), - pivot: { unread: 1 } - }; + setNotifications(prev => [newNotification, ...prev]); + setUnreadNotification(true); - setNotifications(prev => [newNotification, ...prev]); - setUnreadNotification(true); - }; - - return echo.private(channelName) - .listen('.event.participation.cancelled', (event) => { - handleNotification(event.notificationId,`L'événement ${event.event.name} a été supprimé. Vous n'y participez donc plus.`); - }) - .listen(`.task.participation.cancelled`, (event) => { - handleNotification(event.notificationId,`La tâche ${event.task.name} de l'événement ${event.event.name} a été supprimée. Vous n'y participez donc plus.`); - }) - .listen('.volunteer.assigned.to.task', (event) => { - handleNotification(event.notificationId,`Vous avez été assigné à la tâche ${event.task.name} de l'événement ${event.event.name}.`); - }) - .listen('.volunteer.unassigned.to.task', (event) => { - handleNotification(event.notificationId,`Vous avez été désassigné de la tâche ${event.task.name} de l'événement ${event.event.name}.`); - }) - .listen('.volunteer.role.updated', (event) => { - handleNotification(event.notificationId, `Votre rôle a changé pour : ${event.role} `); - }) - .listen('.task.date.updated', (event) => { - handleNotification(event.notificationId,`La date de la tâche ${event.task.name} de l'événement ${event.event.name} à été mis à jour. Cette tâche aura maintenant lieu du ${event.start} au ${event.end}.`); + if (notification.type === 'App\\Notifications\\UserRegistered' && updatePendingMembers) { + updatePendingMembers(); + } }); + + return channelName; }; \ No newline at end of file