From 503a24a24bef161c0b0f9f08a5ea41c23924753e Mon Sep 17 00:00:00 2001 From: jdrskr Date: Fri, 1 Dec 2023 17:39:47 +0100 Subject: [PATCH] feat: add navigation. --- frontend/src/App.tsx | 17 ++- frontend/src/components/Layout.tsx | 37 ++++++ frontend/src/components/NavigationBar.tsx | 109 ++++++++++++++++++ frontend/src/pages/client/pages/IssuePage.tsx | 2 - 4 files changed, 157 insertions(+), 8 deletions(-) create mode 100644 frontend/src/components/Layout.tsx create mode 100644 frontend/src/components/NavigationBar.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0e5210a..70fc7c3 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -15,6 +15,8 @@ import { AuthContextProvider } from "./context/AuthContext"; import { ApiContextProvider } from "./context/ApiContext"; import { ForbiddenPage } from "./pages/errors/ForbiddenPage"; import { ClientPages } from "./pages/client/ClientPages"; +import { NavigationBar } from "./components/NavigationBar"; +import { DashboardLayout } from "./components/Layout"; function App() { return ( @@ -31,15 +33,18 @@ function App() { > + - {AdminPages} - {ClientPages} - {AccountPages} + }> + {AdminPages} + {ClientPages} + {AccountPages} - - } /> + + } /> + + } /> - } /> diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx new file mode 100644 index 0000000..8bece33 --- /dev/null +++ b/frontend/src/components/Layout.tsx @@ -0,0 +1,37 @@ +import React from "react"; +import { Box } from "@mui/material"; +import { Outlet } from "react-router-dom"; +import { NavigationBar } from "./NavigationBar"; + +export const DashboardLayout = () => { + return ( + + + + + {/* This is so that the sidebar stays here */} + + + + + + + + + ); +}; diff --git a/frontend/src/components/NavigationBar.tsx b/frontend/src/components/NavigationBar.tsx new file mode 100644 index 0000000..86e30ea --- /dev/null +++ b/frontend/src/components/NavigationBar.tsx @@ -0,0 +1,109 @@ +import React from "react"; +import { AppBar, Box, IconButton, Typography } from "@mui/material"; +import { Logout } from "@mui/icons-material"; +import { useAuthContext } from "../context/AuthContext"; +import { useNavigate } from "react-router-dom"; + +export const NavigationBar: React.FC = ({ ...props }) => { + const authContext = useAuthContext(); + const navigate = useNavigate(); + + const onLogout = async () => { + await authContext.logout(); + }; + + return ( + ({ + zIndex: zIndex.drawer + 1, + })} + > + + {!authContext.isAuthenticated && ( + + navigate("/accounts/login")} + > + Login + + navigate("/accounts/register")} + > + Register + + + )} + {authContext.isAuthenticated && ( + + {authContext.isAdmin && ( + navigate("/admin/orders")} + > + Orders + + )} + {!authContext.isAdmin && ( + navigate("/client/issue")} + > + Issue + + )} + + + {authContext.userId} + + + + + + + + )} + + + ); +}; diff --git a/frontend/src/pages/client/pages/IssuePage.tsx b/frontend/src/pages/client/pages/IssuePage.tsx index f16be47..f102151 100644 --- a/frontend/src/pages/client/pages/IssuePage.tsx +++ b/frontend/src/pages/client/pages/IssuePage.tsx @@ -8,11 +8,9 @@ export const IssuePage: React.FC = () => {