2023-05-17 11:20:11 +00:00
|
|
|
|
import { Link, useLocation, useNavigate } from "react-router-dom";
|
2023-03-27 12:45:44 +00:00
|
|
|
|
import { useEffect } from "react";
|
2023-05-17 11:20:11 +00:00
|
|
|
|
import { Box, Button, Container, Divider, IconButton, Typography, useTheme } from "@mui/material";
|
2023-03-22 11:51:16 +00:00
|
|
|
|
|
2022-11-21 18:19:51 +00:00
|
|
|
|
import SectionWrapper from "../SectionWrapper";
|
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";
|
2023-03-27 12:45:44 +00:00
|
|
|
|
import Drawers from "../Drawers";
|
2023-03-22 11:51:16 +00:00
|
|
|
|
import PenaLogo from "../PenaLogo";
|
2023-03-27 12:45:44 +00:00
|
|
|
|
import Menu from "../Menu";
|
2023-05-17 11:20:11 +00:00
|
|
|
|
import { logout } from "@root/api/auth";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { clearUser, useUserStore } from "@root/stores/user";
|
2022-11-21 18:19:51 +00:00
|
|
|
|
|
|
|
|
|
interface Props {
|
2023-05-12 14:27:35 +00:00
|
|
|
|
isLoggedIn: boolean;
|
2022-11-21 18:19:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function NavbarFull({ isLoggedIn }: Props) {
|
2023-05-12 14:27:35 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const { clearToken } = authStore();
|
|
|
|
|
const location = useLocation();
|
2023-05-17 11:20:11 +00:00
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const user = useUserStore(state => state.user);
|
2023-03-22 11:51:16 +00:00
|
|
|
|
|
2023-05-12 14:27:35 +00:00
|
|
|
|
const { open } = basketStore();
|
2023-03-22 11:51:16 +00:00
|
|
|
|
|
2023-05-12 14:27:35 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (location.pathname === "/basket") {
|
|
|
|
|
open(false)();
|
|
|
|
|
}
|
|
|
|
|
}, [location.pathname, open]);
|
2023-03-24 18:30:56 +00:00
|
|
|
|
|
2023-05-12 14:27:35 +00:00
|
|
|
|
async function handleLogoutClick() {
|
2023-05-17 11:20:11 +00:00
|
|
|
|
try {
|
|
|
|
|
await logout();
|
|
|
|
|
clearToken();
|
|
|
|
|
clearUser();
|
|
|
|
|
navigate("/");
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.log("Logout error", error);
|
2023-05-23 12:50:21 +00:00
|
|
|
|
enqueueSnackbar("Не удалось выйти");
|
2023-05-17 11:20:11 +00:00
|
|
|
|
}
|
2023-05-12 14:27:35 +00:00
|
|
|
|
}
|
2022-11-21 18:19:51 +00:00
|
|
|
|
|
2023-05-12 14:27:35 +00:00
|
|
|
|
return isLoggedIn ? (
|
|
|
|
|
<Container
|
|
|
|
|
component="nav"
|
|
|
|
|
disableGutters
|
|
|
|
|
maxWidth={false}
|
2022-11-21 18:19:51 +00:00
|
|
|
|
sx={{
|
2023-05-12 14:27:35 +00:00
|
|
|
|
px: "16px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
height: "80px",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "60px",
|
|
|
|
|
bgcolor: "white",
|
|
|
|
|
borderBottom: "1px solid #E3E3E3",
|
2022-11-21 18:19:51 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-05-12 14:27:35 +00:00
|
|
|
|
<PenaLogo width={124} />
|
|
|
|
|
<Menu />
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
ml: "auto",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Drawers />
|
|
|
|
|
<IconButton sx={{ p: 0, ml: "8px" }}>
|
|
|
|
|
<WalletIcon color={theme.palette.grey2.main} bgcolor="#F2F3F7" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Box sx={{ ml: "8px", whiteSpace: "nowrap" }}>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "12px",
|
|
|
|
|
lineHeight: "14px",
|
|
|
|
|
color: theme.palette.grey3.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Мой баланс
|
|
|
|
|
</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" }}
|
|
|
|
|
>
|
|
|
|
|
<LogoutIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
|
|
|
|
</Container>
|
|
|
|
|
) : (
|
2023-05-17 11:20:11 +00:00
|
|
|
|
<>
|
|
|
|
|
<SectionWrapper
|
|
|
|
|
component="nav"
|
|
|
|
|
maxWidth="lg"
|
|
|
|
|
outerContainerSx={{
|
|
|
|
|
backgroundColor: theme.palette.lightPurple.main,
|
|
|
|
|
// borderBottom: "1px solid #E3E3E3",
|
|
|
|
|
}}
|
2023-05-12 14:27:35 +00:00
|
|
|
|
sx={{
|
2023-05-17 11:20:11 +00:00
|
|
|
|
px: "20px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
height: "80px",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "50px",
|
2023-05-12 14:27:35 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-05-17 11:20:11 +00:00
|
|
|
|
<PenaLogo width={150} />
|
|
|
|
|
<Menu />
|
|
|
|
|
<Button
|
|
|
|
|
component={Link}
|
|
|
|
|
to={user ? "/tariffs" : "/signin"}
|
|
|
|
|
state={user ? undefined : { backgroundLocation: location }}
|
|
|
|
|
variant="outlined"
|
|
|
|
|
sx={{
|
|
|
|
|
px: "18px",
|
|
|
|
|
py: "10px",
|
|
|
|
|
borderColor: "white",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
minWidth: "180px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Личный кабинет
|
|
|
|
|
</Button>
|
|
|
|
|
</SectionWrapper>
|
|
|
|
|
<Divider sx={{ bgcolor: "#E3E3E3", borderColor: "#00000000" }} />
|
|
|
|
|
</>
|
2023-05-12 14:27:35 +00:00
|
|
|
|
);
|
|
|
|
|
}
|