frontAnswerer/lib/components/ViewPublicationPage/ResultForm.tsx

274 lines
8.6 KiB
TypeScript
Raw Normal View History

2024-05-06 13:47:19 +00:00
import { useEffect } 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";
import { useQuizData } 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";
import { DESIGN_LIST } from "@/utils/designList";
2024-05-06 13:47:19 +00:00
import { quizThemes } from "@utils/themes/Publication/themePublication";
import YoutubeEmbedIframe from "./tools/YoutubeEmbedIframe";
import { NameplateLogo } from "@icons/NameplateLogo";
import type { QuizQuestionResult } from "@/model/questionTypes/result";
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
};
export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
2024-04-17 13:27:29 +00:00
const theme = useTheme();
const isMobile = useRootContainerSize() < 650;
const isTablet = useRootContainerSize() < 1000;
const { settings, show_badge, quizId } = useQuizData();
const setCurrentQuizStep = useQuizViewStore(
(state) => state.setCurrentQuizStep
);
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);
useEffect(() => {
2024-05-11 12:55:58 +00:00
vkMetrics.resultIdShown(resultQuestion.id);
yandexMetrics.resultIdShown(resultQuestion.id);
vkMetrics.resultShown();
yandexMetrics.resultShown();
2024-05-06 13:47:19 +00:00
}, []);
2023-12-16 14:55:56 +00:00
2024-04-17 13:27:29 +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,
}}
>
<Box
sx={{
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
alignItems: "center",
pt: "30px",
width: "100%",
height: "100%",
overflow: "auto",
background:
settings.cfg.design && !isMobile
? quizThemes[settings.cfg.theme].isLight
? "transparent"
: "linear-gradient(90deg,#272626, transparent)"
: theme.palette.background.default,
scrollbarWidth: "none",
"&::-webkit-scrollbar": {
width: 0,
},
}}
>
<Box
2024-04-17 13:27:29 +00:00
sx={{
display: "flex",
alignItems: "center",
flexWrap: "wrap",
gap: "30px",
mb: "7px",
}}
>
<Typography
sx={{
2024-04-17 13:27:29 +00:00
fontSize: "14px",
color: theme.palette.text.primary,
wordBreak: "break-word",
}}
2024-04-17 13:27:29 +00:00
>
Ваш результат:
2024-04-17 13:27:29 +00:00
</Typography>
</Box>
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
width: "100%",
maxWidth: "844px",
padding: isMobile ? "0 16px" : isTablet ? "0 78px" : undefined,
}}
>
2024-04-17 13:27:29 +00:00
{!resultQuestion?.content.useImage &&
resultQuestion.content.video && (
<YoutubeEmbedIframe
videoUrl={resultQuestion.content.video}
containerSX={{
width: "100%",
maxWidth: "844px",
height: isMobile ? "100%" : "306px",
}}
/>
)}
{resultQuestion?.content.useImage && resultQuestion.content.back && (
<Box
2024-04-17 13:27:29 +00:00
sx={{ width: "100%", display: "flex", justifyContent: "center" }}
>
<Box
component="img"
src={resultQuestion.content.back}
2023-12-29 00:58:19 +00:00
sx={{
2024-04-17 13:27:29 +00:00
width: "100%",
maxWidth: "306px",
height: spec ? "auto" : isMobile ? "236px" : "306px",
borderRadius: "8px",
objectFit: "contain",
2023-12-29 00:58:19 +00:00
}}
2024-04-17 13:27:29 +00:00
/>
</Box>
)}
{resultQuestion.description !== "" &&
resultQuestion.description !== " " && (
<Typography
sx={{
fontSize: "24px",
2024-04-17 13:27:29 +00:00
fontWeight: 700,
mt: "25px",
2024-04-17 13:27:29 +00:00
color: theme.palette.text.primary,
wordBreak: "break-word",
}}
>
{resultQuestion.description}
</Typography>
)}
2024-04-17 13:27:29 +00:00
<Typography
sx={{
mt: "20px",
2024-04-17 13:27:29 +00:00
color: theme.palette.text.primary,
wordBreak: "break-word",
}}
>
{resultQuestion.title}
</Typography>
2024-04-17 13:27:29 +00:00
{resultQuestion.content.text !== "" &&
resultQuestion.content.text !== " " && (
<Typography
sx={{
fontSize: "18px",
mt: "30px ",
2024-04-17 13:27:29 +00:00
wordBreak: "break-word",
color: theme.palette.text.primary,
}}
>
{resultQuestion.content.text}
</Typography>
)}
</Box>
2024-04-17 13:27:29 +00:00
<Box width="100%">
<Box
sx={{
display: "flex",
width: "100%",
justifyContent: "end",
px: "20px",
}}
>
{show_badge && (
<Box
component={Link}
target={"_blank"}
2024-05-11 23:54:10 +00:00
href={`https://${window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
2024-04-17 13:27:29 +00:00
sx={{
display: "flex",
alignItems: "center",
mt: "15px",
gap: "10px",
textDecoration: "none",
mb: "15px",
}}
>
<NameplateLogo
style={{
fontSize: "23px",
color: quizThemes[settings.cfg.theme].isLight
? "#000000"
: "#F5F7FF",
}}
/>
</Box>
)}
</Box>
2024-04-17 13:27:29 +00:00
<Box
sx={{
// boxShadow: "0 0 15px 0 rgba(0,0,0,.08)",
width: "100%",
flexDirection: "column",
display: "flex",
justifyContent: "center",
alignItems: "center",
borderTop: "1px solid #9A9AAF80",
p:
(settings.cfg.resultInfo.showResultForm === "before" &&
!settings.cfg.score) ||
2024-05-11 23:54:10 +00:00
(settings.cfg.resultInfo.showResultForm === "after" &&
resultQuestion.content.redirect)
2024-04-17 13:27:29 +00:00
? "20px"
: "0",
}}
>
{settings.cfg.resultInfo.showResultForm === "before" &&
!settings.cfg.score && (
<Button
onClick={() => setCurrentQuizStep("contactform")}
variant="contained"
sx={{
p: "10px 20px",
width: "auto",
height: "50px",
}}
>
{resultQuestion.content.hint.text || "Узнать подробнее"}
</Button>
)}
{settings.cfg.resultInfo.showResultForm === "after" &&
resultQuestion.content.redirect && (
<Button
2024-05-11 23:54:10 +00:00
onClick={() => {
vkMetrics.resultLink();
yandexMetrics.resultLink();
setTimeout(() => {
location.href =
(resultQuestion.content.redirect.includes("https")
? resultQuestion.content.redirect
: `https://${resultQuestion.content.redirect}`).replace(/\s+/g, "");
}, 1000)
}}
2024-04-17 13:27:29 +00:00
variant="contained"
sx={{ p: "10px 20px", width: "auto", height: "50px" }}
>
{resultQuestion.content.hint.text || "Перейти на сайт"}
</Button>
)}
</Box>
</Box>
2024-04-17 13:27:29 +00:00
</Box>
2024-05-11 23:54:10 +00:00
</Box >
2024-04-17 13:27:29 +00:00
);
2024-01-10 18:02:37 +00:00
};