From fbc1df5f346f75c50cc108976389254d729a93a1 Mon Sep 17 00:00:00 2001 From: april Date: Thu, 11 Jan 2024 15:06:40 -0600 Subject: [PATCH] Add placeholder admin dashboard --- web/app/routes/logbook.admin/route.tsx | 13 +++++++++++++ web/app/ui/nav/navbar.tsx | 16 +++++++++++++++- web/app/util/auth.tsx | 13 +++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 web/app/routes/logbook.admin/route.tsx diff --git a/web/app/routes/logbook.admin/route.tsx b/web/app/routes/logbook.admin/route.tsx new file mode 100644 index 0000000..10528d8 --- /dev/null +++ b/web/app/routes/logbook.admin/route.tsx @@ -0,0 +1,13 @@ +import { Container, Group, Title } from "@mantine/core"; + +export default function Admin() { + return ( + <> + + + Admin + + + + ); +} diff --git a/web/app/ui/nav/navbar.tsx b/web/app/ui/nav/navbar.tsx index b862a59..1df3f25 100644 --- a/web/app/ui/nav/navbar.tsx +++ b/web/app/ui/nav/navbar.tsx @@ -2,6 +2,7 @@ import { useAuth } from "@/util/auth"; import { Stack, NavLink } from "@mantine/core"; import { Link, useLocation } from "@remix-run/react"; import { + IconAdjustments, IconBook2, IconDashboard, IconLogout, @@ -19,7 +20,7 @@ export default function Navbar({ const location = useLocation(); const page = location.pathname.split("/")[2]; - const { user, signout } = useAuth(); + const { user, authLevel, signout } = useAuth(); return ( @@ -51,6 +52,19 @@ export default function Navbar({ active={page === "aircraft"} onClick={() => (opened ? toggle() : null)} /> + {authLevel ? ( + authLevel === 2 ? ( + } + active={page === "admin"} + onClick={() => (opened ? toggle() : null)} + /> + ) : null + ) : null} (null); + const [authLevel, setAuthLevel] = useState(null); const [loading, setLoading] = useState(true); const navigate = useNavigate(); @@ -83,7 +85,10 @@ function useProvideAuth() { setLoading(false); await client .get("/users/me") - .then((response) => handleUser(response.data.username)) + .then((response) => { + handleUser(response.data.username); + setAuthLevel(response.data.level); + }) .catch(() => handleUser(null)); navigate("/logbook"); }; @@ -99,13 +104,17 @@ function useProvideAuth() { useEffect(() => { client .get("/users/me") - .then((response) => handleUser(response.data.username)) + .then((response) => { + handleUser(response.data.username); + setAuthLevel(response.data.level); + }) .catch(() => handleUser(null)); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return { user, + authLevel, loading, signin, signout,