Merge branch 'dev' into 'features/linkEventsPage'

# Conflicts:
#   src/pages/Profile/ProfilePage.jsx
This commit is contained in:
T'JAMPENS QUENTIN p2406187
2026-01-12 14:55:23 +00:00
46 changed files with 515 additions and 111 deletions
+13 -8
View File
@@ -1,4 +1,5 @@
import styles from "./Filter.module.css";
import Button from "../ui/button/button.jsx"
function Filter({isFilterVisible, filters, setFilters}){
const setAlphabeticalOrder = (order) => {
@@ -18,31 +19,35 @@ function Filter({isFilterVisible, filters, setFilters}){
return (
<div className={`${styles.filterContainer} ${isFilterVisible ? styles.filterOpen : styles.filterClose}`}>
<abbr title="Tri alphabétique croissant (A à Z)">
<button className={`${styles.filterTag} glassCard ${filters.alphabetical !== "asc" ? "" : styles.active}`}
<Button className={`${styles.filterTag} glassCard ${filters.alphabetical !== "asc" ? "" : styles.active}`}
variant={"default"}
onClick={() => setAlphabeticalOrder("asc")}>
<img src={"sortByAlpha.svg"} alt="Tri alphabétique croissant (A à Z)"/>
</button>
</Button>
</abbr>
<abbr title="Tri alphabétique décroissant (Z à A)">
<button className={`${styles.filterTag} glassCard ${filters.alphabetical !== "desc" ? "" : styles.active}`}
<Button className={`${styles.filterTag} glassCard ${filters.alphabetical !== "desc" ? "" : styles.active}`}
variant={"default"}
onClick={() => setAlphabeticalOrder("desc")}>
<img src={"sortByAntiAlpha.svg"} alt="Tri alphabétique décroissant (Z à A)"/>
</button>
</Button>
</abbr>
<abbr title="Tri chronologique décroissant (du plus récent au plus ancien)">
<button className={`${styles.filterTag} glassCard ${filters.yearOrder !== "desc" ? "" : styles.active}`}
<Button className={`${styles.filterTag} glassCard ${filters.yearOrder !== "desc" ? "" : styles.active}`}
variant={"default"}
onClick={() => setYearOrder("desc")}>
<img src={"timerArrowUp.svg"} alt="Tri chronologique décroissant (du plus récent au plus ancien)"/>
</button>
</Button>
</abbr>
<abbr title="Tri chronologique croissant (du plus ancien au plus récent)">
<button className={`${styles.filterTag} glassCard ${filters.yearOrder !== "asc" ? "" : styles.active}`}
<Button className={`${styles.filterTag} glassCard ${filters.yearOrder !== "asc" ? "" : styles.active}`}
variant={"default"}
onClick={() => setYearOrder("asc")}>
<img src={"timerArrowDown.svg"} alt="Tri chronologique croissant (du plus ancien au plus récent)"/>
</button>
</Button>
</abbr>
</div>
)
+83 -26
View File
@@ -1,26 +1,59 @@
import styles from "./Header.module.css"
import { Link, NavLink } from "react-router";
import {useContext, useEffect, useRef, useState} from "react";
import getUserNotifications from "../../utils/getUserNotifications.js";
import {AuthContext} from "../../contexts/auth/AuthContext.js";
import styles from "./Header.module.css"
import getUserNotifications from "../../utils/notifications/getUserNotifications.js";
import deleteNotificationUser from "../../utils/notifications/deleteNotificationUser.js";
import initEcho from "../../utils/echo/initEcho.js"
import readNotifications from "../../utils/notifications/readNotifications.js";
import getUser from "../../utils/getUser.js";
import { userCreatedListener } from "../../utils/echo/listeners/userCreatedListener";
import { userNotificationsListener } from "../../utils/echo/listeners/userNotificationsListener.js";
import NotificationCard from "../NotificationCard/NotificationCard.jsx";
function Header() {
const { update, user } = useContext(AuthContext);
const [notificationMenu, setnotificationMenu] = useState(false);
const [unreadNotification, setunreadNotification] = useState(true);
const [unreadNotification, setunreadNotification] = useState(false);
const [mobileMenu, setMobileMenu] = useState(false);
const [notifications, setNotifications] = useState([{"content" : "ok"}, {"content" : "pourquoi pas antoine"}]);
const [notifications, setNotifications] = useState([]);
const notificationRef = useRef(null);
const { user } = useContext(AuthContext);
useEffect(() => {
async function loadNotifications() {
const notifData = await getUserNotifications();
setNotifications(notifData || []);
let echoInstance = null;
let channelsToLeave = [];
async function initializeHeader() {
try {
const [userData, notifData] = await Promise.all([
getUser(),
getUserNotifications()
]);
const data = notifData || [];
setNotifications(data);
const hasUnread = data.some(n => n.pivot && n.pivot.unread === 1);
setunreadNotification(hasUnread);
const echo = initEcho();
echoInstance = echo;
const activeChannels = [
userCreatedListener(echo, userData, setNotifications, setunreadNotification),
userNotificationsListener(echo, userData, setNotifications, setunreadNotification),
];
channelsToLeave = activeChannels.filter(name => name !== null);
} catch (err) {
console.error("Erreur initialisation Header:", err);
}
}
//loadNotifications();
initializeHeader();
const handleClickOutside = (event) => {
if (
notificationRef.current &&
@@ -32,11 +65,48 @@ function Header() {
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
if (echoInstance) {
channelsToLeave.forEach(chan => echoInstance.leave(chan));
}
};
}, []);
const toggleNotificationMenu = async () => {
try {
setnotificationMenu(!notificationMenu);
if (unreadNotification) {
const result = await readNotifications();
if (result) {
setunreadNotification(false);
update();
}
}
} catch (err) {
console.error('Erreur suppression notification :', err);
}
}
async function deleteNotification(notificationId) {
try {
const result = await deleteNotificationUser(notificationId);
if (result) {
setNotifications(prev => prev.filter(n => n.id !== notificationId));
update();
}
} catch (err) {
console.error('Erreur suppression notification :', err);
}
}
return (
<div className={styles.headerContainer}>
<header className={`${styles.header} glassCard`}>
@@ -66,10 +136,7 @@ function Header() {
<div className={styles.headerRightContent}>
<button
className={`${styles.bellBtn} ${notificationMenu ? styles.activeBellBtn : ""}`}
onClick={() => {
setnotificationMenu(!notificationMenu);
setunreadNotification(false);
}}
onClick={() => {toggleNotificationMenu();}}
>
<img className={styles.notificationsImg} src="/bell.svg" alt="notifications"/>
{unreadNotification && <span className={styles.notificationBadge}></span>}
@@ -119,17 +186,7 @@ function Header() {
{notifications.length === 0 ? (
<p className={styles.notification}>Vous n'avez aucune notification !</p>
) : (
notifications.map((notification, index) => (
<div className={styles.notification} key={index}>
<p>{notification.content}</p>
<button
className={styles.closeBtn}
onClick={() => setNotifications(prev => prev.filter((_, i) => i !== index))}
>
<img src="/close.svg" alt="supprimer la notification"/>
</button>
</div>
))
<NotificationCard notifications={notifications} deleteNotification={deleteNotification} />
)}
</div>
</div>
+4 -11
View File
@@ -150,13 +150,16 @@
.notificationDiv {
position: absolute;
width: 250px;
width: 300px;
top: 105%;
right: 2rem;
opacity: 0;
transform: translateY(-10px);
transition: opacity 0.3s ease, transform 0.3s ease;
z-index: 0;
max-height: 60vh;
overflow: scroll;
scrollbar-width: none;
}
.activeNotificationDiv {
@@ -183,16 +186,6 @@
border-radius: 50%;
}
.closeBtn {
display: flex;
align-items: center;
justify-content: center;
border: none;
cursor: pointer;
background: none;
margin: 0;
width: fit-content;
}
.closeBtn:focus {
outline: none;
@@ -37,17 +37,13 @@ display: none;
min-height: 250px;
max-height: 250px;
overflow-y: auto;
padding: 10px;
text-align: center;
padding-bottom: 200px;
padding: 10px 10px 200px 10px;
box-sizing: border-box;
opacity: 0;
transform: translateX(20px);
animation: slideInEvent 1s ease forwards;
flex-shrink: 1;
padding: 10px;
text-align: center;
box-sizing: border-box;
}
.eventCard:nth-child(1) {
@@ -99,7 +95,6 @@ display: none;
min-width: 100%;
min-height: 200px;
max-height: fit-content;
padding-bottom: 0px;
}
.eventCard h3 {
@@ -114,7 +109,7 @@ display: none;
margin-top: 15px;
height: fit-content;
overflow-y: auto;
padding-bottom: 0px;
padding-bottom: 0;
scroll-behavior: smooth;
}
@@ -0,0 +1,34 @@
import formatDate from "../../utils/date/formatDate.js";
import formatTime from "../../utils/date/formatTime.js";
import styles from "./NotificationCard.module.css"
function NotificationCard({notifications, deleteNotification}) {
return (
notifications.map((notification, index) => (
<div className={styles.notificationCard} key={index}>
<div className={styles.cardHeader}>
<span className={styles.timeTag}>
Le {formatDate(notification.created_at)} à {formatTime(notification.created_at)}
</span>
<button
className={styles.closeIconButton}
onClick={() => deleteNotification(notification.id)}
title="Supprimer"
>
</button>
</div>
<div className={styles.cardContent}>
<p className={styles.message}>
{notification.content}
</p>
</div>
</div>
))
);
}
export default NotificationCard;
@@ -0,0 +1,44 @@
.notificationCard {
padding: 1.25rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
transition: background 0.2s ease;
}
.cardHeader {
display: flex;
justify-content: space-between;
align-items: center;
}
.timeTag {
color: #019AFF;
letter-spacing: 0.2px;
}
.message {
margin: 0;
font-size: 1.1rem;
line-height: 1.5;
color: #2c3e50;
font-weight: 400;
}
.closeIconButton {
background: none;
border: none;
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
font-size: 1.1rem;
color: #2c3e50;
}
.closeIconButton:hover {
color: #cc0000;
}
+2 -2
View File
@@ -1,8 +1,8 @@
import styles from "./SearchBar.module.css"
import {Link} from "react-router";
import {useEffect, useState} from "react";
import searchEvents from "../../utils/searchEvents.js";
import searchUsers from "../../utils/searchUsers.js";
import searchEvents from "../../utils/events/searchEvents.js";
import searchUsers from "../../utils/users/searchUsers.js";
import { useLocation } from "react-router";
+1 -1
View File
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react";
import getEventById from "../../utils/event/getEventById.js";
import getEventById from "../../utils/events/getEventById.js";
import styles from "./Task.module.css";
import formatDate from "../../utils/date/formatDate.js";
+5 -4
View File
@@ -3,6 +3,7 @@ import Filter from "../Filter/Filter.jsx";
import {useEffect, useState} from "react";
import SearchBar from "../SearchBar/SearchBar.jsx";
import CreateEventBtn from "../createEventBtn/CreateEventBtn.jsx";
import Button from "../ui/button/button.jsx";
function ToolBar({setFilters, filters, showCreate = true}) {
@@ -40,14 +41,14 @@ function ToolBar({setFilters, filters, showCreate = true}) {
<CreateEventBtn />
) : null}
<button className={`${styles.searchButton} glassCard`} onClick={() => setIsSearchVisible(true)}>
<Button className={`${styles.searchButton} glassCard`} variant={"default"} onClick={() => setIsSearchVisible(true)}>
<img src="search.svg" alt="Rechercher"/>
</button>
</Button>
<div className={`${styles.filterContainer} ${isFilterVisible ? "glassCard" : ""}`}>
<button className={`${isFilterVisible ? "" : styles.mobileFilter} ${styles.sortButton} glassCard`} onClick={toggleFilters}>
<Button className={`${isFilterVisible ? "" : styles.mobileFilter} ${styles.sortButton} glassCard`} variant={"default"} onClick={toggleFilters}>
<img src="filter.svg" alt="Filtrer"/>
</button>
</Button>
<div className={styles.filterMenu}>
<Filter isFilterVisible={isFilterVisible} filters={filters} setFilters={setFilters}/>
</div>
@@ -1,4 +1,3 @@
/* BACKGROUND ////////////////////////////////////////////////////////*/
.backgroundContainer {
z-index: 0;
margin: 0;
+3 -3
View File
@@ -6,9 +6,9 @@ import styles from "./ParticipationChart.module.css";
Chart.register(ArcElement);
function participationChart() {
function ParticipationChart() {
const [selected, setSelected] = useState("3");
const [participationRate, setParticipationRate] = useState(78);
const [participationRate] = useState(78);
const chartData = {
labels: ["Progress", "Background"],
@@ -87,4 +87,4 @@ function participationChart() {
);
}
export default participationChart;
export default ParticipationChart;
@@ -4,7 +4,6 @@
flex-direction: column;
align-items: center;
height: calc(100vh - 260px);
/* Exemple: calc(100vh - 60px) */
margin-bottom: auto;
}
@@ -3,7 +3,7 @@ import { useState } from "react";
import Modal from "../ui/modal/modal.jsx";
import Button from "../ui/button/button.jsx";
import TextInput from "../ui/input/input.jsx";
import createEvent from "../../utils/event/createEvent.js"
import createEvent from "../../utils/events/createEvent.js"
export default function CreateEventBtn() {
+1 -1
View File
@@ -12,7 +12,7 @@ function Calendar({ events = [] }) {
const today = new Date();
const [currentMonth, setCurrentMonth] = useState(today.getMonth());
const [currentYear, setCurrentYear] = useState(today.getFullYear());
const [currentYear] = useState(today.getFullYear());
const [selectedDay, setSelectedDay] = useState(null);
const eventsByDate = useMemo(() => {
+11 -2
View File
@@ -106,7 +106,6 @@
.eventBox {
width: 100%;
border-radius: 20px;
padding: 15px;
margin-top: 16px;
}
@@ -131,10 +130,20 @@
.glassCard {
width: 45%;
max-height: 100%;
margin: 16px 0px 16px 0px;
margin: 16px 0 16px 0;
padding: 10px 20px 10px 20px;
height: fit-content;
background: rgba(255, 255, 255, 0.65);
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.3);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.5),
inset 0 -1px 0 rgba(255, 255, 255, 0.1),
inset 0 0 8px 4px rgba(255, 255, 255, 0.4);
overflow: scroll;
}
.glassCard::-webkit-scrollbar{
+12 -2
View File
@@ -1,10 +1,20 @@
.glassCard {
width: 45%;
max-height: 100%;
margin: 16px 0px 16px 0px;
margin: 16px 0 16px 0;
padding: 10px 20px 10px 20px;
height: fit-content;
background: rgba(255, 255, 255, 0.65);
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.3);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.5),
inset 0 -1px 0 rgba(255, 255, 255, 0.1),
inset 0 0 8px 4px rgba(255, 255, 255, 0.4);
overflow: scroll;
}
.glassCard::-webkit-scrollbar{
@@ -40,7 +50,7 @@ h2{
}
.eventGroup{
margin: 16px 0px 16px 0px;
margin: 16px 0 16px 0;
padding: 10px 20px 10px 20px;
}
@@ -5,7 +5,7 @@
input {
width: 100%;
height: 60px;
padding: 0px 10px;
padding: 0 10px;
border: none;
border-radius: 10px;
font-size: 19px;
@@ -33,9 +33,9 @@ input::placeholder{
.inputContainer {
padding: 15px;
width: 100%;
}
/* style scoped (module) */
.loginButton {
display: inline-block;
height: 50px;
+1 -1
View File
@@ -68,7 +68,7 @@ body {
.glassBorder{
border-radius: 20px;
border: none;
background: rgba(255, 255, 255, 0.5);
background: rgb(255, 255, 255, 0.25);
box-shadow:
inset 1.25px 1.25px 1px rgba(255, 255, 255, 1),
inset -1.25px -1.25px 1px rgba(255, 255, 255, 1),
+3 -3
View File
@@ -9,11 +9,11 @@ import { AuthContext } from "./contexts/auth/AuthContext.js";
function Layout(){
/*const { user, loading } = useContext(AuthContext);
const { user, loading } = useContext(AuthContext);
if (loading) return <p>Loading</p>;
if (loading) return <p>Loading</p>;
if (!user) return <Navigate to="/login" />;
if(user && user.validate === 0) return <Navigate to="/error/validation" />;*/
if(user && user.validate === 0) return <Navigate to="/error/validation" />;
return (
<div>
+16 -16
View File
@@ -12,24 +12,24 @@ function AdminPage() {
const { user } = useContext(AuthContext);
const navigate = useNavigate();
const [selected, setSelected] = useState("3");
const [participationRate, setParticipationRate] = useState(89);
const [selected, setSelected] = useState("3");
const [participationRate] = useState(89);
/*if(!user.isAdmin) navigate("/");*/
if(!user.isAdmin) navigate("/");
return (
<div className={styles.container}>
<ParticipationChart
selected={selected}
setSelected={setSelected}
participationRate={participationRate}
/>
<div className={styles.rightSection}>
<IncompleteEvents />
<PendingMembers />
</div>
</div>
);
return (
<div className={styles.container}>
<ParticipationChart
selected={selected}
setSelected={setSelected}
participationRate={participationRate}
/>
<div className={styles.rightSection}>
<IncompleteEvents />
<PendingMembers />
</div>
</div>
);
}
export default AdminPage;
+1 -1
View File
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import Event from "../../components/Event/Event.jsx";
import styles from "./EventsPage.module.css";
import ToolBar from "../../components/ToolBar/ToolBar.jsx";
import getAllEvents from "../../utils/event/getAllEvents.js";
import getAllEvents from "../../utils/events/getAllEvents.js";
import filter from "../../utils/filter.js";
+1 -1
View File
@@ -2,7 +2,7 @@ import styles from "./HomePage.module.css";
import Calendar from "../../components/homePage/calendar.jsx";
import EventList from "../../components/homePage/eventList.jsx";
import { useState, useEffect } from "react";
import getAllEvents from "../../utils/event/getAllEvents.js";
import getAllEvents from "../../utils/events/getAllEvents.js";
function HomePage() {
+1 -1
View File
@@ -9,6 +9,6 @@
.allContent{
display: flex;
flex-direction: column;
gap: 0px;
gap: 0;
}
}
+6 -1
View File
@@ -10,11 +10,16 @@ function LoginPage() {
const { user, loading } = useContext(AuthContext)
const navigate = useNavigate();
useEffect(() => {
console.log("loading" + loading);
console.log("user" + user);
if (!loading && user) {
navigate("/");
}
}, [loading, user]);
}, [loading, navigate, user]);
return (
<Background>
+2 -2
View File
@@ -25,11 +25,11 @@ function ProfilePage() {
<h2> {user?.name} {user?.lastname} </h2>
</div>
<div className={styles.topDescription}>
<div className={styles.infoBlock}>
<div className={`${styles.infoBlock} glassBorder`}>
<p><strong>Role :</strong> {user?.role}</p>
<p><strong>Membre depuis :</strong> {user && formatDate(user.created_at)}</p>
</div>
<div className={styles.infoBlock}>
<div className={`${styles.infoBlock} glassBorder`}>
<p><strong>Mail :</strong> {user?.email} </p>
<p><strong>Téléphone :</strong> {user?.phone === null ? "Pas de numéro enregistré" : user?.phone}</p>
</div>
-3
View File
@@ -47,9 +47,7 @@
.infoBlock {
width: 100%;
background: rgba(255, 255, 255, 0.1);
padding: 10px;
border-radius: 5px;
}
.eventTasks {
@@ -131,7 +129,6 @@
margin-bottom: 20px;
}
/* Desktop (1024px et plus) */
@media screen and (min-width: 1024px) {
.container {
max-width: 100%;
+1 -1
View File
@@ -117,7 +117,7 @@ function RegisterPage() {
<div className={styles.logButton}>
<Button variant={"transparent"} onClick={() => navigate("/login")}>Vous avez déjà un compte ?</Button>
<Button variant={"default"} onClick={handleSubmit}> Se connecter </Button>
<Button variant={"default"} onClick={handleSubmit}> Créer le compte </Button>
</div>
</div>
</div>
@@ -40,4 +40,5 @@ h1 {
.inputContainer {
padding: 15px;
width: 100%;
}
@@ -131,7 +131,6 @@
margin-bottom: 20px;
}
/* Desktop (1024px et plus) */
@media screen and (min-width: 1024px) {
.container {
max-width: 100%;
+8
View File
@@ -0,0 +1,8 @@
export default function formatTime(d) {
const date = new Date(d);
const hh = String(date.getUTCHours()).padStart(2, '0');
const min = String(date.getUTCMinutes()).padStart(2, '0');
return `${hh}:${min}`;
}
+21
View File
@@ -0,0 +1,21 @@
import Echo from "laravel-echo";
import Pusher from "pusher-js";
window.Pusher = Pusher;
export default function initEcho() {
const echoInstance = new Echo({
broadcaster: import.meta.env.VITE_BROADCASTER,
key: import.meta.env.VITE_REVERB_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: Number(import.meta.env.VITE_REVERB_PORT),
forceTLS: import.meta.env.VITE_FORCE_TLS === 'true',
disableStats: import.meta.env.VITE_DISABLE_STATS === 'true',
encrypted: import.meta.env.VITE_ENCRYPTED === 'true',
cluster: import.meta.env.VITE_CLUSTER,
enabledTransports: ['ws', 'wss'],
});
window.Echo = echoInstance;
return echoInstance;
}
@@ -0,0 +1,18 @@
export const userCreatedListener = (echo, userData, setNotifications, setunreadNotification) => {
if (userData.isAdmin || userData.role === "Gérant") {
const channelName = "users.registration";
echo.private(channelName)
.listen(".users.registration", (event) => {
const newNotification = {
id: Date.now(),
content: `Nouvelle demande d'inscription : ${event.user.name} ${event.user.lastname}`,
created_at: Date.now(),
pivot: { unread: 1 }
};
setNotifications(prev => [newNotification, ...prev]);
setunreadNotification(true);
});
return channelName;
}
return null;
};
@@ -0,0 +1,47 @@
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.`,
created_at: Date.now(),
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.`,
created_at: Date.now(),
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}`,
created_at: Date.now(),
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}`,
created_at: Date.now(),
pivot: { unread: 1 }
};
setNotifications(prev => [newNotification, ...prev]);
setunreadNotification(true);
});
};
+2 -2
View File
@@ -4,9 +4,9 @@ function filter(elements, filters, type) {
const dB = new Date(dateB);
if (filters.yearOrder === "asc") {
return dA - dB; // plus ancien -> plus récent
return dA - dB;
} else {
return dB - dA; // plus récent -> plus ancien
return dB - dA;
}
};
@@ -0,0 +1,26 @@
import getXSRFToken from "../getXSRF.js";
export default async function deleteNotificationUser(notificationId) {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/delete/notification/${notificationId}`, {
method: 'DELETE',
credentials: 'include',
headers: {
'Accept': 'application/json',
'X-XSRF-TOKEN': csrfToken
}
});
if (!res.ok) {
throw new Error(`Erreur serveur : ${res.status}`);
}
const data = await res.json();
return data;
} catch (err) {
console.error('Erreur :', err);
return null;
}
}
@@ -1,7 +1,7 @@
export default async function getUserNotifications() {
try {
const response = await fetch(
'http://localhost:80/api/users/1/notifications',
`http://${import.meta.env.VITE_API_URL}/api/users/notifications`,
{
method: 'GET',
credentials: 'include',
@@ -0,0 +1,27 @@
import getXSRFToken from "../getXSRF.js";
export default async function readNotifications() {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/notifications/read`, {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json',
'X-XSRF-TOKEN': csrfToken,
'Content-Type': 'application/json',
},
});
if (!res.ok) {
throw new Error(`Erreur serveur : ${res.status}`);
}
return await res.json();
} catch (err) {
console.error('Erreur :', err);
return null;
}
}