From 5bd7ac195172a620090b89d3552c02c8d0d96253 Mon Sep 17 00:00:00 2001 From: Bilal Date: Fri, 5 Apr 2024 21:01:52 +0200 Subject: [PATCH] $ --- src/api/authentication.js | 1 - src/api/items.js | 6 +++ src/api/rooms.js | 10 ++++ src/components/NavBar/NavBar.jsx | 31 +++++++++++-- src/pages/profile/Profile.jsx | 5 +- src/pages/room/Room.jsx | 46 +++++++++++++++++-- src/pages/room/Room.scss | 11 +++++ src/pages/rooms/Rooms.jsx | 78 ++++++++++++++++++++++++++++---- src/pages/rooms/Rooms.scss | 33 ++++++++++++++ src/router.jsx | 2 +- src/services/pageManagement.js | 6 +++ 11 files changed, 206 insertions(+), 23 deletions(-) create mode 100644 src/services/pageManagement.js diff --git a/src/api/authentication.js b/src/api/authentication.js index 77cc1ae..4587110 100644 --- a/src/api/authentication.js +++ b/src/api/authentication.js @@ -18,7 +18,6 @@ export const login = async (username, password) => { return response.data; } catch (error) { - window.location.reload(); return error.response.data; } }; diff --git a/src/api/items.js b/src/api/items.js index de8a7bc..0f8ca38 100644 --- a/src/api/items.js +++ b/src/api/items.js @@ -35,6 +35,12 @@ export const updateItem = async (settings) => { formData.append("description", settings.description); formData.append("purchaseDate", settings.purchaseDate); formData.append("link", settings.link); + formData.append("invoice", settings.invoice); + + // je ne sais pas si ca va bug sans je verrai apres + if (settings.image) { + formData.append("image", settings.image); + } const response = await axios.put(`/item/${settings._id}`, formData); return response.data; diff --git a/src/api/rooms.js b/src/api/rooms.js index 159962e..266a25e 100644 --- a/src/api/rooms.js +++ b/src/api/rooms.js @@ -103,6 +103,16 @@ export const getRooms = async () => { } }; +export const getRoomsLength = async () => { + try { + const response = await getRooms(); + return response.length; + } catch (err) { + console.error(err); + return null; + } +}; + export const getRoom = async (id) => { try { const response = await axios.get(`/room/${id}`); diff --git a/src/components/NavBar/NavBar.jsx b/src/components/NavBar/NavBar.jsx index 6651f60..b9514b1 100644 --- a/src/components/NavBar/NavBar.jsx +++ b/src/components/NavBar/NavBar.jsx @@ -2,37 +2,60 @@ import { useAuth } from "../../hooks"; import "./NavBar.scss"; import { logout } from "../../api"; import { Link } from "react-router-dom/"; +import { getRoomsLength } from "../../api"; +import { useEffect } from "react"; +import { useState } from "react"; +import refresh from "../../services/pageManagement"; export default function NavBar() { const { user } = useAuth(); + const [roomsLength, setRoomsLength] = useState(null); const onLogout = () => { logout().then((res) => { if (res === "Ok") { - window.location.reload(); + refresh(); } }); }; + const refreshAllDatas = async () => { + const roomsLen = await getRoomsLength(); + if (!roomsLen) { + return; + } + setRoomsLength(roomsLen); + }; + + useEffect(() => { + refreshAllDatas(); + }, []); + return (