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 (