front-hub/src/pages/Support/Support.tsx

90 lines
3.2 KiB
TypeScript
Raw Normal View History

2022-12-22 12:43:14 +00:00
import { Typography, Box, useTheme, useMediaQuery, IconButton } from "@mui/material";
2022-11-25 18:52:46 +00:00
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import { useParams } from "react-router-dom";
import SectionWrapper from "@components/SectionWrapper";
import ComplexNavText from "@components/ComplexNavText";
2023-04-13 16:48:17 +00:00
import SupportChat from "./SupportChat";
2022-12-15 14:09:07 +00:00
import CreateTicket from "./CreateTicket";
2023-04-06 08:07:48 +00:00
import TicketList from "./TicketList/TicketList";
2023-06-06 13:13:58 +00:00
import { useCallback } from "react";
2023-06-24 18:16:02 +00:00
import { Ticket, getMessageFromFetchError, useToken } from "@frontend/kitui";
2023-06-06 13:13:58 +00:00
import { updateTickets, setTicketCount, clearTickets, useTicketStore } from "@root/stores/tickets";
2023-03-31 15:01:43 +00:00
import { enqueueSnackbar } from "notistack";
2023-06-06 13:13:58 +00:00
import { useSSESubscription, useTickets } from "@frontend/kitui";
2022-11-23 11:46:04 +00:00
2023-03-30 12:33:28 +00:00
2022-11-23 11:46:04 +00:00
export default function Support() {
2023-03-30 12:33:28 +00:00
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
const ticketId = useParams().ticketId;
2023-04-06 15:10:22 +00:00
const ticketApiPage = useTicketStore(state => state.apiPage);
2023-03-31 15:01:43 +00:00
const ticketsPerPage = useTicketStore(state => state.ticketsPerPage);
2023-06-24 18:16:02 +00:00
const token = useToken();
2023-03-31 15:01:43 +00:00
2023-06-06 13:13:58 +00:00
const fetchState = useTickets({
url: "https://hub.pena.digital/heruvym/getTickets",
ticketsPerPage,
ticketApiPage,
onNewTickets: useCallback(result => {
if (result.data) updateTickets(result.data);
setTicketCount(result.count);
}, []),
onError: useCallback((error: Error) => {
2023-06-24 18:16:02 +00:00
const message = getMessageFromFetchError(error);
if (message) enqueueSnackbar(message);
2023-06-06 13:13:58 +00:00
}, [])
});
2023-03-31 15:01:43 +00:00
2023-06-06 13:13:58 +00:00
useSSESubscription<Ticket>({
enabled: Boolean(token),
url: `https://admin.pena.digital/heruvym/subscribe?Authorization=${token}`,
onNewData: updateTickets,
onDisconnect: useCallback(() => {
2023-03-31 15:01:43 +00:00
clearTickets();
2023-06-06 13:13:58 +00:00
}, []),
marker: "ticket"
});
2022-11-23 11:46:04 +00:00
2023-03-30 12:33:28 +00:00
return (
<SectionWrapper
maxWidth="lg"
sx={{
pt: upMd ? "25px" : "20px",
pb: upMd ? "82px" : "43px",
height: "100%",
}}
2022-11-23 11:46:04 +00:00
>
2023-03-30 12:33:28 +00:00
{upMd && <ComplexNavText text1="Все тарифы — " text2="Запрос в службу техподдержки" />}
<Box
sx={{
mt: "20px",
mb: "40px",
display: "flex",
gap: "10px",
}}
>
{!upMd && (
<IconButton sx={{ p: 0, height: "28px", width: "28px", color: "black" }}>
<ArrowBackIcon />
</IconButton>
)}
<Typography variant="h4">Запрос в службу техподдержки</Typography>
</Box>
{ticketId ? (
<SupportChat />
) : (
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: upMd ? "40px" : "60px",
}}
>
<CreateTicket />
2023-06-06 13:13:58 +00:00
<TicketList fetchState={fetchState} />
2023-03-30 12:33:28 +00:00
</Box>
)}
</SectionWrapper>
);
}