resolve datetime conflict for notifications

This commit is contained in:
2026-03-19 16:58:21 +01:00
parent dbed114843
commit 72d2cfae27
5 changed files with 12 additions and 5 deletions
@@ -14,7 +14,7 @@ function NotificationCard({ notifications, deleteNotification }: NotificationCar
<div className={styles.notificationCard} key={index}>
<div className={styles.cardHeader}>
<span className={styles.timeTag}>
Le {formatDate(String(notification.created_at))} à {formatTime(String(notification.created_at))}
Le {formatDate(notification.created_at)} à {formatTime(notification.created_at)}
</span>
<button
className={styles.closeIconButton}
+3 -1
View File
@@ -1,4 +1,6 @@
export default function formatDate(d: string | Date): string {
export default function formatDate(d: string | Date | number | null | undefined): string {
if (!d) return "Date inconnue";
const date = d instanceof Date ? d : new Date(d);
const jj = String(date.getUTCDate()).padStart(2, "0");
+1 -1
View File
@@ -1,5 +1,5 @@
export default function formatTime(d: string | Date | null | undefined): string {
export default function formatTime(d: string | Date | number | null | undefined): string {
if (!d) return "Heure inconnue";
const date = d instanceof Date ? d : new Date(d);
@@ -6,7 +6,7 @@ export const adminNotificationsListener = (echo, userData, setNotifications, set
const newNotification = {
id: Date.now(),
content,
created_at: Date.now(),
created_at: new Date().toISOString(),
pivot: { unread: 1 }
};
setNotifications(prev => [newNotification, ...prev]);
@@ -3,12 +3,14 @@ export const userNotificationsListener = (echo, userData, setNotifications, setU
const channelName = `user.${userData.id}`;
const handleNotification = (content) => {
const newNotification = {
id: Date.now(),
content,
created_at: Date.now(),
created_at: new Date().toISOString(),
pivot: { unread: 1 }
};
setNotifications(prev => [newNotification, ...prev]);
setUnreadNotification(true);
};
@@ -25,5 +27,8 @@ export const userNotificationsListener = (echo, userData, setNotifications, setU
})
.listen('.volunteer.unassigned.to.task', (event) => {
handleNotification(`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(`Votre rôle a changé pour : ${event.role} !`);
});
};