front-hub/src/components/Navbar/NavbarFull.tsx

184 lines
5.0 KiB
TypeScript
Raw Normal View History

2023-03-24 15:30:58 +00:00
import Icon from "@mui/material/Icon";
2023-03-22 11:51:16 +00:00
import { useEffect, useState } from "react";
2022-11-21 18:19:51 +00:00
import { Box, Button, Container, IconButton, Typography, useTheme } from "@mui/material";
2023-03-22 11:51:16 +00:00
2023-03-24 15:30:58 +00:00
import { Drawers } from "../Drawer/Drawers";
2022-11-21 18:19:51 +00:00
import NavMenuItem from "../NavMenuItem";
import SectionWrapper from "../SectionWrapper";
2023-03-22 11:51:16 +00:00
2023-03-24 15:30:58 +00:00
import { basketStore } from "@stores/BasketStore";
2023-03-21 18:52:19 +00:00
import { authStore } from "@stores/makeRequest";
2022-11-21 18:19:51 +00:00
2023-03-22 11:51:16 +00:00
import LogoutIcon from "../icons/LogoutIcon";
import WalletIcon from "../icons/WalletIcon";
import CustomAvatar from "./Avatar";
import PenaLogo from "../PenaLogo";
2023-03-24 15:30:58 +00:00
import { useLocation } from "react-router-dom";
2022-11-21 18:19:51 +00:00
interface Props {
2023-03-19 15:25:40 +00:00
isLoggedIn: boolean;
2022-11-21 18:19:51 +00:00
}
export default function NavbarFull({ isLoggedIn }: Props) {
2023-03-19 15:25:40 +00:00
const theme = useTheme();
2023-03-21 18:52:19 +00:00
const { clearToken } = authStore();
2023-03-22 11:51:16 +00:00
const [basketQuantity, setBasketQuantity] = useState<number>(0);
2023-03-24 15:30:58 +00:00
const location = useLocation();
2023-03-22 11:51:16 +00:00
2023-03-24 15:30:58 +00:00
const { templ, squiz, reducer, open } = basketStore();
2023-03-22 11:51:16 +00:00
useEffect(() => {
setBasketQuantity(Object.keys(templ).length + Object.keys(squiz).length);
2023-03-24 15:30:58 +00:00
if (location.pathname === "/basket") {
open(false)();
}
}, [templ, squiz, location.pathname, open]);
2022-11-29 12:20:50 +00:00
2023-03-19 15:25:40 +00:00
async function handleLogoutClick() {
2023-03-21 18:52:19 +00:00
clearToken();
2023-03-19 15:25:40 +00:00
}
2022-11-21 18:19:51 +00:00
2023-03-19 15:25:40 +00:00
return isLoggedIn ? (
<Container
component="nav"
disableGutters
maxWidth={false}
sx={{
px: "16px",
display: "flex",
height: "80px",
alignItems: "center",
gap: "60px",
bgcolor: "white",
borderBottom: "1px solid #E3E3E3",
}}
>
<PenaLogo width={124} />
<Box
sx={{
display: "flex",
gap: "30px",
overflow: "hidden",
}}
>
<NavMenuItem text="Меню 1" />
<NavMenuItem text="Меню 2" isActive />
<NavMenuItem text="Меню 3" />
<NavMenuItem text="Меню 4" />
<NavMenuItem text="Меню 5" />
<NavMenuItem text="Меню 1" />
<NavMenuItem text="Меню 2" />
</Box>
<Box
sx={{
display: "flex",
ml: "auto",
}}
>
2023-03-24 15:30:58 +00:00
<IconButton sx={{ p: 0 }}>
2023-03-22 11:51:16 +00:00
<Typography component="div" sx={{ position: "absolute" }}>
2023-03-24 15:30:58 +00:00
<Drawers />
2023-03-22 11:51:16 +00:00
</Typography>
{basketQuantity && (
<Icon
sx={{
position: "relative",
left: "8px",
bottom: "7px",
width: "16px",
height: "16px",
backgroundColor: "#7E2AEA",
borderRadius: "12px",
}}
>
<Typography
component="div"
sx={{
display: "flex",
fontSize: "12px",
mt: "4.5px",
width: "100%",
height: "9px",
color: "white",
alignItems: "center",
justifyContent: "center",
}}
>
{basketQuantity}
</Typography>
</Icon>
)}
2023-03-19 15:25:40 +00:00
</IconButton>
2023-03-22 11:51:16 +00:00
<IconButton sx={{ p: 0, ml: "8px" }}>
2023-03-19 15:25:40 +00:00
<WalletIcon color={theme.palette.grey2.main} bgcolor="#F2F3F7" />
</IconButton>
<Box sx={{ ml: "8px", whiteSpace: "nowrap" }}>
<Typography
2022-11-21 18:19:51 +00:00
sx={{
2023-03-19 15:25:40 +00:00
fontSize: "12px",
lineHeight: "14px",
color: theme.palette.grey3.main,
2022-11-21 18:19:51 +00:00
}}
2023-03-19 15:25:40 +00:00
>
Мой баланс
</Typography>
<Typography variant="body2" color={theme.palette.brightPurple.main}>
00.00 руб.
</Typography>
</Box>
<CustomAvatar sx={{ ml: "27px", backgroundColor: theme.palette.orange.main, height: "36px", width: "36px" }} />
<IconButton
onClick={handleLogoutClick}
sx={{ ml: "20px", bgcolor: "#F2F3F7", borderRadius: "6px", height: "36px", width: "36px" }}
2022-11-21 18:19:51 +00:00
>
2023-03-19 15:25:40 +00:00
<LogoutIcon />
</IconButton>
</Box>
</Container>
) : (
<SectionWrapper
component="nav"
maxWidth="lg"
outerContainerSx={{
backgroundColor: theme.palette.lightPurple.main,
// borderBottom: "1px solid #E3E3E3",
}}
sx={{
px: "20px",
display: "flex",
justifyContent: "space-between",
height: "80px",
alignItems: "center",
}}
>
<Box
sx={{
display: "flex",
gap: "30px",
overflow: "hidden",
}}
>
<NavMenuItem text="Меню 1" />
<NavMenuItem text="Меню 2" isActive />
<NavMenuItem text="Меню 3" />
<NavMenuItem text="Меню 4" />
<NavMenuItem text="Меню 5" />
<NavMenuItem text="Меню 1" />
<NavMenuItem text="Меню 2" />
</Box>
<Button
variant="outlined"
sx={{
px: "18px",
py: "10px",
borderColor: "white",
borderRadius: "8px",
}}
>
Личный кабинет
</Button>
</SectionWrapper>
);
}