import { useEffect, useMemo } from "react"; import { Box, Button, Link, Typography, useTheme } from "@mui/material"; import { useQuizViewStore } from "@/stores/quizView"; import { useRootContainerSize } from "@contexts/RootContainerWidthContext"; import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals"; import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals"; import { DESIGN_LIST } from "@/utils/designList"; import { quizThemes } from "@utils/themes/Publication/themePublication"; import { NameplateLogo } from "@icons/NameplateLogo"; import type { QuizQuestionResult } from "@/model/questionTypes/result"; import QuizVideo from "@/ui_kit/VideoIframe/VideoIframe"; import { TextAccordion } from "./tools/TextAccordion"; import { PointSystemResultList } from "./PointSystemResultList"; import { enqueueSnackbar } from "notistack"; import { sendFC, sendResult } from "@/api/quizRelase"; import { isProduction } from "@/utils/defineDomain"; import { useQuizStore } from "@/stores/useQuizStore"; type ResultFormProps = { resultQuestion: QuizQuestionResult; }; export const ResultForm = ({ resultQuestion }: ResultFormProps) => { const theme = useTheme(); const isMobile = useRootContainerSize() < 650; const isTablet = useRootContainerSize() < 1000; const { settings, show_badge, quizId, questions, preview } = useQuizStore(); const setCurrentQuizStep = useQuizViewStore((state) => state.setCurrentQuizStep); //Список засчитанных баллов для балловых квизов const pointsSum = useQuizViewStore((state) => state.pointsSum); const spec = settings.cfg.spec; const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber); const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber); useEffect(() => { vkMetrics.resultIdShown(resultQuestion.id); yandexMetrics.resultIdShown(resultQuestion.id); }, [resultQuestion.id, vkMetrics, yandexMetrics]); 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) { enqueueSnackbar("Заявка не может быть отправлена"); } } 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) { enqueueSnackbar("Количество баллов не может быть отправлено"); } } })(); }, []); const choiceImgUrlQuestion = useMemo(() => { if ( resultQuestion.content.editedUrlImagesList !== undefined && resultQuestion.content.editedUrlImagesList !== null ) { return resultQuestion.content.editedUrlImagesList[isMobile ? "mobile" : isTablet ? "tablet" : "desktop"]; } else { return resultQuestion.content.back; } }, [resultQuestion]); return ( Ваш результат: {!resultQuestion?.content.useImage && resultQuestion.content.video && ( )} {resultQuestion?.content.useImage && choiceImgUrlQuestion && ( event.preventDefault()} > resultImage )} {resultQuestion.description !== "" && resultQuestion.description !== " " && ( {resultQuestion.description} )} {resultQuestion.title} {resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && ( {resultQuestion.content.text} )} {settings.cfg?.score && ( <> Ваши баллы {pointsSum} из {questions.filter((e) => e.type != "result").length} Посмотреть ответы } sx={{ mt: "60px", width: "100%", }} > )} {show_badge && ( )} {settings.cfg.resultInfo.showResultForm === "before" && settings.cfg.showfc !== false && !settings.cfg.score && ( )} {settings.cfg.resultInfo.showResultForm === "after" && resultQuestion.content.redirect && ( )} ); };