2024-04-25 06:37:48 +00:00
|
|
|
|
import type { ReactNode, Ref } from "react";
|
|
|
|
|
import { forwardRef, useEffect, useState } from "react";
|
2024-02-10 14:58:36 +00:00
|
|
|
|
import {
|
2024-04-25 06:37:48 +00:00
|
|
|
|
Badge,
|
2024-02-10 14:58:36 +00:00
|
|
|
|
Box,
|
|
|
|
|
Dialog,
|
2024-04-25 06:37:48 +00:00
|
|
|
|
Fab,
|
2024-03-09 21:01:57 +00:00
|
|
|
|
Modal,
|
2024-04-25 06:37:48 +00:00
|
|
|
|
Slide,
|
2024-03-09 21:01:57 +00:00
|
|
|
|
Typography,
|
2024-04-25 06:37:48 +00:00
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2024-02-10 14:58:36 +00:00
|
|
|
|
} from "@mui/material";
|
2024-02-09 14:04:38 +00:00
|
|
|
|
import CircleDoubleDown from "./QuestionIcon";
|
2024-02-06 14:39:02 +00:00
|
|
|
|
import Chat from "./Chat";
|
2024-02-10 14:58:36 +00:00
|
|
|
|
import { TransitionProps } from "@mui/material/transitions";
|
|
|
|
|
import { useLocation } from "react-router-dom";
|
2024-03-06 11:13:28 +00:00
|
|
|
|
import { useTicketStore } from "@root/ticket";
|
|
|
|
|
import { useUserStore } from "@root/user";
|
2024-04-25 06:37:48 +00:00
|
|
|
|
import { TicketMessage } from "@frontend/kitui";
|
2024-03-14 15:13:01 +00:00
|
|
|
|
|
2024-02-09 14:04:38 +00:00
|
|
|
|
const animation = {
|
|
|
|
|
"@keyframes runningStripe": {
|
|
|
|
|
"0%": { left: "10%", backgroundColor: "transparent" },
|
|
|
|
|
"10%": { backgroundColor: "#ffffff" },
|
|
|
|
|
"50%": { backgroundColor: "#ffffff", transform: "translate(400px, 0)" },
|
|
|
|
|
"80%": { backgroundColor: "#ffffff" },
|
|
|
|
|
"100%": { backgroundColor: "transparent", boxShadow: "none", left: "100%" },
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-14 15:13:01 +00:00
|
|
|
|
const Transition = forwardRef(function Transition(
|
2024-02-10 14:58:36 +00:00
|
|
|
|
props: TransitionProps & {
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
},
|
2024-03-14 15:13:01 +00:00
|
|
|
|
ref: Ref<unknown>,
|
2024-02-10 14:58:36 +00:00
|
|
|
|
) {
|
|
|
|
|
return <Slide direction="up" ref={ref} {...props} />;
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-06 11:13:28 +00:00
|
|
|
|
interface Props {
|
|
|
|
|
isChatOpened: boolean;
|
|
|
|
|
handleChatClickOpen: () => void;
|
|
|
|
|
handleChatClickClose: () => void;
|
|
|
|
|
handleChatClickSwitch: () => void;
|
2024-03-09 21:01:57 +00:00
|
|
|
|
sendMessage: (a: string) => Promise<boolean>;
|
2025-07-05 00:27:58 +00:00
|
|
|
|
sendFile: (a: File | undefined) => Promise<void>;
|
2024-03-09 21:01:57 +00:00
|
|
|
|
modalWarningType: string | null;
|
|
|
|
|
setModalWarningType: any;
|
2024-04-25 06:37:48 +00:00
|
|
|
|
greetingMessage: TicketMessage;
|
2024-03-06 11:13:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function FloatingSupportChat({
|
|
|
|
|
isChatOpened,
|
|
|
|
|
handleChatClickOpen,
|
|
|
|
|
handleChatClickClose,
|
|
|
|
|
handleChatClickSwitch,
|
|
|
|
|
sendMessage,
|
|
|
|
|
sendFile,
|
2024-03-09 21:01:57 +00:00
|
|
|
|
modalWarningType,
|
|
|
|
|
setModalWarningType,
|
2024-04-25 06:37:48 +00:00
|
|
|
|
greetingMessage,
|
2024-03-06 11:13:28 +00:00
|
|
|
|
}: Props) {
|
2024-03-14 15:13:01 +00:00
|
|
|
|
const [monitorType, setMonitorType] = useState<"desktop" | "mobile" | "">("");
|
2024-02-09 14:04:38 +00:00
|
|
|
|
const theme = useTheme();
|
2024-03-14 15:13:01 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(800));
|
2024-02-10 14:58:36 +00:00
|
|
|
|
const location = useLocation();
|
|
|
|
|
const locationChat = location.pathname;
|
2024-03-06 11:13:28 +00:00
|
|
|
|
const user = useUserStore((state) => state.user?._id);
|
2024-02-06 14:39:02 +00:00
|
|
|
|
|
2024-03-09 21:01:57 +00:00
|
|
|
|
const { messages } = useTicketStore(
|
|
|
|
|
(state) => state[user ? "authData" : "unauthData"],
|
|
|
|
|
);
|
2024-03-06 11:13:28 +00:00
|
|
|
|
|
2024-03-14 15:13:01 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
const onResize = () => {
|
|
|
|
|
if (document.fullscreenElement) {
|
|
|
|
|
setMonitorType(isMobile ? "mobile" : "desktop");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMonitorType("");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener("resize", onResize);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener("resize", onResize);
|
|
|
|
|
};
|
|
|
|
|
}, [isMobile]);
|
2024-02-10 14:58:36 +00:00
|
|
|
|
|
2024-02-06 14:39:02 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "fixed",
|
|
|
|
|
right: "20px",
|
2024-02-10 14:58:36 +00:00
|
|
|
|
bottom: locationChat !== "/edit" ? "10px" : "100px",
|
2024-02-06 14:39:02 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "8px",
|
2024-02-10 14:58:36 +00:00
|
|
|
|
width: isChatOpened ? "clamp(200px, 100% - 40px, 454px)" : "64px",
|
2024-02-06 14:39:02 +00:00
|
|
|
|
zIndex: 10,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-02-14 16:47:30 +00:00
|
|
|
|
<Chat
|
2024-03-14 15:13:01 +00:00
|
|
|
|
open={isChatOpened && (monitorType === "desktop" || !isMobile)}
|
2024-02-14 16:47:30 +00:00
|
|
|
|
sx={{ alignSelf: "start", width: "clamp(200px, 100%, 400px)" }}
|
2024-03-06 11:13:28 +00:00
|
|
|
|
sendMessage={sendMessage}
|
|
|
|
|
sendFile={sendFile}
|
2024-04-25 06:37:48 +00:00
|
|
|
|
greetingMessage={greetingMessage}
|
2024-02-14 16:47:30 +00:00
|
|
|
|
/>
|
2024-02-10 14:58:36 +00:00
|
|
|
|
<Dialog
|
|
|
|
|
fullScreen
|
2024-03-14 15:13:01 +00:00
|
|
|
|
open={isChatOpened && (monitorType === "mobile" || isMobile)}
|
2024-03-06 11:13:28 +00:00
|
|
|
|
onClose={handleChatClickClose}
|
2024-02-10 14:58:36 +00:00
|
|
|
|
TransitionComponent={Transition}
|
|
|
|
|
>
|
2024-03-09 21:01:57 +00:00
|
|
|
|
<Chat
|
2024-03-14 15:13:01 +00:00
|
|
|
|
open={isChatOpened && (monitorType === "mobile" || isMobile)}
|
2024-03-09 21:01:57 +00:00
|
|
|
|
onclickArrow={handleChatClickClose}
|
|
|
|
|
sendMessage={sendMessage}
|
|
|
|
|
sendFile={sendFile}
|
2024-04-25 06:37:48 +00:00
|
|
|
|
greetingMessage={greetingMessage}
|
2024-03-09 21:01:57 +00:00
|
|
|
|
/>
|
2024-02-10 14:58:36 +00:00
|
|
|
|
</Dialog>
|
2024-02-06 14:39:02 +00:00
|
|
|
|
<Fab
|
|
|
|
|
disableRipple
|
|
|
|
|
sx={{
|
|
|
|
|
position: "relative",
|
|
|
|
|
backgroundColor: "rgba(255, 255, 255, 0.7)",
|
2024-02-09 14:04:38 +00:00
|
|
|
|
borderRadius: "50%",
|
2024-02-06 14:39:02 +00:00
|
|
|
|
alignSelf: "end",
|
2024-02-09 14:04:38 +00:00
|
|
|
|
padding: "0px",
|
2024-02-06 14:39:02 +00:00
|
|
|
|
overflow: "hidden",
|
2024-02-09 14:04:38 +00:00
|
|
|
|
height: "54px",
|
|
|
|
|
width: "54px",
|
|
|
|
|
transform: !isMobile ? "scale(1.2)" : null,
|
2024-02-06 14:39:02 +00:00
|
|
|
|
"&:hover": {
|
|
|
|
|
background: "rgba(255, 255, 255, 0.7)",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
variant={"extended"}
|
2024-02-10 14:58:36 +00:00
|
|
|
|
onClick={() => {
|
2024-03-09 21:01:57 +00:00
|
|
|
|
handleChatClickSwitch();
|
2024-02-10 14:58:36 +00:00
|
|
|
|
}}
|
2024-02-06 14:39:02 +00:00
|
|
|
|
>
|
|
|
|
|
{!isChatOpened && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
bgcolor: "#FFFFFF",
|
|
|
|
|
height: "100px",
|
|
|
|
|
width: "25px",
|
|
|
|
|
animation: "runningStripe linear 3s infinite",
|
|
|
|
|
transform:
|
|
|
|
|
" skew(-10deg) rotate(70deg) skewX(20deg) skewY(10deg)",
|
|
|
|
|
boxShadow: "0px 3px 12px rgba(126, 42, 234, 0.1)",
|
|
|
|
|
opacity: "0.4",
|
|
|
|
|
...animation,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-02-14 16:47:30 +00:00
|
|
|
|
<Badge
|
2024-03-09 21:01:57 +00:00
|
|
|
|
badgeContent={
|
|
|
|
|
messages.filter(({ shown }) => shown?.me !== 1).length || 0
|
|
|
|
|
}
|
2024-02-14 16:47:30 +00:00
|
|
|
|
sx={{
|
|
|
|
|
"& .MuiBadge-badge": {
|
|
|
|
|
display: isChatOpened ? "none" : "flex",
|
|
|
|
|
color: "#FFFFFF",
|
|
|
|
|
background: theme.palette.brightPurple.main,
|
|
|
|
|
top: "4px",
|
|
|
|
|
right: "4px",
|
|
|
|
|
transform: "scale(0.8) translate(50%, -50%)",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-03-06 11:13:28 +00:00
|
|
|
|
<CircleDoubleDown />
|
2024-02-14 16:47:30 +00:00
|
|
|
|
</Badge>
|
2024-02-06 14:39:02 +00:00
|
|
|
|
</Fab>
|
2024-03-09 21:01:57 +00:00
|
|
|
|
<Modal
|
|
|
|
|
open={modalWarningType !== null}
|
|
|
|
|
onClose={() => setModalWarningType(null)}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
width: isMobile ? 300 : 400,
|
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
|
borderRadius: 3,
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
p: 4,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CurrentModal status={modalWarningType} />
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
2024-02-06 14:39:02 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-03-09 21:01:57 +00:00
|
|
|
|
const CurrentModal = ({ status }: { status: ["errorType" | "errorSize"] }) => {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case null:
|
|
|
|
|
return null;
|
|
|
|
|
case "errorType":
|
|
|
|
|
return <Typography>Выбран некорректный тип файла</Typography>;
|
|
|
|
|
case "errorSize":
|
|
|
|
|
return (
|
|
|
|
|
<Typography>Файл слишком большой. Максимальный размер 50 МБ</Typography>
|
|
|
|
|
);
|
|
|
|
|
default:
|
|
|
|
|
return <></>;
|
|
|
|
|
}
|
|
|
|
|
};
|