update user listener to use native laravel notifications
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user