diff --git a/src/components/Drawers.tsx b/src/components/Drawers.tsx index aac6dfd..735613f 100644 --- a/src/components/Drawers.tsx +++ b/src/components/Drawers.tsx @@ -51,15 +51,14 @@ export default function Drawers() { (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); + const { tickets, ticketCount, apiPage, ticketsPerPage } = useTicketStore( + (state) => state + ); useTickets({ url: "https://hub.pena.digital/heruvym/getTickets", ticketsPerPage, - ticketApiPage, + ticketApiPage: apiPage, onNewTickets: useCallback((result) => { if (result.data) updateTickets(result.data); setTicketCount(result.count); diff --git a/src/components/Navbar/NavbarCollapsed.tsx b/src/components/Navbar/NavbarCollapsed.tsx index 009b7f3..bff8752 100644 --- a/src/components/Navbar/NavbarCollapsed.tsx +++ b/src/components/Navbar/NavbarCollapsed.tsx @@ -1,9 +1,10 @@ -import { useState, useEffect, useCallback } from "react"; +import { useState, useRef, useEffect, useCallback } from "react"; import { Box, Badge, Drawer, IconButton, useTheme } from "@mui/material"; import { Link } from "react-router-dom"; import { useTickets } from "@frontend/kitui"; import SectionWrapper from "../SectionWrapper"; +import { NotificationsModal } from "../NotificationsModal"; import { useUserStore } from "@root/stores/user"; import { @@ -29,15 +30,18 @@ interface Props { export default function NavbarCollapsed({ isLoggedIn, children }: Props) { const [open, setOpen] = useState(false); + const [openNotificationsModal, setOpenNotificationsModal] = + useState(false); + const bellRef = useRef(null); 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 { ticketCount, tickets, apiPage, ticketsPerPage } = useTicketStore( + (state) => state + ); useTickets({ url: "https://hub.pena.digital/heruvym/getTickets", ticketsPerPage, - ticketApiPage, + ticketApiPage: apiPage, onNewTickets: useCallback((result) => { if (result.data) updateTickets(result.data); setTicketCount(result.count); @@ -134,6 +138,8 @@ export default function NavbarCollapsed({ isLoggedIn, children }: Props) { setOpenNotificationsModal((isOpened) => !isOpened)} aria-label="cart" sx={{ width: "30px", @@ -168,6 +174,16 @@ export default function NavbarCollapsed({ isLoggedIn, children }: Props) { + ({ + text: "У вас новое сообщение от техподдержки", + date: new Date(ticket.updated_at).toLocaleDateString(), + watched: ticket.user === ticket.top_message.user_id, + }))} + /> diff --git a/src/components/NotificationsModal.tsx b/src/components/NotificationsModal.tsx index 2c34c32..b99650a 100644 --- a/src/components/NotificationsModal.tsx +++ b/src/components/NotificationsModal.tsx @@ -1,4 +1,11 @@ -import { Popover, List, ListItem, Typography } from "@mui/material"; +import { + Popover, + List, + ListItem, + Typography, + useTheme, + useMediaQuery, +} from "@mui/material"; type Notification = { text: string; @@ -19,6 +26,9 @@ export const NotificationsModal = ({ anchorElement, notifications, }: NotificationsModalProps) => { + const theme = useTheme(); + const isMobile = useMediaQuery(theme.breakpoints.down(650)); + return ( {date}