2024-01-04 01:15:39 +00:00
|
|
|
|
import { useState, useRef, useLayoutEffect } from "react";
|
2023-05-10 17:35:30 +00:00
|
|
|
|
import ChartIcon from "@icons/ChartIcon";
|
|
|
|
|
import LinkIcon from "@icons/LinkIcon";
|
|
|
|
|
import PencilIcon from "@icons/PencilIcon";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import { Quiz } from "@model/quiz/quiz";
|
2022-12-09 11:48:15 +00:00
|
|
|
|
import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
IconButton,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
|
|
|
|
Popover,
|
|
|
|
|
} from "@mui/material";
|
2023-11-14 13:37:20 +00:00
|
|
|
|
import { deleteQuiz, setEditQuizId } from "@root/quizes/actions";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-01-04 01:15:39 +00:00
|
|
|
|
import { inCart } from "../../pages/Tariffs/Tariffs";
|
|
|
|
|
import { makeRequest } from "@frontend/kitui";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-11-13 18:04:51 +00:00
|
|
|
|
|
2022-12-09 11:48:15 +00:00
|
|
|
|
interface Props {
|
2023-12-16 23:10:24 +00:00
|
|
|
|
quiz: Quiz;
|
|
|
|
|
openCount?: number;
|
|
|
|
|
applicationCount?: number;
|
|
|
|
|
conversionPercent?: number;
|
2022-12-09 11:48:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
export default function QuizCard({
|
|
|
|
|
quiz,
|
|
|
|
|
openCount = 0,
|
|
|
|
|
applicationCount = 0,
|
|
|
|
|
conversionPercent = 0,
|
|
|
|
|
}: Props) {
|
2023-12-16 23:10:24 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
|
|
|
|
const navigate = useNavigate();
|
2023-11-30 06:27:15 +00:00
|
|
|
|
const [subMenuOpen, setSubMenuOpen] = useState<boolean>(false);
|
|
|
|
|
const subMenuRef = useRef<HTMLButtonElement | null>(null);
|
2023-11-13 18:04:51 +00:00
|
|
|
|
|
2023-12-16 23:10:24 +00:00
|
|
|
|
function handleEditClick() {
|
|
|
|
|
setEditQuizId(quiz.backendId);
|
|
|
|
|
navigate("/edit");
|
|
|
|
|
}
|
2022-12-09 11:48:15 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const questionCount = useRef(quiz.questions_count.toString() || "");
|
2023-12-30 18:51:16 +00:00
|
|
|
|
|
2024-01-04 01:15:39 +00:00
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
const pay = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await makeRequest({
|
|
|
|
|
method: "POST",
|
|
|
|
|
url: "https://suiz.pena.digital/customer/cart/pay",
|
|
|
|
|
});
|
|
|
|
|
inCart();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
enqueueSnackbar(
|
|
|
|
|
"Попробуйте снова купить тариф после зачисления средств",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
const fromSquiz = params.get("action");
|
|
|
|
|
if (fromSquiz === "fromhub") {
|
2024-01-04 18:36:26 +00:00
|
|
|
|
window.history.replaceState(null, "", "/list");
|
2024-01-04 01:15:39 +00:00
|
|
|
|
pay();
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
2023-12-16 23:10:24 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
backgroundColor: "white",
|
|
|
|
|
width: "560px",
|
|
|
|
|
height: "280px",
|
|
|
|
|
p: "20px",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
boxSizing: "border-box",
|
|
|
|
|
boxShadow: `0px 100px 309px rgba(210, 208, 225, 0.24),
|
2022-12-09 11:48:15 +00:00
|
|
|
|
0px 41.7776px 129.093px rgba(210, 208, 225, 0.172525),
|
|
|
|
|
0px 22.3363px 69.0192px rgba(210, 208, 225, 0.143066),
|
|
|
|
|
0px 12.5216px 38.6916px rgba(210, 208, 225, 0.12),
|
|
|
|
|
0px 6.6501px 20.5488px rgba(210, 208, 225, 0.0969343),
|
|
|
|
|
0px 2.76726px 8.55082px rgba(210, 208, 225, 0.0674749)`,
|
2023-12-16 23:10:24 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-19 23:08:33 +00:00
|
|
|
|
<Typography
|
2023-12-31 02:53:25 +00:00
|
|
|
|
sx={{
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
widows: "100%",
|
2024-01-04 15:18:29 +00:00
|
|
|
|
maxWidth: "280px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}}
|
2023-12-19 23:08:33 +00:00
|
|
|
|
variant="h5"
|
|
|
|
|
>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
{quiz.name.length === 0 || quiz.name === " "
|
|
|
|
|
? quiz.config.type === "form"
|
|
|
|
|
? "Анкета " + questionCount.current
|
|
|
|
|
: "Квиз " + questionCount.current
|
|
|
|
|
: quiz.name}
|
2023-12-19 23:08:33 +00:00
|
|
|
|
</Typography>
|
2023-12-16 23:10:24 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
mt: "10px",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LinkIcon bgcolor="#EEE4FC" color={theme.palette.brightPurple.main} />
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<Typography color={theme.palette.grey3.main}>
|
|
|
|
|
быстрая ссылка ...
|
|
|
|
|
</Typography>
|
2023-12-16 23:10:24 +00:00
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
mt: "32px",
|
|
|
|
|
mr: "22px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ flex: "1 1 0" }}>
|
|
|
|
|
<Typography variant="h5">{openCount}</Typography>
|
|
|
|
|
<Typography color={theme.palette.grey3.main}>Открытий</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ flex: "1 1 0" }}>
|
|
|
|
|
<Typography variant="h5">{applicationCount}</Typography>
|
|
|
|
|
<Typography color={theme.palette.grey3.main}>Заявок</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ flex: "1 1 0" }}>
|
|
|
|
|
<Typography variant="h5">{conversionPercent} %</Typography>
|
|
|
|
|
<Typography color={theme.palette.grey3.main}>Конверсия</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
mt: "auto",
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: isMobile ? "10px" : "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-29 23:11:37 +00:00
|
|
|
|
{/* <Button
|
2023-12-16 23:10:24 +00:00
|
|
|
|
variant="contained"
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "10px 39px",
|
|
|
|
|
}}
|
2023-10-18 12:46:59 +00:00
|
|
|
|
>
|
2023-12-16 23:10:24 +00:00
|
|
|
|
Заявки
|
2023-12-29 23:11:37 +00:00
|
|
|
|
</Button> */}
|
2023-12-16 23:10:24 +00:00
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
startIcon={<PencilIcon />}
|
|
|
|
|
onClick={handleEditClick}
|
|
|
|
|
sx={{
|
|
|
|
|
padding: isMobile ? "10px" : "10px 20px",
|
|
|
|
|
minWidth: "unset",
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
"& .MuiButton-startIcon": {
|
|
|
|
|
marginRight: isMobile ? 0 : "4px",
|
|
|
|
|
marginLeft: 0,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{isMobile ? "" : "Редактировать"}
|
|
|
|
|
</Button>
|
2023-12-29 23:11:37 +00:00
|
|
|
|
{/* <Button
|
2023-12-16 23:10:24 +00:00
|
|
|
|
variant="outlined"
|
|
|
|
|
startIcon={<ChartIcon />}
|
|
|
|
|
sx={{
|
|
|
|
|
minWidth: "46px",
|
|
|
|
|
padding: "10px 10px",
|
|
|
|
|
"& .MuiButton-startIcon": {
|
|
|
|
|
mr: 0,
|
|
|
|
|
ml: 0,
|
|
|
|
|
},
|
|
|
|
|
}}
|
2023-12-29 23:11:37 +00:00
|
|
|
|
/> */}
|
2023-12-16 23:10:24 +00:00
|
|
|
|
<IconButton
|
|
|
|
|
ref={subMenuRef}
|
|
|
|
|
sx={{
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
ml: "auto",
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => setSubMenuOpen(true)}
|
|
|
|
|
data-cy="delete-quiz"
|
|
|
|
|
>
|
|
|
|
|
<MoreHorizIcon sx={{ transform: "scale(1.75)" }} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Popover
|
|
|
|
|
open={subMenuOpen}
|
|
|
|
|
anchorEl={subMenuRef.current}
|
|
|
|
|
onClose={() => setSubMenuOpen(false)}
|
|
|
|
|
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
|
|
|
|
>
|
|
|
|
|
<Box onClick={() => setSubMenuOpen(false)}>
|
|
|
|
|
{/* <Button
|
2023-11-30 06:27:15 +00:00
|
|
|
|
sx={{
|
|
|
|
|
display: "block",
|
|
|
|
|
width: "100%",
|
|
|
|
|
padding: "15px 30px",
|
|
|
|
|
}}
|
|
|
|
|
onClick={()=>{}}
|
|
|
|
|
>
|
|
|
|
|
Копировать
|
2023-12-14 16:50:02 +00:00
|
|
|
|
</Button> */}
|
2023-12-16 23:10:24 +00:00
|
|
|
|
<Button
|
|
|
|
|
sx={{
|
|
|
|
|
display: "block",
|
|
|
|
|
width: "100%",
|
|
|
|
|
padding: "15px 30px",
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => deleteQuiz(quiz.id)}
|
|
|
|
|
>
|
|
|
|
|
Удалить
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Popover>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2023-10-18 12:46:59 +00:00
|
|
|
|
}
|