Skip to content

Commit

Permalink
vinvoor: add an admin route
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie authored and hannes-dev committed Jul 20, 2024
1 parent 72303a9 commit 8f181f4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
1 change: 0 additions & 1 deletion vinvoor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"notistack": "^3.0.1",
"react": "^18.2.0",
"react-apexcharts": "^1.4.1",
"react-device-detect": "^2.2.3",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1",
"react-router-hash-link": "^2.4.3",
Expand Down
13 changes: 13 additions & 0 deletions vinvoor/src/components/BrowserView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMediaQuery, useTheme } from "@mui/material";
import { FC } from "react";

interface BrowserViewProps {
children: React.ReactNode;
}

export const BrowserView: FC<BrowserViewProps> = ({ children }) => {
const theme = useTheme();
const isMobileView = useMediaQuery(theme.breakpoints.down("md"));

return isMobileView ? null : <>{children}</>;
};
5 changes: 5 additions & 0 deletions vinvoor/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CustomSnackbarProvider } from "./providers/CustomSnackbarProvider.tsx";
import { ThemeProvider } from "./providers/ThemeProvider.tsx";
import { UserProvider } from "./providers/UserProvider.tsx";
import { Scans } from "./scans/Scans.tsx";
import { Admin } from "./settings/admin/Admin.tsx";
import { SettingsOverview } from "./settings/SettingsOverview.tsx";
import { Login } from "./user/Login.tsx";
import { Logout } from "./user/Logout.tsx";
Expand Down Expand Up @@ -50,6 +51,10 @@ const router = createBrowserRouter([
path: "settings",
element: <SettingsOverview />,
},
{
path: "admin",
element: <Admin />,
},
],
},
]);
Expand Down
23 changes: 20 additions & 3 deletions vinvoor/src/navbar/NavBarUserMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AccountCircle } from "@mui/icons-material";
import { Button, Divider, Menu, MenuItem, Typography } from "@mui/material";
import { ExitRun } from "mdi-material-ui";
import { Cow, ExitRun, ShieldAccountOutline } from "mdi-material-ui";
import { FC, MouseEvent, useContext, useState } from "react";
import { UnstyledLink } from "../components/UnstyledLink";
import { UserContext } from "../providers/UserProvider";
Expand Down Expand Up @@ -39,7 +38,7 @@ export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({ pageIcons }) => {
color: "secondary.contrastText",
}}
>
<AccountCircle sx={{ mr: "3px" }} />
<ShieldAccountOutline sx={{ mr: "3px" }} />
<Typography variant="h6">{user.username}</Typography>
</Button>
<Menu
Expand All @@ -66,6 +65,24 @@ export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({ pageIcons }) => {
</UnstyledLink>
))}
<Divider />
{user.admin && (
<UnstyledLink to="admin">
<MenuItem
onClick={handleCloseUserMenu}
sx={{
paddingX: "0",
justifyContent: "center",
backgroundColor: "error.dark",
"&:hover": {
backgroundColor: "error.light",
},
}}
>
<Cow sx={{ mr: ".3rem", ml: "-12px" }} />
<Typography>Admin</Typography>
</MenuItem>
</UnstyledLink>
)}
<MenuItem
onClick={handleCloseUserMenu}
sx={{
Expand Down
2 changes: 1 addition & 1 deletion vinvoor/src/overview/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box, Paper, Stack, Switch, Typography } from "@mui/material";
import Grid from "@mui/material/Grid";
import { createContext, useEffect, useRef, useState } from "react";
import { BrowserView } from "react-device-detect";
import { Tooltip } from "react-tooltip";
import { BrowserView } from "../components/BrowserView";
import { LoadingSkeleton } from "../components/LoadingSkeleton";
import { useFetch } from "../hooks/useFetch";
import { convertScanJSON, Scan } from "../types/scans";
Expand Down
6 changes: 6 additions & 0 deletions vinvoor/src/settings/admin/Admin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Typography } from "@mui/material";
import { FC } from "react";

export const Admin: FC = () => {
return <Typography>Admin</Typography>;
};
12 changes: 0 additions & 12 deletions vinvoor/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2071,13 +2071,6 @@ react-apexcharts@^1.4.1:
dependencies:
prop-types "^15.8.1"

react-device-detect@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/react-device-detect/-/react-device-detect-2.2.3.tgz#97a7ae767cdd004e7c3578260f48cf70c036e7ca"
integrity sha512-buYY3qrCnQVlIFHrC5UcUoAj7iANs/+srdkwsnNjI7anr3Tt7UY6MqNxtMLlr0tMBied0O49UZVK8XKs3ZIiPw==
dependencies:
ua-parser-js "^1.0.33"

react-dom@^18.2.0:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4"
Expand Down Expand Up @@ -2398,11 +2391,6 @@ typescript@^5.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.3.tgz#e1b0a3c394190838a0b168e771b0ad56a0af0faa"
integrity sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==

ua-parser-js@^1.0.33:
version "1.0.38"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.38.tgz#66bb0c4c0e322fe48edfe6d446df6042e62f25e2"
integrity sha512-Aq5ppTOfvrCMgAPneW1HfWj66Xi7XL+/mIy996R1/CLS/rcyJQm6QZdsKrUeivDFQ+Oc9Wyuwor8Ze8peEoUoQ==

update-browserslist-db@^1.0.16:
version "1.1.0"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz#7ca61c0d8650766090728046e416a8cde682859e"
Expand Down

0 comments on commit 8f181f4

Please sign in to comment.