Error message as snack bar instead of 404

This commit is contained in:
Luis-Hebendanz
2023-09-02 14:57:45 +02:00
parent 75c885eeb5
commit 7c41aa57bb

View File

@@ -1,4 +1,5 @@
import { import {
Alert,
Divider, Divider,
Icon, Icon,
IconButton, IconButton,
@@ -7,6 +8,7 @@ import {
ListItemButton, ListItemButton,
ListItemIcon, ListItemIcon,
ListItemText, ListItemText,
Snackbar,
} from "@mui/material"; } from "@mui/material";
import Image from "next/image"; import Image from "next/image";
import { ReactNode, useState } from "react"; import { ReactNode, useState } from "react";
@@ -21,11 +23,13 @@ import Link from "next/link";
import { tw } from "@/utils/tailwind"; import { tw } from "@/utils/tailwind";
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
import React from "react";
type MenuEntry = { type MenuEntry = {
icon: ReactNode; icon: ReactNode;
label: string; label: string;
to: string; to: string;
missing: boolean;
} & { } & {
subMenuEntries?: MenuEntry[]; subMenuEntries?: MenuEntry[];
}; };
@@ -35,31 +39,37 @@ const menuEntries: MenuEntry[] = [
icon: <DashboardIcon />, icon: <DashboardIcon />,
label: "Dashoard", label: "Dashoard",
to: "/", to: "/",
missing: false,
}, },
{ {
icon: <DevicesIcon />, icon: <DevicesIcon />,
label: "Machines", label: "Machines",
to: "/machines", to: "/machines",
missing: false,
}, },
{ {
icon: <AppsIcon />, icon: <AppsIcon />,
label: "Applications", label: "Applications",
to: "/applications", to: "/applications",
missing: true,
}, },
{ {
icon: <LanIcon />, icon: <LanIcon />,
label: "Network", label: "Network",
to: "/network", to: "/network",
missing: true,
}, },
{ {
icon: <DesignServicesIcon />, icon: <DesignServicesIcon />,
label: "Templates", label: "Templates",
to: "/templates", to: "/templates",
missing: false,
}, },
{ {
icon: <BackupIcon />, icon: <BackupIcon />,
label: "Backups", label: "Backups",
to: "/backups", to: "/backups",
missing: true,
}, },
]; ];
@@ -72,6 +82,23 @@ interface SidebarProps {
} }
export function Sidebar(props: SidebarProps) { export function Sidebar(props: SidebarProps) {
const { show, onClose } = props; const { show, onClose } = props;
const [open, setOpen] = React.useState(false);
const handleClick = () => {
setOpen(true);
};
const handleClose = (
event?: React.SyntheticEvent | Event,
reason?: string,
) => {
if (reason === "clickaway") {
return;
}
setOpen(false);
};
return ( return (
<aside <aside
className={tw`${ className={tw`${
@@ -110,7 +137,10 @@ export function Sidebar(props: SidebarProps) {
<ListItemButton <ListItemButton
className="justify-center lg:justify-normal" className="justify-center lg:justify-normal"
LinkComponent={Link} LinkComponent={Link}
href={menuEntry.to} href={menuEntry.missing ? "" : menuEntry.to}
onClickCapture={
menuEntry.missing ? () => handleClick() : undefined
}
> >
<ListItemIcon <ListItemIcon
color="inherit" color="inherit"
@@ -131,6 +161,11 @@ export function Sidebar(props: SidebarProps) {
})} })}
</List> </List>
<Snackbar open={open} autoHideDuration={2000} onClose={handleClose}>
<Alert onClose={handleClose} severity="error" sx={{ width: "100%" }}>
Site does not exist yet
</Alert>
</Snackbar>
<Divider flexItem className="mx-8 my-10 hidden bg-zinc-600 lg:block" /> <Divider flexItem className="mx-8 my-10 hidden bg-zinc-600 lg:block" />
<div className="mx-auto mb-8 hidden w-full max-w-xs rounded-sm px-4 py-6 text-center align-bottom shadow-sm lg:block"> <div className="mx-auto mb-8 hidden w-full max-w-xs rounded-sm px-4 py-6 text-center align-bottom shadow-sm lg:block">
<h3 className="mb-2 w-full font-semibold text-white"> <h3 className="mb-2 w-full font-semibold text-white">