Merge branch 'features/getUserNotifications' into 'dev'
add of getUserNotifications function See merge request sae-but2/2025-26/gestion-benevoles-association/Frontend!13
This commit is contained in:
commit
66e2019364
2 files changed
+31
-6
No files matched your search
@@ -1,20 +1,24 @@
|
|||||||
import styles from "./Header.module.css"
|
import styles from "./Header.module.css"
|
||||||
import { Link, NavLink } from "react-router";
|
import { Link, NavLink } from "react-router";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import getUserNotifications from "../../utils/getUserNotifications.js";
|
||||||
|
|
||||||
function Header() {
|
function Header() {
|
||||||
const [notificationMenu, setnotificationMenu] = useState(false);
|
const [notificationMenu, setnotificationMenu] = useState(false);
|
||||||
const [unreadNotification, setunreadNotification] = useState(true);
|
const [unreadNotification, setunreadNotification] = useState(true);
|
||||||
const [mobileMenu, setMobileMenu] = useState(false);
|
const [mobileMenu, setMobileMenu] = useState(false);
|
||||||
|
const [notifications, setNotifications] = useState([]);
|
||||||
const notificationRef = useRef(null);
|
const notificationRef = useRef(null);
|
||||||
|
|
||||||
const [notifications, setNotifications] = useState([
|
|
||||||
"Vous avez un nouveau message !",
|
|
||||||
"Jean Paul est en attente de validation !",
|
|
||||||
"Vous avez un nouveau message !"
|
|
||||||
]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
async function loadNotifications() {
|
||||||
|
const notifData = await getUserNotifications();
|
||||||
|
setNotifications(notifData || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadNotifications();
|
||||||
const handleClickOutside = (event) => {
|
const handleClickOutside = (event) => {
|
||||||
if (
|
if (
|
||||||
notificationRef.current &&
|
notificationRef.current &&
|
||||||
@@ -109,7 +113,7 @@ function Header() {
|
|||||||
) : (
|
) : (
|
||||||
notifications.map((notification, index) => (
|
notifications.map((notification, index) => (
|
||||||
<div className={styles.notification} key={index}>
|
<div className={styles.notification} key={index}>
|
||||||
<p>{notification}</p>
|
<p>{notification.content}</p>
|
||||||
<button
|
<button
|
||||||
className={styles.closeBtn}
|
className={styles.closeBtn}
|
||||||
onClick={() => setNotifications(prev => prev.filter((_, i) => i !== index))}
|
onClick={() => setNotifications(prev => prev.filter((_, i) => i !== index))}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export default async function getUserNotifications() {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
'http://localhost:8000/api/users/1/notifications',
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
return data.data;
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur :", err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user