Notifications sur le site
{
- if (userData.isAdmin) {
- const channelName = "users.admin";
-
- const handleNotification = (id, content) => {
- const newNotification = {
- id,
- content,
- created_at: new Date().toISOString(),
- pivot: { unread: 1 }
- };
- setNotifications(prev => [newNotification, ...prev]);
- setUnreadNotification(true);
- };
-
- echo.private(channelName)
- .listen(".users.registration", (event) => {
- handleNotification(event.notificationId, `Nouvelle demande d'inscription : ${event.user.name} ${event.user.lastname}`);
- updatePendingMembers();
- });
- return channelName;
- }
- return null;
-};
\ No newline at end of file
diff --git a/src/utils/echo/listeners/userNotificationsListener.js b/src/utils/echo/listeners/userNotificationsListener.js
index f9ec96b..c518d7b 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,
+ data: { message: notification.message },
+ read_at: null,
+ created_at: new Date().toISOString(),
+ };
- 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
diff --git a/src/utils/events/updateEvent.ts b/src/utils/events/updateEvent.ts
new file mode 100644
index 0000000..a46b610
--- /dev/null
+++ b/src/utils/events/updateEvent.ts
@@ -0,0 +1,13 @@
+import fetchWrapper from "../fetchWrapper";
+import getXSRFToken from "../getXSRF";
+
+export default async function updateEvent(id: number, name: string, description: string, start: string, end: string) {
+ const csrfToken = await getXSRFToken();
+
+ return fetchWrapper(
+ `/api/events/${id}/update`,
+ { name, description, start, end },
+ "POST",
+ { "X-XSRF-TOKEN": csrfToken }
+ );
+}
diff --git a/src/utils/notifications/deleteNotificationUser.ts b/src/utils/notifications/deleteNotificationUser.ts
index 4322722..ce216e9 100644
--- a/src/utils/notifications/deleteNotificationUser.ts
+++ b/src/utils/notifications/deleteNotificationUser.ts
@@ -1,6 +1,6 @@
import getXSRFToken from "../getXSRF";
-export default async function deleteNotificationUser(notificationId:number) {
+export default async function deleteNotificationUser(notificationId:string) {
const csrfToken = await getXSRFToken();
try {
diff --git a/src/utils/tasks/updateTask.ts b/src/utils/tasks/updateTask.ts
new file mode 100644
index 0000000..ad18e82
--- /dev/null
+++ b/src/utils/tasks/updateTask.ts
@@ -0,0 +1,22 @@
+import fetchWrapper from "../fetchWrapper";
+import getXSRFToken from "../getXSRF";
+
+interface UpdateTaskParams {
+ name: string;
+ description: string;
+ start: string;
+ end: string;
+ location: string;
+ max_participants: number;
+}
+
+export default async function updateTask(id: number, params: UpdateTaskParams): Promise
{
+ const csrfToken = await getXSRFToken();
+
+ return fetchWrapper(
+ `/api/events/tasks/${id}/update`,
+ params,
+ "POST",
+ { "X-XSRF-TOKEN": csrfToken }
+ );
+}
diff --git a/src/utils/users/confirmEmailChange.ts b/src/utils/users/confirmEmailChange.ts
new file mode 100644
index 0000000..285cc72
--- /dev/null
+++ b/src/utils/users/confirmEmailChange.ts
@@ -0,0 +1,12 @@
+import fetchWrapper from "../fetchWrapper";
+import getXSRFToken from "../getXSRF";
+
+export default async function confirmEmailChange(token: string) {
+ const csrfToken = await getXSRFToken();
+ return fetchWrapper(
+ "/api/users/update/email/confirm",
+ { token },
+ "POST",
+ { "X-XSRF-TOKEN": csrfToken }
+ );
+}
\ No newline at end of file
diff --git a/src/utils/users/updateUserEmail.ts b/src/utils/users/updateUserEmail.ts
new file mode 100644
index 0000000..e61364e
--- /dev/null
+++ b/src/utils/users/updateUserEmail.ts
@@ -0,0 +1,12 @@
+import fetchWrapper from "../fetchWrapper";
+import getXSRFToken from "../getXSRF";
+
+export default async function updateUserEmail(email: string) {
+ const csrfToken = await getXSRFToken();
+ return fetchWrapper(
+ "/api/users/update/email/request",
+ { email },
+ "POST",
+ { "X-XSRF-TOKEN": csrfToken }
+ );
+}
\ No newline at end of file
diff --git a/src/utils/users/updateUserPassword.ts b/src/utils/users/updateUserPassword.ts
new file mode 100644
index 0000000..7d7ceb3
--- /dev/null
+++ b/src/utils/users/updateUserPassword.ts
@@ -0,0 +1,12 @@
+import fetchWrapper from "../fetchWrapper";
+import getXSRFToken from "../getXSRF";
+
+export default async function updateUserPassword(current_password: string, new_password: string, new_password_confirmation: string) {
+ const csrfToken = await getXSRFToken();
+ return fetchWrapper(
+ "/api/users/update/password",
+ { current_password, new_password, new_password_confirmation },
+ "POST",
+ { "X-XSRF-TOKEN": csrfToken }
+ );
+}
\ No newline at end of file