2023-03-20 15:27:42 +00:00
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { Box, Button, useTheme } from "@mui/material";
|
|
|
|
|
import SearchOutlinedIcon from '@mui/icons-material/SearchOutlined';
|
|
|
|
|
import HighlightOffOutlinedIcon from '@mui/icons-material/HighlightOffOutlined';
|
|
|
|
|
import { enqueueSnackbar } from 'notistack';
|
2023-03-21 12:59:46 +00:00
|
|
|
|
import { GetTicketsRequest, Ticket } from "@root/model/ticket";
|
2023-03-22 09:33:17 +00:00
|
|
|
|
import { setTickets, addOrUpdateTicket } from "@root/stores/tickets";
|
2023-03-21 12:59:46 +00:00
|
|
|
|
import { getTickets, subscribeToAllTickets } from "@root/api/tickets";
|
2023-03-20 15:27:42 +00:00
|
|
|
|
import Chat from "./Chat";
|
2023-03-22 09:33:17 +00:00
|
|
|
|
import TicketList from "./TicketList";
|
2023-03-20 15:27:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function Support() {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
|
|
useEffect(function fetchTickets() {
|
|
|
|
|
const getTicketsBody: GetTicketsRequest = {
|
|
|
|
|
amt: 10,
|
|
|
|
|
page: 0,
|
|
|
|
|
status: "open",
|
|
|
|
|
};
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
|
2023-03-21 14:43:21 +00:00
|
|
|
|
setTickets([]);
|
2023-03-21 12:59:46 +00:00
|
|
|
|
getTickets({
|
2023-03-20 15:27:42 +00:00
|
|
|
|
body: getTicketsBody,
|
|
|
|
|
signal: controller.signal,
|
2023-03-21 12:59:46 +00:00
|
|
|
|
}).then(result => {
|
2023-03-20 15:27:42 +00:00
|
|
|
|
console.log("GetTicketsResponse", result);
|
|
|
|
|
setTickets(result.data);
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
console.log("Error fetching tickets", error);
|
|
|
|
|
enqueueSnackbar(error.message);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => controller.abort();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(function subscribeToTickets() {
|
|
|
|
|
const token = localStorage.getItem("AT");
|
|
|
|
|
if (!token) return;
|
|
|
|
|
|
|
|
|
|
const unsubscribe = subscribeToAllTickets({
|
|
|
|
|
accessToken: token,
|
|
|
|
|
onMessage(event) {
|
2023-03-21 12:59:46 +00:00
|
|
|
|
console.log("SSE: ticket received:", event.data);
|
2023-03-20 15:27:42 +00:00
|
|
|
|
try {
|
|
|
|
|
const newTicket = JSON.parse(event.data) as Ticket;
|
|
|
|
|
addOrUpdateTicket(newTicket);
|
|
|
|
|
} catch (error) {
|
2023-03-21 12:59:46 +00:00
|
|
|
|
console.log("Error parsing ticket SSE", error);
|
2023-03-20 15:27:42 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onError(event) {
|
|
|
|
|
console.log("SSE Error:", event);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
unsubscribe();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
display: "flex",
|
2023-03-21 12:59:46 +00:00
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
height: "600px",
|
2023-03-20 15:27:42 +00:00
|
|
|
|
}}>
|
|
|
|
|
<Chat />
|
|
|
|
|
<Box sx={{
|
|
|
|
|
width: "max(40%, 460px)",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}>
|
|
|
|
|
<Box sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: theme.palette.grayDark.main,
|
|
|
|
|
borderRadius: "3px",
|
|
|
|
|
padding: "10px"
|
|
|
|
|
}}>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: theme.palette.grayDark.main,
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "45px",
|
|
|
|
|
fontSize: "15px",
|
|
|
|
|
fontWeight: "normal",
|
|
|
|
|
textTransform: "capitalize",
|
|
|
|
|
"&:hover": {
|
|
|
|
|
backgroundColor: theme.palette.menu.main
|
|
|
|
|
}
|
|
|
|
|
}}>
|
|
|
|
|
Поиск
|
|
|
|
|
<SearchOutlinedIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="text"
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "35px",
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
fontWeight: "normal",
|
|
|
|
|
color: theme.palette.secondary.main,
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: theme.palette.golden.main,
|
|
|
|
|
borderRadius: 0,
|
|
|
|
|
"&:hover": {
|
|
|
|
|
backgroundColor: theme.palette.menu.main
|
|
|
|
|
}
|
|
|
|
|
}}>
|
|
|
|
|
ЗАКРЫТЬ ТИКЕТ
|
|
|
|
|
<HighlightOffOutlinedIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
2023-03-22 09:33:17 +00:00
|
|
|
|
<TicketList />
|
2023-03-20 15:27:42 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|