2024-11-14 21:29:28 +00:00
|
|
|
import { useEffect, useMemo } from "react";
|
2024-04-17 13:27:29 +00:00
|
|
|
import { Box, Button, Link, Typography, useTheme } from "@mui/material";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-05-06 13:47:19 +00:00
|
|
|
import { useQuizViewStore } from "@/stores/quizView";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-05-06 13:47:19 +00:00
|
|
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
2024-05-31 17:56:17 +00:00
|
|
|
import { useQuizSettings } from "@contexts/QuizDataContext";
|
2024-05-06 13:47:19 +00:00
|
|
|
|
|
|
|
import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals";
|
|
|
|
import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals";
|
2024-04-03 12:42:12 +00:00
|
|
|
import { DESIGN_LIST } from "@/utils/designList";
|
2024-05-06 13:47:19 +00:00
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
|
|
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
|
|
|
|
|
|
|
import type { QuizQuestionResult } from "@/model/questionTypes/result";
|
2024-06-17 14:12:53 +00:00
|
|
|
import QuizVideo from "@/ui_kit/VideoIframe/VideoIframe";
|
2024-10-23 13:23:35 +00:00
|
|
|
import { TextAccordion } from "./tools/TextAccordion";
|
|
|
|
import { PointSystemResultList } from "./PointSystemResultList";
|
2024-10-23 16:18:29 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
2024-10-23 19:48:26 +00:00
|
|
|
import { sendFC, sendResult } from "@/api/quizRelase";
|
2024-10-24 12:50:24 +00:00
|
|
|
import { isProduction } from "@/utils/defineDomain";
|
2025-04-20 15:16:22 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-01-30 16:49:33 +00:00
|
|
|
|
2023-12-16 14:55:56 +00:00
|
|
|
type ResultFormProps = {
|
2024-04-17 13:27:29 +00:00
|
|
|
resultQuestion: QuizQuestionResult;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
2024-02-08 13:42:31 +00:00
|
|
|
|
2024-04-03 12:42:12 +00:00
|
|
|
export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
|
2024-04-17 13:27:29 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
const isMobile = useRootContainerSize() < 650;
|
|
|
|
const isTablet = useRootContainerSize() < 1000;
|
2024-10-23 19:15:05 +00:00
|
|
|
const { settings, show_badge, quizId, questions, preview } = useQuizSettings();
|
2024-05-31 16:41:18 +00:00
|
|
|
const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep);
|
2024-10-23 19:15:05 +00:00
|
|
|
//Список засчитанных баллов для балловых квизов
|
|
|
|
const pointsSum = useQuizViewStore((state) => state.pointsSum);
|
2024-04-17 13:27:29 +00:00
|
|
|
const spec = settings.cfg.spec;
|
2024-05-06 13:47:19 +00:00
|
|
|
const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber);
|
|
|
|
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
2025-04-20 15:16:22 +00:00
|
|
|
const { t } = useTranslation();
|
2024-05-05 22:07:15 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-05-11 12:55:58 +00:00
|
|
|
vkMetrics.resultIdShown(resultQuestion.id);
|
|
|
|
yandexMetrics.resultIdShown(resultQuestion.id);
|
2024-06-02 10:34:14 +00:00
|
|
|
}, [resultQuestion.id, vkMetrics, yandexMetrics]);
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-10-23 16:18:29 +00:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
if (!settings.cfg.showfc) {
|
|
|
|
try {
|
|
|
|
await sendFC({
|
|
|
|
questionId: resultQuestion.id,
|
|
|
|
body: {},
|
|
|
|
qid: quizId,
|
|
|
|
preview,
|
|
|
|
});
|
|
|
|
|
|
|
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
|
|
|
localStorage.setItem("sessions", JSON.stringify({ ...sessions, [quizId]: new Date().getTime() }));
|
|
|
|
} catch (e) {
|
2025-04-20 15:16:22 +00:00
|
|
|
enqueueSnackbar(t("The request could not be sent"));
|
2024-10-23 16:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
2024-10-23 19:48:26 +00:00
|
|
|
if (Boolean(settings.cfg.score)) {
|
|
|
|
try {
|
|
|
|
await sendResult({
|
|
|
|
questionId: resultQuestion.id,
|
|
|
|
pointsSum,
|
|
|
|
qid: quizId,
|
|
|
|
preview,
|
|
|
|
});
|
|
|
|
|
|
|
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
|
|
|
localStorage.setItem("sessions", JSON.stringify({ ...sessions, [quizId]: new Date().getTime() }));
|
|
|
|
} catch (e) {
|
2025-04-20 15:16:22 +00:00
|
|
|
enqueueSnackbar(t("Количество баллов не может быть отправлено"));
|
2024-10-23 19:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2024-10-23 16:18:29 +00:00
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
2024-11-14 21:29:28 +00:00
|
|
|
const choiceImgUrlQuestion = useMemo(() => {
|
2024-11-16 19:22:50 +00:00
|
|
|
if (
|
|
|
|
resultQuestion.content.editedUrlImagesList !== undefined &&
|
|
|
|
resultQuestion.content.editedUrlImagesList !== null
|
|
|
|
) {
|
2024-11-14 21:29:28 +00:00
|
|
|
return resultQuestion.content.editedUrlImagesList[isMobile ? "mobile" : isTablet ? "tablet" : "desktop"];
|
|
|
|
} else {
|
|
|
|
return resultQuestion.content.back;
|
|
|
|
}
|
|
|
|
}, [resultQuestion]);
|
2024-05-31 16:41:18 +00:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
alignItems: "center",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
height: "100%",
|
|
|
|
minHeight: "100%",
|
|
|
|
width: "100%",
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
backgroundPosition: "center",
|
|
|
|
backgroundSize: "cover",
|
|
|
|
backgroundImage: settings.cfg.design && !isMobile ? `url(${DESIGN_LIST[settings.cfg.theme]})` : null,
|
|
|
|
position: "relative",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
alignItems: "center",
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
background:
|
|
|
|
settings.cfg.design && !isMobile
|
|
|
|
? quizThemes[settings.cfg.theme].isLight
|
|
|
|
? "transparent"
|
|
|
|
: "linear-gradient(90deg, rgba(39, 38, 38, 0.95) 7.66%, rgba(42, 42, 46, 0.85) 42.12%, rgba(51, 54, 71, 0.4) 100%)"
|
|
|
|
: theme.palette.background.default,
|
|
|
|
}}
|
|
|
|
>
|
2023-12-17 13:22:21 +00:00
|
|
|
<Box
|
2024-05-31 16:41:18 +00:00
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
alignItems: "center",
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
overflow: "auto",
|
|
|
|
padding: "0 20px 20px",
|
|
|
|
scrollbarWidth: "none",
|
|
|
|
"&::-webkit-scrollbar": {
|
|
|
|
width: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
2024-01-30 16:49:33 +00:00
|
|
|
sx={{
|
2024-05-31 16:41:18 +00:00
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
mb: "10px",
|
|
|
|
width: "100%",
|
|
|
|
maxWidth: "700px",
|
|
|
|
backgroundColor: "#9A9AAF1A",
|
|
|
|
borderRadius: "0 0 12px 12px",
|
|
|
|
padding: "20px 20px 15px",
|
2024-03-14 17:17:19 +00:00
|
|
|
}}
|
2024-05-31 16:41:18 +00:00
|
|
|
>
|
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
fontSize: "17px",
|
|
|
|
color: "#9A9AAF",
|
|
|
|
wordBreak: "break-word",
|
|
|
|
}}
|
|
|
|
>
|
2025-04-20 15:16:22 +00:00
|
|
|
{t("Your result")}:
|
2024-05-31 16:41:18 +00:00
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
alignItems: "flex-start",
|
|
|
|
width: "100%",
|
|
|
|
maxWidth: "700px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{!resultQuestion?.content.useImage && resultQuestion.content.video && (
|
2024-06-17 14:12:53 +00:00
|
|
|
<QuizVideo
|
2024-05-31 16:41:18 +00:00
|
|
|
videoUrl={resultQuestion.content.video}
|
|
|
|
containerSX={{
|
|
|
|
width: "100%",
|
|
|
|
maxWidth: "700px",
|
|
|
|
height: isMobile ? "100%" : "306px",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2024-11-14 21:29:28 +00:00
|
|
|
{resultQuestion?.content.useImage && choiceImgUrlQuestion && (
|
2024-05-31 16:41:18 +00:00
|
|
|
<Box
|
2024-04-17 13:27:29 +00:00
|
|
|
sx={{
|
2024-05-31 16:41:18 +00:00
|
|
|
width: "100%",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "center",
|
|
|
|
}}
|
2024-12-21 18:44:57 +00:00
|
|
|
onClick={(event) => event.preventDefault()}
|
2024-05-31 16:41:18 +00:00
|
|
|
>
|
|
|
|
<img
|
|
|
|
alt="resultImage"
|
2024-11-14 21:29:28 +00:00
|
|
|
src={choiceImgUrlQuestion}
|
2024-05-31 16:41:18 +00:00
|
|
|
style={{
|
2024-05-08 13:53:57 +00:00
|
|
|
width: "100%",
|
2024-05-31 16:41:18 +00:00
|
|
|
height: spec ? "auto" : isMobile ? "236px" : "306px",
|
|
|
|
borderRadius: "12px",
|
|
|
|
objectFit: "cover",
|
|
|
|
overflow: "hidden",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
{resultQuestion.description !== "" && resultQuestion.description !== " " && (
|
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
fontSize: "27px",
|
|
|
|
lineHeight: "32px",
|
|
|
|
fontWeight: 700,
|
|
|
|
mt: "30px",
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
wordBreak: "break-word",
|
2024-04-17 13:27:29 +00:00
|
|
|
}}
|
2024-05-31 16:41:18 +00:00
|
|
|
>
|
|
|
|
{resultQuestion.description}
|
|
|
|
</Typography>
|
|
|
|
)}
|
2024-03-02 15:33:28 +00:00
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
mt: "12px",
|
|
|
|
fontSize: "17px",
|
|
|
|
lineHeight: "20px",
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
wordBreak: "break-word",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{resultQuestion.title}
|
|
|
|
</Typography>
|
2024-01-30 16:49:33 +00:00
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
{resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && (
|
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
fontSize: "17px",
|
|
|
|
lineHeight: "20px",
|
|
|
|
mt: "25px ",
|
|
|
|
wordBreak: "break-word",
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{resultQuestion.content.text}
|
|
|
|
</Typography>
|
|
|
|
)}
|
2024-10-23 19:15:05 +00:00
|
|
|
{settings.cfg?.score && (
|
|
|
|
<>
|
2024-10-23 13:23:35 +00:00
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
color: theme.palette.primary.main,
|
2024-10-23 19:15:05 +00:00
|
|
|
fontSize: "30px",
|
|
|
|
m: "30px 0",
|
|
|
|
fontWeight: 600,
|
2024-10-23 13:23:35 +00:00
|
|
|
}}
|
|
|
|
>
|
2025-04-20 15:16:22 +00:00
|
|
|
{t("Your points")}
|
2024-10-23 13:23:35 +00:00
|
|
|
</Typography>
|
2024-10-23 19:15:05 +00:00
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
fontSize: "30px",
|
|
|
|
fontWeight: 600,
|
|
|
|
}}
|
|
|
|
>
|
2025-04-20 15:16:22 +00:00
|
|
|
{pointsSum} {t("of")} {questions.filter((e) => e.type != "result").length}
|
2024-10-23 19:15:05 +00:00
|
|
|
</Typography>
|
|
|
|
<TextAccordion
|
|
|
|
headerText={
|
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
"&:hover": {
|
|
|
|
color: theme.palette.primary.dark,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
2025-04-20 15:16:22 +00:00
|
|
|
{t("View answers")}
|
2024-10-23 19:15:05 +00:00
|
|
|
</Typography>
|
|
|
|
}
|
|
|
|
sx={{
|
|
|
|
mt: "60px",
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
mt: "25px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<PointSystemResultList />
|
|
|
|
</Box>
|
|
|
|
</TextAccordion>
|
|
|
|
</>
|
|
|
|
)}
|
2024-05-31 16:41:18 +00:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
{show_badge && (
|
|
|
|
<Box
|
|
|
|
component={Link}
|
|
|
|
target={"_blank"}
|
2024-10-24 12:50:24 +00:00
|
|
|
href={`https://${isProduction ? "" : "s"}quiz.pena.digital/answer/v1.0.0/logo?q=${quizId}`}
|
2024-05-31 16:41:18 +00:00
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
alignSelf: isMobile ? "center" : "end",
|
|
|
|
margin: isMobile ? "15px 0 0" : "15px 25px 0 0",
|
|
|
|
gap: "10px",
|
|
|
|
textDecoration: "none",
|
|
|
|
mb: "15px",
|
|
|
|
position: isTablet || isMobile ? "sticky" : "absolute",
|
|
|
|
bottom: "90px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<NameplateLogo
|
|
|
|
style={{
|
|
|
|
fontSize: "23px",
|
|
|
|
color: quizThemes[settings.cfg.theme].isLight ? "#000000" : "#F5F7FF",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
flexDirection: "column",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
|
|
|
borderTop: "1px solid #9A9AAF80",
|
|
|
|
p: "20px",
|
|
|
|
position: "sticky",
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
>
|
2024-06-02 11:08:09 +00:00
|
|
|
{settings.cfg.resultInfo.showResultForm === "before" &&
|
|
|
|
settings.cfg.showfc !== false &&
|
|
|
|
!settings.cfg.score && (
|
|
|
|
<Button
|
|
|
|
onClick={() => setCurrentQuizStep("contactform")}
|
|
|
|
variant="contained"
|
|
|
|
sx={{
|
|
|
|
p: "10px 20px",
|
|
|
|
width: "auto",
|
|
|
|
height: "50px",
|
|
|
|
}}
|
|
|
|
>
|
2025-04-20 15:16:22 +00:00
|
|
|
{resultQuestion.content.hint.text || t("Find out more")}
|
2024-06-02 11:08:09 +00:00
|
|
|
</Button>
|
|
|
|
)}
|
2024-05-31 16:41:18 +00:00
|
|
|
{settings.cfg.resultInfo.showResultForm === "after" && resultQuestion.content.redirect && (
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
vkMetrics.resultLink();
|
|
|
|
yandexMetrics.resultLink();
|
|
|
|
setTimeout(() => {
|
|
|
|
location.href = (
|
|
|
|
resultQuestion.content.redirect.includes("https")
|
|
|
|
? resultQuestion.content.redirect
|
|
|
|
: `https://${resultQuestion.content.redirect}`
|
|
|
|
).replace(/\s+/g, "");
|
|
|
|
}, 1000);
|
|
|
|
}}
|
|
|
|
variant="contained"
|
|
|
|
sx={{
|
|
|
|
p: "10px 20px",
|
|
|
|
width: "auto",
|
|
|
|
}}
|
|
|
|
>
|
2025-04-20 15:16:22 +00:00
|
|
|
{resultQuestion.content.hint.text || t("Go to website")}
|
2024-05-31 16:41:18 +00:00
|
|
|
</Button>
|
|
|
|
)}
|
2023-12-21 19:22:06 +00:00
|
|
|
</Box>
|
2024-05-31 16:41:18 +00:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
2024-01-10 18:02:37 +00:00
|
|
|
};
|