import { useState, useRef, useCallback } from "react"; import { Typography, Drawer, useMediaQuery, useTheme, Box, IconButton, SvgIcon, Badge, } from "@mui/material"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import ClearIcon from "@mui/icons-material/Clear"; import { useTickets } from "@frontend/kitui"; import SectionWrapper from "./SectionWrapper"; import CustomWrapperDrawer from "./CustomWrapperDrawer"; import CustomButton from "./CustomButton"; import { NotificationsModal } from "./NotificationsModal"; import { useNavigate } from "react-router"; import { useCart } from "@root/utils/hooks/useCart"; import { currencyFormatter } from "@root/utils/currencyFormatter"; import { closeCartDrawer, openCartDrawer, useCartStore, } from "@root/stores/cart"; import { useCustomTariffsStore } from "@root/stores/customTariffs"; import { useUserStore } from "@root/stores/user"; import { updateTickets, setTicketCount, 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"; 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 isDrawerOpen = useCartStore((state) => state.isDrawerOpen); const cart = useCart(); const summaryPriceBeforeDiscountsMap = useCustomTariffsStore( (state) => state.summaryPriceBeforeDiscountsMap ); const summaryPriceAfterDiscountsMap = useCustomTariffsStore( (state) => state.summaryPriceAfterDiscountsMap ); const userAccount = useUserStore((state) => state.userAccount); const ticketCount = useTicketStore((state) => state.ticketCount); const ticketApiPage = useTicketStore((state) => state.apiPage); const ticketsPerPage = useTicketStore((state) => state.ticketsPerPage); const tickets = useTicketStore((state) => state.tickets); useTickets({ url: "https://hub.pena.digital/heruvym/getTickets", ticketsPerPage, ticketApiPage, onNewTickets: useCallback((result) => { if (result.data) updateTickets(result.data); setTicketCount(result.count); }, []), onError: () => {}, }); const basePrice = Object.values(summaryPriceBeforeDiscountsMap).reduce( (a, e) => a + e, 0 ); const discountedPrice = Object.values(summaryPriceAfterDiscountsMap).reduce( (a, e) => a + e, 0 ); const totalPriceBeforeDiscounts = cart.priceBeforeDiscounts + basePrice; const totalPriceAfterDiscounts = cart.priceAfterDiscounts + discountedPrice; return ( setOpenNotificationsModal((isOpened) => !isOpened)} sx={{ cursor: "pointer", borderRadius: "6px", background: openNotificationsModal ? theme.palette.brightPurple.main : theme.palette.background.default, "& .MuiBadge-badge": { background: openNotificationsModal ? theme.palette.background.default : theme.palette.brightPurple.main, color: openNotificationsModal ? theme.palette.brightPurple.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.brightPurple.main, "& .MuiBox-root": { background: theme.palette.brightPurple.main, }, "& .MuiBadge-badge": { background: theme.palette.background.default, color: theme.palette.brightPurple.main, }, "& svg > path:first-child": { fill: "#FFFFFF" }, "& svg > path:last-child": { stroke: "#FFFFFF" }, }, }} > ({ text: "У вас новое сообщение от техподдержки", date: new Date(ticket.updated_at).toLocaleDateString(), watched: ticket.user === ticket.top_message.user_id, }))} /> path:nth-child(1)": { fill: "#FFFFFF" }, "& svg > path:nth-child(2)": { fill: "#FFFFFF" }, "& svg > path:nth-child(3)": { stroke: "#FFFFFF" }, }, }} > {!upMd && ( )} Корзина {cart.services.map((serviceData) => ( ))} Итоговая цена Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель — это текст, который имеет Текст-заполнитель {currencyFormatter.format(totalPriceBeforeDiscounts / 100)} {currencyFormatter.format(totalPriceAfterDiscounts / 100)} navigate("/cart")} sx={{ mt: "25px", backgroundColor: theme.palette.brightPurple.main, }} > Оплатить ); }