diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx index 03a1161..b8f3860 100644 --- a/src/components/Header/Header.jsx +++ b/src/components/Header/Header.jsx @@ -2,23 +2,25 @@ import styles from "./Header.module.css" import { Link, NavLink } from "react-router"; import { useEffect, useRef, useState } from "react"; import getUserNotifications from "../../utils/getUserNotifications.js"; +import getUser from "../../utils/getUser.js"; function Header() { const [notificationMenu, setnotificationMenu] = useState(false); const [unreadNotification, setunreadNotification] = useState(true); const [mobileMenu, setMobileMenu] = useState(false); - const [notifications, setNotifications] = useState([{"content" : "ok"}, {"content" : "pourquoi pas antoine"}]); + const [notifications, setNotifications] = useState([]); const notificationRef = useRef(null); useEffect(() => { async function loadNotifications() { - const notifData = await getUserNotifications(); + const user = await getUser(); + const notifData = await getUserNotifications(user.id); setNotifications(notifData || []); } - //loadNotifications(); + loadNotifications(); const handleClickOutside = (event) => { if ( notificationRef.current && diff --git a/src/utils/getUserNotifications.js b/src/utils/getUserNotifications.js index 1b93395..8f750ee 100644 --- a/src/utils/getUserNotifications.js +++ b/src/utils/getUserNotifications.js @@ -1,7 +1,7 @@ -export default async function getUserNotifications() { +export default async function getUserNotifications(id) { try { const response = await fetch( - 'http://localhost:80/api/users/1/notifications', + `http://${import.meta.env.VITE_API_URL}/api/users/${id}/notifications`, { method: 'GET', credentials: 'include',