remove duplicated notification handling code
This commit is contained in:
@@ -1,46 +1,29 @@
|
|||||||
export const userNotificationsListener = (echo, userData, setNotifications, setunreadNotification) => {
|
export const userNotificationsListener = (echo, userData, setNotifications, setUnreadNotification) => {
|
||||||
|
|
||||||
const channelName = `user.${userData.id}`;
|
const channelName = `user.${userData.id}`;
|
||||||
|
|
||||||
|
const handleNotification = (content) => {
|
||||||
|
const newNotification = {
|
||||||
|
id: Date.now(),
|
||||||
|
content,
|
||||||
|
created_at: Date.now(),
|
||||||
|
pivot: { unread: 1 }
|
||||||
|
};
|
||||||
|
setNotifications(prev => [newNotification, ...prev]);
|
||||||
|
setUnreadNotification(true);
|
||||||
|
};
|
||||||
|
|
||||||
return echo.private(channelName)
|
return echo.private(channelName)
|
||||||
.listen('.event.participation.cancelled', (event) => {
|
.listen('.event.participation.cancelled', (event) => {
|
||||||
const newNotification = {
|
handleNotification(`L'événement ${event.event.name} a été supprimé ! Vous n'y participez donc plus.`);
|
||||||
id: Date.now(),
|
|
||||||
content: `L'événement ${event.event.name} a été supprimé ! Vous n'y participez donc plus.`,
|
|
||||||
created_at: Date.now(),
|
|
||||||
pivot: { unread: 1 }
|
|
||||||
};
|
|
||||||
setNotifications(prev => [newNotification, ...prev]);
|
|
||||||
setunreadNotification(true);
|
|
||||||
})
|
})
|
||||||
.listen(`.task.participation.cancelled`, (event) => {
|
.listen(`.task.participation.cancelled`, (event) => {
|
||||||
const newNotification = {
|
handleNotification(`La tâche ${event.task.name} de l'événement ${event.event.name} a été supprimée !`);
|
||||||
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.`,
|
|
||||||
created_at: Date.now(),
|
|
||||||
pivot: { unread: 1 }
|
|
||||||
};
|
|
||||||
setNotifications(prev => [newNotification, ...prev]);
|
|
||||||
setunreadNotification(true);
|
|
||||||
})
|
})
|
||||||
.listen('.volunteer.assigned.to.task', (event) => {
|
.listen('.volunteer.assigned.to.task', (event) => {
|
||||||
const newNotification = {
|
handleNotification(`Vous avez été assigné à la tâche ${event.task.name} de l'événement ${event.event.name}`);
|
||||||
id: Date.now(),
|
|
||||||
content: `Vous avez été assigné à la tâche ${event.task.name} de l'événement ${event.event.name}`,
|
|
||||||
created_at: Date.now(),
|
|
||||||
pivot: { unread: 1 }
|
|
||||||
};
|
|
||||||
setNotifications(prev => [newNotification, ...prev]);
|
|
||||||
setunreadNotification(true);
|
|
||||||
})
|
})
|
||||||
.listen('.volunteer.unassigned.to.task', (event) => {
|
.listen('.volunteer.unassigned.to.task', (event) => {
|
||||||
const newNotification = {
|
handleNotification(`Vous avez été désassigné de la tâche ${event.task.name} de l'événement ${event.event.name}`);
|
||||||
id: Date.now(),
|
|
||||||
content: `Vous avez été désassigné de la tâche ${event.task.name} de l'événement ${event.event.name}`,
|
|
||||||
created_at: Date.now(),
|
|
||||||
pivot: { unread: 1 }
|
|
||||||
};
|
|
||||||
setNotifications(prev => [newNotification, ...prev]);
|
|
||||||
setunreadNotification(true);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user