multiplex user notifications over a single private channel
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
export const userNotificationsListener = (echo, userData, setNotifications, setunreadNotification) => {
|
||||
if (!userData?.id) return null;
|
||||
|
||||
const channelName = `user.${userData.id}`;
|
||||
|
||||
return echo.private(channelName)
|
||||
.listen('.event.participation.cancelled', (event) => {
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
content: `L'événement ${event.event.name} a été supprimé ! Vous n'y participez donc plus.`,
|
||||
pivot: { unread: 1 }
|
||||
};
|
||||
setNotifications(prev => [newNotification, ...prev]);
|
||||
setunreadNotification(true);
|
||||
})
|
||||
.listen(`.task.participation.cancelled`, (event) => {
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
content: `La tâche ${event.task.name} de l'événement ${event.event.name} a été supprimé ! Vous n'y participez donc plus.`,
|
||||
pivot: { unread: 1 }
|
||||
};
|
||||
setNotifications(prev => [newNotification, ...prev]);
|
||||
setunreadNotification(true);
|
||||
})
|
||||
.listen('.volunteer.assigned.to.task', (event) => {
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
content: `Vous avez été assigné à la tâche ${event.task.name} de l'événement ${event.event.name}`,
|
||||
pivot: { unread: 1 }
|
||||
};
|
||||
setNotifications(prev => [newNotification, ...prev]);
|
||||
setunreadNotification(true);
|
||||
})
|
||||
.listen('.volunteer.unassigned.to.task', (event) => {
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
content: `Vous avez été désassigné de la tâche ${event.task.name} de l'événement ${event.event.name}`,
|
||||
pivot: { unread: 1 }
|
||||
};
|
||||
setNotifications(prev => [newNotification, ...prev]);
|
||||
setunreadNotification(true);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user