From 7f9f95ecc23be89cd8ef8a82cc945d2ac2653201 Mon Sep 17 00:00:00 2001 From: Simon Catanese Date: Thu, 4 Apr 2024 09:28:19 +0200 Subject: [PATCH] commit --- package-lock.json | 1 + package.json | 1 + src/App copy.jsx | 13 ------ src/App.jsx | 2 + src/api/room.js | 10 +++++ src/components/nav/Navbar.jsx | 83 +++++++++++++++++++++++++++++++++++ src/hooks/use-auth.js | 4 ++ 7 files changed, 101 insertions(+), 13 deletions(-) delete mode 100644 src/App copy.jsx create mode 100644 src/api/room.js create mode 100644 src/components/nav/Navbar.jsx diff --git a/package-lock.json b/package-lock.json index 41fe026..00d3eea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "react-router-dom": "^6.21.3" }, "devDependencies": { + "antd": "^5.15.4", "@playwright/test": "^1.42.1", "@testing-library/react": "^14.1.2", "@types/node": "^20.11.9", diff --git a/package.json b/package.json index cfc611a..e201860 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "react-router-dom": "^6.21.3" }, "devDependencies": { + "antd": "^5.15.4", "@playwright/test": "^1.42.1", "@testing-library/react": "^14.1.2", "@types/node": "^20.11.9", diff --git a/src/App copy.jsx b/src/App copy.jsx deleted file mode 100644 index 0a0016e..0000000 --- a/src/App copy.jsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from "react"; - -import { Authenticated } from "./components"; - -import { Router } from "./router"; - -const App = () => ( - - - -); - -export default App; diff --git a/src/App.jsx b/src/App.jsx index 0a0016e..ff2f13a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,10 +3,12 @@ import React from "react"; import { Authenticated } from "./components"; import { Router } from "./router"; +import Navbar from "./components/nav/Navbar"; const App = () => ( + ); diff --git a/src/api/room.js b/src/api/room.js new file mode 100644 index 0000000..2e10903 --- /dev/null +++ b/src/api/room.js @@ -0,0 +1,10 @@ +import axios from "axios"; + +export const getRoom = async () => { + try { + const response = await axios.get("/room", {}); + return response.data; + } catch (error) { + return error.response.data; + } +}; diff --git a/src/components/nav/Navbar.jsx b/src/components/nav/Navbar.jsx new file mode 100644 index 0000000..9fb8914 --- /dev/null +++ b/src/components/nav/Navbar.jsx @@ -0,0 +1,83 @@ +import React, { useState } from "react"; +import { Authenticated } from ".."; +import { Router } from "../../router"; + +import { + AppstoreOutlined, + ContainerOutlined, + DesktopOutlined, + MailOutlined, + MenuFoldOutlined, + MenuUnfoldOutlined, + PieChartOutlined, +} from "@ant-design/icons"; +import { Button, Menu } from "antd"; +import { Home } from "../../pages"; +import { getRoom } from "../../api/room"; +import { getAuth, useAuth } from "../../hooks"; +function getItem(label, key, icon, children, type) { + return { + key, + icon, + children, + label, + type, + }; +} + +// Component +const Navbar = () => { + //Hook calls + const [collapsed, setCollapsed] = useState(false); + const toggleCollapsed = () => { + setCollapsed(!collapsed); + }; + const [rooms, setRooms] = useState([]); + + useEffect(() => { + if (user) { + getRoom().then((result) => { + setRooms(result); + }); + } + }, []); + + const items = [ + getItem("Menu principal", "1", ), + getItem("Vue d'ensemble", "2", ), + getItem("Chambres", "3", , [ + rooms.forEach((room, i = 0) => { + i++; + getItem(room.name, `sub${i}`, ); + }), + ]), + ]; + + // Rendering + return ( +
+ + +
+ ); +}; +export default Navbar; diff --git a/src/hooks/use-auth.js b/src/hooks/use-auth.js index 5ef6e0f..aef1ae6 100644 --- a/src/hooks/use-auth.js +++ b/src/hooks/use-auth.js @@ -5,3 +5,7 @@ import { AuthenticationContext } from "../contexts"; export function useAuth() { return React.useContext(AuthenticationContext); } + +export function getAuth() { + return React.useContext(AuthenticationContext).user; +}