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

110 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-08-04 14:49:05 +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";
2023-08-04 14:49:05 +00:00
import { Link, useParams } from "react-router-dom";
import SectionWrapper from "@components/SectionWrapper";
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-08-04 14:49:05 +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
export default function Support() {
2023-08-04 14:49:05 +00:00
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
const ticketId = useParams().ticketId;
const ticketApiPage = useTicketStore((state) => state.apiPage);
const ticketsPerPage = useTicketStore((state) => state.ticketsPerPage);
const token = useToken();
2023-03-31 15:01:43 +00:00
2023-08-04 14:49:05 +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) => {
const message = getMessageFromFetchError(error);
if (message) enqueueSnackbar(message);
}, []),
});
2023-03-31 15:01:43 +00:00
2023-08-04 14:49:05 +00:00
useSSESubscription<Ticket>({
enabled: Boolean(token),
url: `https://admin.pena.digital/heruvym/subscribe?Authorization=${token}`,
onNewData: updateTickets,
onDisconnect: useCallback(() => {
clearTickets();
}, []),
marker: "ticket",
});
2022-11-23 11:46:04 +00:00
2023-08-04 14:49:05 +00:00
return (
<SectionWrapper
maxWidth="lg"
sx={{
pt: upMd ? "25px" : "20px",
pb: upMd ? "82px" : "20px",
height: "calc(100vh - 51px)",
maxHeight: "calc(100vh - 51px)",
}}
>
<Box
sx={{
mt: "20px",
mb: "40px",
display: "flex",
gap: "10px",
}}
>
<Link
to="/support"
style={{
textDecoration: "none",
display: "flex",
alignItems: "center",
columnGap: "10px",
color: theme.palette.common.black,
}}
>
<IconButton
sx={{ p: 0, height: "28px", width: "28px", color: "black" }}
>
<ArrowBackIcon />
</IconButton>
<Typography variant="h4">Запрос в службу техподдержки</Typography>
</Link>
</Box>
{ticketId ? (
<SupportChat />
) : (
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: upMd ? "40px" : "60px",
}}
2022-11-23 11:46:04 +00:00
>
2023-08-04 14:49:05 +00:00
<CreateTicket />
<TicketList fetchState={fetchState} />
</Box>
)}
</SectionWrapper>
);
}