import { useState, useRef } from "react"; import { Typography, Drawer, useMediaQuery, useTheme, Box, IconButton, Badge, Button, } from "@mui/material"; import { getMessageFromFetchError } from "@frontend/kitui"; import SectionWrapper from "./SectionWrapper"; import CustomWrapperDrawer from "./CustomWrapperDrawer"; import { NotificationsModal } from "./NotificationsModal"; import { useCart } from "@root/utils/hooks/useCart"; import { currencyFormatter } from "@root/utils/currencyFormatter"; import { closeCartDrawer, openCartDrawer, useCartStore, } from "@root/stores/cart"; import { setUserAccount, useUserStore } from "@root/stores/user"; import { useTicketStore } from "@root/stores/tickets"; import { ReactComponent as BellIcon } from "@root/assets/Icons/bell.svg"; import { ReactComponent as CartIcon } from "@root/assets/Icons/cart.svg"; import { ReactComponent as CrossIcon } from "@root/assets/Icons/cross.svg"; import { payCart } from "@root/api/cart"; import { isAxiosError } from "axios"; import { enqueueSnackbar } from "notistack"; import { Link, useNavigate } from "react-router-dom"; export default function Drawers() { const [openNotificationsModal, setOpenNotificationsModal] = useState(false); const bellRef = useRef(null); const navigate = useNavigate(); const theme = useTheme(); const upMd = useMediaQuery(theme.breakpoints.up("md")); const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isDrawerOpen = useCartStore((state) => state.isDrawerOpen); const cart = useCart(); const userAccount = useUserStore((state) => state.userAccount); const tickets = useTicketStore((state) => state.tickets); const [notEnoughMoneyAmount, setNotEnoughMoneyAmount] = useState(0); const notificationsCount = tickets.filter( ({ user, top_message }) => user !== top_message.user_id && top_message.shown.me !== 1 ).length; async function handlePayClick() { const [payCartResponse, payCartError] = await payCart(); if (payCartError) { const notEnoughMoneyAmount = parseInt( payCartError.replace("insufficient funds: ", "") ); setNotEnoughMoneyAmount(notEnoughMoneyAmount); return enqueueSnackbar(payCartError); } if (payCartResponse) { setUserAccount(payCartResponse); } } function handleReplenishWallet() { navigate("/payment", { state: { notEnoughMoneyAmount } }); } return ( setOpenNotificationsModal((isOpened) => !isOpened)} sx={{ cursor: "pointer", borderRadius: "6px", background: openNotificationsModal ? theme.palette.purple.main : theme.palette.background.default, "& .MuiBadge-badge": { background: openNotificationsModal ? theme.palette.background.default : theme.palette.purple.main, color: openNotificationsModal ? theme.palette.purple.main : theme.palette.background.default, }, "& svg > path:first-child": { fill: openNotificationsModal ? "#FFFFFF" : "#9A9AAF", }, "& svg > path:last-child": { stroke: openNotificationsModal ? "#FFFFFF" : "#9A9AAF", }, "&:hover": { background: theme.palette.purple.main, "& .MuiBox-root": { background: theme.palette.purple.main, }, "& .MuiBadge-badge": { background: theme.palette.background.default, color: theme.palette.purple.main, }, "& svg > path:first-child": { fill: "#FFFFFF" }, "& svg > path:last-child": { stroke: "#FFFFFF" }, }, }} > user !== top_message.user_id) .map((ticket) => ({ text: "У вас новое сообщение от техподдержки", date: new Date(ticket.updated_at).toLocaleDateString(), url: `/support/${ticket.id}`, watched: ticket.user === ticket.top_message.user_id || ticket.top_message.shown.me === 1, }))} /> path:nth-child(1)": { fill: "#FFFFFF" }, "& svg > path:nth-child(2)": { fill: "#FFFFFF" }, "& svg > path:nth-child(3)": { stroke: "#FFFFFF" }, }, }} > Корзина {cart.services.map((serviceData) => ( ))} Итоговая цена Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель {currencyFormatter.format(cart.priceBeforeDiscounts / 100)} {currencyFormatter.format(cart.priceAfterDiscounts / 100)} ); }