header fixes
This commit is contained in:
@@ -7,27 +7,30 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
Button,
|
Button,
|
||||||
Box,
|
Box,
|
||||||
|
useMediaQuery,
|
||||||
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import MenuIcon from "@mui/icons-material/Menu";
|
import MenuIcon from "@mui/icons-material/Menu";
|
||||||
import LogoutIcon from "@mui/icons-material/Logout";
|
import LogoutIcon from "@mui/icons-material/Logout";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useAuth } from "../react-auth";
|
||||||
|
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
headerTitle: string;
|
headerTitle: string;
|
||||||
isMobile: boolean;
|
onDrawerToggle?: () => void; // optional (only used where needed)
|
||||||
onDrawerToggle: () => void;
|
|
||||||
onLogout: () => void;
|
|
||||||
username?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Header({
|
export default function Header({
|
||||||
headerTitle,
|
headerTitle,
|
||||||
isMobile,
|
|
||||||
onDrawerToggle,
|
onDrawerToggle,
|
||||||
onLogout,
|
|
||||||
username,
|
|
||||||
}: HeaderProps) {
|
}: HeaderProps) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { currentUser, logout } = useAuth();
|
||||||
|
|
||||||
|
const theme = useTheme();
|
||||||
|
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
|
|
||||||
|
const isAuthenticated = !!currentUser;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppBar
|
<AppBar
|
||||||
@@ -42,7 +45,8 @@ export default function Header({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
{isMobile && (
|
{/* MOBILE MENU BUTTON */}
|
||||||
|
{isMobile && onDrawerToggle && (
|
||||||
<IconButton
|
<IconButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
edge="start"
|
edge="start"
|
||||||
@@ -53,29 +57,51 @@ export default function Header({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* TITLE */}
|
||||||
<Typography
|
<Typography
|
||||||
variant="h6"
|
variant="h6"
|
||||||
noWrap
|
noWrap
|
||||||
sx={{ flexGrow: 1, fontWeight: "bold" }}
|
sx={{ flexGrow: 1, fontWeight: "bold", cursor: "pointer" }}
|
||||||
|
onClick={() => navigate("/")}
|
||||||
>
|
>
|
||||||
{headerTitle}
|
{headerTitle}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Box sx={{ display: { xs: "none", sm: "flex" }, alignItems: "center", mr: 2 }}>
|
{/* AUTH SECTION */}
|
||||||
|
{isAuthenticated ? (
|
||||||
|
<>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: { xs: "none", sm: "flex" },
|
||||||
|
alignItems: "center",
|
||||||
|
mr: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
color="inherit"
|
color="inherit"
|
||||||
onClick={() => navigate("/admin/profile")}
|
onClick={() => navigate("/admin/profile")}
|
||||||
sx={{ textTransform: "none", fontWeight: 500 }}
|
sx={{ textTransform: "none", fontWeight: 500 }}
|
||||||
>
|
>
|
||||||
{username}
|
{currentUser.username}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Tooltip title="Logout">
|
<Tooltip title="Logout">
|
||||||
<IconButton color="inherit" onClick={onLogout}>
|
<IconButton color="inherit" onClick={logout}>
|
||||||
<LogoutIcon />
|
<LogoutIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
color="inherit"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={() => navigate("/admin")}
|
||||||
|
sx={{ textTransform: "none" }}
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user