From 8fec4e577a60ba58a87320cef4b9a30ed2596e52 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 20 Jul 2024 13:03:26 +0200 Subject: [PATCH] Create Header component --- .../Dashboard/components/Header/Header.jsx | 53 +++++++++++++++++++ .../Dashboard/components/Header/index.js | 1 + 2 files changed, 54 insertions(+) create mode 100644 dashboard/src/states/Dashboard/components/Header/Header.jsx create mode 100644 dashboard/src/states/Dashboard/components/Header/index.js diff --git a/dashboard/src/states/Dashboard/components/Header/Header.jsx b/dashboard/src/states/Dashboard/components/Header/Header.jsx new file mode 100644 index 0000000..dce5977 --- /dev/null +++ b/dashboard/src/states/Dashboard/components/Header/Header.jsx @@ -0,0 +1,53 @@ +import {AppBar, Avatar, IconButton, Stack, Toolbar, Typography} from "@mui/material"; +import {Menu} from "@mui/icons-material"; +import {useContext, useEffect, useState} from "react"; +import {projectSidebar, sidebar} from "@/common/routes/index.jsx"; +import {useLocation} from "react-router-dom"; +import {ProjectContext} from "@/states/Dashboard/contexts/Project"; +import {UserContext} from "@contexts/User"; +import AccountMenu from "@/states/Dashboard/components/Header/components/AccountMenu"; + +const drawerWidth = 260; + +export const Header = ({toggleOpen}) => { + const location = useLocation(); + const {currentProject} = useContext(ProjectContext); + const {user} = useContext(UserContext); + + const [menuOpen, setMenuOpen] = useState(false); + + useEffect(() => { + document.title = "LicenseAPI - " + getTitleByPath(); + }, [location]); + + const getTitleByPath = () => { + const route = [...sidebar, ...projectSidebar].find((route) => location.pathname + .replace(currentProject?.id, ":projectId").startsWith(route.path) && route.path !== "/"); + if (route) return route.name; + return "Start"; + } + + return ( + <> + + + + + + + {getTitleByPath()} + + + setMenuOpen(true)} id="menu" + alignItems="center" direction="row" spacing={1}> + + + + + + + ) +} \ No newline at end of file diff --git a/dashboard/src/states/Dashboard/components/Header/index.js b/dashboard/src/states/Dashboard/components/Header/index.js new file mode 100644 index 0000000..eb54ef6 --- /dev/null +++ b/dashboard/src/states/Dashboard/components/Header/index.js @@ -0,0 +1 @@ +export {Header as default} from "./Header.jsx"; \ No newline at end of file