frontPanel/src/ui_kit/FloatingSupportChat/FloatingSupportChat.tsx

138 lines
3.8 KiB
TypeScript
Raw Normal View History

import {
Box,
Fab,
useTheme,
useMediaQuery,
Slide,
Dialog,
2024-02-14 16:47:30 +00:00
Badge,
} from "@mui/material";
import { ReactNode, useState } from "react";
2024-02-09 14:04:38 +00:00
import CircleDoubleDown from "./QuestionIcon";
import * as React from "react";
2024-02-06 14:39:02 +00:00
import Chat from "./Chat";
import { TransitionProps } from "@mui/material/transitions";
import { useLocation } from "react-router-dom";
2024-02-14 16:47:30 +00:00
import { useUnauthTicketStore } from "@root/unauthTicket";
2024-02-06 14:39:02 +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%" },
},
};
const Transition = React.forwardRef(function Transition(
props: TransitionProps & {
children: ReactNode;
},
ref: React.Ref<unknown>,
) {
return <Slide direction="up" ref={ref} {...props} />;
});
2024-02-06 14:39:02 +00:00
export default function FloatingSupportChat() {
const [isChatOpened, setIsChatOpened] = useState<boolean>(false);
2024-02-09 14:04:38 +00:00
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(800));
const [open, setOpen] = useState(false);
const location = useLocation();
const locationChat = location.pathname;
2024-02-14 16:47:30 +00:00
const { messages } = useUnauthTicketStore((state) => state);
2024-02-06 14:39:02 +00:00
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
2024-02-06 14:39:02 +00:00
return (
<Box
sx={{
position: "fixed",
right: "20px",
bottom: locationChat !== "/edit" ? "10px" : "100px",
2024-02-06 14:39:02 +00:00
display: "flex",
flexDirection: "column",
gap: "8px",
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
open={isChatOpened}
sx={{ alignSelf: "start", width: "clamp(200px, 100%, 400px)" }}
/>
<Dialog
fullScreen
open={open}
onClose={handleClose}
TransitionComponent={Transition}
>
2024-02-17 17:31:39 +00:00
<Chat open={open} onclickArrow={handleClose} />
</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"}
onClick={() => {
if (isMobile) {
2024-02-17 17:31:39 +00:00
handleClickOpen();
} else {
setIsChatOpened((prev) => !prev);
}
}}
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
badgeContent={messages.filter(({ shown }) => shown.me !== 1).length}
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%)",
},
}}
>
<CircleDoubleDown isUp={isChatOpened} />
</Badge>
2024-02-06 14:39:02 +00:00
</Fab>
</Box>
);
}