adminFront/src/pages/dashboard/Content/Support/Support.tsx

62 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-03-23 11:32:09 +00:00
import { Box, useMediaQuery, useTheme } from "@mui/material";
2023-03-29 10:31:02 +00:00
import Chat from "./Chat/Chat";
2023-03-23 11:32:09 +00:00
import Collapse from "./Collapse";
2023-03-29 10:31:02 +00:00
import TicketList from "./TicketList/TicketList";
2023-08-02 11:36:50 +00:00
import { Ticket } from "@root/model/ticket";
2023-08-29 12:07:00 +00:00
import { clearTickets, setTicketsFetchState, updateTickets, useTicketStore } from "@root/stores/tickets";
2023-03-29 10:57:33 +00:00
import { enqueueSnackbar } from "notistack";
import { clearMessageState } from "@root/stores/messages";
2023-08-29 12:07:00 +00:00
import { getMessageFromFetchError, useSSESubscription, useTicketsFetcher, useToken } from "@frontend/kitui";
2023-03-20 15:27:42 +00:00
export default function Support() {
2023-08-02 11:36:50 +00:00
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
const ticketsPerPage = useTicketStore((state) => state.ticketsPerPage);
const ticketApiPage = useTicketStore((state) => state.apiPage);
const token = useToken();
2023-08-29 12:07:00 +00:00
useTicketsFetcher({
2024-01-23 18:31:02 +00:00
url: process.env.REACT_APP_DOMAIN + "/heruvym/getTickets",
2023-08-02 11:36:50 +00:00
ticketsPerPage,
ticketApiPage,
2023-08-29 12:07:00 +00:00
onSuccess: result => {
2023-08-02 11:36:50 +00:00
if (result.data) updateTickets(result.data);
2023-05-24 14:20:54 +00:00
},
2023-08-02 11:36:50 +00:00
onError: (error: Error) => {
const message = getMessageFromFetchError(error);
if (message) enqueueSnackbar(message);
2023-05-24 14:20:54 +00:00
},
2023-08-29 12:07:00 +00:00
onFetchStateChange: setTicketsFetchState,
2023-08-02 11:36:50 +00:00
});
useSSESubscription<Ticket>({
enabled: Boolean(token),
2024-01-23 18:31:02 +00:00
url: process.env.REACT_APP_DOMAIN + `/heruvym/subscribe?Authorization=${token}`,
2023-08-02 11:36:50 +00:00
onNewData: updateTickets,
onDisconnect: () => {
clearMessageState();
clearTickets();
},
marker: "ticket"
});
return (
<Box
sx={{
display: "flex",
width: "100%",
flexDirection: upMd ? "row" : "column",
gap: "12px",
}}
>
{!upMd && (
<Collapse headerText="Тикеты">
2023-08-29 12:07:00 +00:00
<TicketList />
2023-08-02 11:36:50 +00:00
</Collapse>
)}
<Chat />
2023-08-29 12:07:00 +00:00
{upMd && <TicketList />}
2023-08-02 11:36:50 +00:00
</Box>
);
2023-05-24 14:20:54 +00:00
}