EquipmentTracker-Frontend/src/Components/Header/Header.tsx

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-19 16:10:36 +08:00
import { useEffect, useState } from "react";
2023-11-17 17:23:53 +08:00
import styles, { colors } from "../../styles";
2023-11-19 14:50:39 +08:00
import MenuIcon from "@mui/icons-material/Menu";
import SidebarModal from "../SidebarModal/SidebarModal";
import { Drawer } from "@mui/material";
2023-11-19 16:10:36 +08:00
import { useSelector } from "react-redux";
import { RootState } from "../Plugins/Redux/Store/Store";
import { useNavigate } from "react-router-dom";
2023-11-17 17:23:53 +08:00
export interface props {
2023-11-19 16:10:36 +08:00
label: string;
2023-11-17 17:23:53 +08:00
}
export default function Header(props: props) {
2023-11-19 14:50:39 +08:00
const [SidebarOpen, SetSidebarOpen] = useState(false);
2023-11-19 16:10:36 +08:00
const authenticated = useSelector((state: RootState) => state.auth.value);
const navigate = useNavigate();
useEffect(() => {
if (!authenticated) {
navigate("/");
console.log("Not logged in. Redirecting to landing page");
}
}, [authenticated, navigate]);
2023-11-17 17:23:53 +08:00
return (
<div
style={{
position: "sticky",
top: 0,
zIndex: -1,
backgroundColor: colors.header_color,
display: "flex",
2023-11-19 14:50:39 +08:00
flexDirection: "row",
2023-11-17 17:23:53 +08:00
}}
>
2023-11-19 14:50:39 +08:00
<div
style={{
flex: 1,
alignSelf: "center",
}}
>
<MenuIcon
style={{
height: "64px",
width: "64px",
float: "left",
marginLeft: "8px",
}}
onClick={() => {
SetSidebarOpen(true);
}}
/>
</div>
<p style={{ ...styles.text_light, ...styles.text_M, ...{ flex: 1 } }}>
{props.label}
</p>
<div style={{ flex: 1 }} />
<Drawer open={SidebarOpen} onClose={() => SetSidebarOpen(false)}>
<SidebarModal />
</Drawer>
2023-11-17 17:23:53 +08:00
</div>
);
}