2024-01-16 19:24:09 +00:00
|
|
|
|
import { Link, useNavigate } from "react-router-dom";
|
|
|
|
|
import { Box, IconButton, Typography, useTheme, useMediaQuery } from "@mui/material";
|
|
|
|
|
import LogoutIcon from "../icons/LogoutIcon";
|
|
|
|
|
import Drawers from "../Drawers";
|
|
|
|
|
import { logout } from "@root/api/auth";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { clearUserData, useUserStore } from "@root/stores/user";
|
|
|
|
|
import { AvatarButton, clearAuthToken } from "@frontend/kitui";
|
|
|
|
|
import { clearCustomTariffs } from "@root/stores/customTariffs";
|
|
|
|
|
import { clearTickets } from "@root/stores/tickets";
|
2023-08-23 09:27:57 +00:00
|
|
|
|
|
2024-01-16 19:24:09 +00:00
|
|
|
|
import { currencyFormatter } from "@root/utils/currencyFormatter";
|
2023-08-23 09:27:57 +00:00
|
|
|
|
|
2024-01-16 19:24:09 +00:00
|
|
|
|
import walletIcon from "@root/assets/Icons/wallet_icon.svg";
|
2023-08-23 09:27:57 +00:00
|
|
|
|
|
|
|
|
|
export const NavbarPanel = () => {
|
2024-01-16 19:24:09 +00:00
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
|
|
|
|
const cash = useUserStore((state) => state.userAccount?.wallet.cash) ?? 0;
|
|
|
|
|
const initials = useUserStore((state) => state.initials);
|
2023-08-23 09:27:57 +00:00
|
|
|
|
|
2024-01-16 19:24:09 +00:00
|
|
|
|
async function handleLogoutClick() {
|
|
|
|
|
const [_, logoutError] = await logout();
|
2023-08-30 09:56:14 +00:00
|
|
|
|
|
2024-01-16 19:24:09 +00:00
|
|
|
|
if (logoutError) {
|
|
|
|
|
return enqueueSnackbar(logoutError);
|
|
|
|
|
}
|
2023-08-23 09:27:57 +00:00
|
|
|
|
|
2024-01-16 19:24:09 +00:00
|
|
|
|
clearAuthToken();
|
|
|
|
|
clearUserData();
|
|
|
|
|
clearCustomTariffs();
|
|
|
|
|
clearTickets();
|
|
|
|
|
navigate("/");
|
|
|
|
|
}
|
2023-08-30 09:56:14 +00:00
|
|
|
|
|
2024-01-16 19:24:09 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box sx={{ display: "flex", ml: "auto" }}>
|
|
|
|
|
<Drawers />
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
ml: isTablet ? "10px" : "20px",
|
|
|
|
|
bgcolor: "#F2F3F7",
|
|
|
|
|
borderRadius: "6px",
|
|
|
|
|
height: "36px",
|
|
|
|
|
width: "36px",
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => navigate("/wallet")}
|
|
|
|
|
>
|
|
|
|
|
<img src={walletIcon} alt="wallet" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Box sx={{ ml: "8px", whiteSpace: "nowrap" }}>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "12px",
|
|
|
|
|
lineHeight: "14px",
|
|
|
|
|
color: theme.palette.gray.dark,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-08-30 09:56:14 +00:00
|
|
|
|
Мой баланс
|
2024-01-16 19:24:09 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
<Typography variant="body2" color={theme.palette.purple.main}>
|
|
|
|
|
{currencyFormatter.format(cash / 100)}
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<AvatarButton component={Link} to="/settings" sx={{ ml: "27px" }}>
|
|
|
|
|
{initials}
|
|
|
|
|
</AvatarButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={handleLogoutClick}
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "20px",
|
|
|
|
|
bgcolor: "#F2F3F7",
|
|
|
|
|
borderRadius: "6px",
|
|
|
|
|
height: "36px",
|
|
|
|
|
width: "36px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LogoutIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|