update user listener to use native laravel notifications

This commit is contained in:
Giovanni committed 2026-03-28 15:56:35 +01:00
1 parent 6fcf45d4ff
commit 371b38f3e7
1 file changed
+11 -25
@@ -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 = { const newNotification = {
id, id: notification.id,
content, content: notification.message,
created_at: new Date().toISOString(), created_at: new Date().toISOString(),
pivot: { unread: 1 } pivot: { unread: 1 }
}; };
setNotifications(prev => [newNotification, ...prev]); setNotifications(prev => [newNotification, ...prev]);
setUnreadNotification(true); setUnreadNotification(true);
};
return echo.private(channelName) if (notification.type === 'App\\Notifications\\UserRegistered' && updatePendingMembers) {
.listen('.event.participation.cancelled', (event) => { updatePendingMembers();
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}.`);
}); });
return channelName;
}; };