frontPanel/src/pages/ViewPublicationPage/ResultForm.tsx

130 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-12-15 12:12:36 +00:00
import { Box, Typography, Button } from "@mui/material";
2023-12-16 12:33:06 +00:00
import { getQuestionByContentId } from "@root/questions/actions";
2023-12-15 12:12:36 +00:00
import { useCurrentQuiz } from "@root/quizes/hooks";
2023-12-16 09:36:35 +00:00
import { useQuestionsStore } from "@root/questions/store";
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
2023-12-16 12:33:06 +00:00
import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx"
2023-12-15 12:12:36 +00:00
type ResultFormProps = {
2023-12-16 09:36:35 +00:00
currentQuestion: AnyTypedQuizQuestion;
2023-12-15 12:12:36 +00:00
showContactForm: boolean;
setShowContactForm: (show: boolean) => void;
setShowResultForm: (show: boolean) => void;
};
export const ResultForm = ({
2023-12-16 09:36:35 +00:00
currentQuestion,
2023-12-15 12:12:36 +00:00
showContactForm,
setShowContactForm,
setShowResultForm,
2023-12-16 12:33:06 +00:00
2023-12-15 12:12:36 +00:00
}: ResultFormProps) => {
const quiz = useCurrentQuiz();
2023-12-16 09:36:35 +00:00
const { questions } = useQuestionsStore();
const resultQuestion = questions.find(
(question) =>
question.type === "result" &&
(question.content.rule.parentId === "line" || currentQuestion.content.id)
2023-12-16 09:36:35 +00:00
);
2023-12-15 12:12:36 +00:00
const followNextForm = () => {
setShowResultForm(false);
setShowContactForm(true);
};
return (
2023-12-16 12:33:06 +00:00
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "space-between",
height: "100vh",
width: "100vw",
pt: "28px"
}}
>
<Box
sx={{
display: "flex",
flexDirection: "column",
alignItems: "start",
width: "490px",
}}
>
{
2023-12-16 15:59:36 +00:00
!resultQuestion?.content.useImage &&
resultQuestion.content.video &&
2023-12-16 12:33:06 +00:00
<YoutubeEmbedIframe
2023-12-16 15:59:36 +00:00
videoUrl={resultQuestion.content.video}
2023-12-16 12:33:06 +00:00
containerSX={{
width: "490px",
height: "280px"
}}
/>
}
{
2023-12-16 15:59:36 +00:00
resultQuestion?.content.useImage &&
resultQuestion.content.back &&
2023-12-16 12:33:06 +00:00
<Box
component='img'
2023-12-16 15:59:36 +00:00
src={resultQuestion.content.back}
2023-12-16 12:33:06 +00:00
sx={{
width: "490px",
height: "280px"
}}
>
</Box>
}
2023-12-16 15:59:36 +00:00
{resultQuestion.description !== "" && resultQuestion.description !== " " && <Typography
2023-12-16 12:33:06 +00:00
sx={{
fontSize: "23px",
fontWeight: 700,
m: "20px 0"
}}
2023-12-16 15:59:36 +00:00
>{resultQuestion.description}</Typography>}
2023-12-16 12:33:06 +00:00
<Typography
sx={{
m: "20px 0"
}}
2023-12-16 15:59:36 +00:00
>{resultQuestion.title || "Форма результатов"}
2023-12-16 12:33:06 +00:00
</Typography>
</Box>
{
quiz?.config.resultInfo.when === "before" &&
<Box
2023-12-16 12:33:06 +00:00
sx={{
height: "100px",
boxShadow: "0 0 15px 0 rgba(0,0,0,.08)",
width: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center"
2023-12-16 12:33:06 +00:00
}}
>
<Button
onClick={followNextForm}
variant="contained"
sx={{
p: "10px 20px",
width: "210px",
height: "50px"
}}
>
{resultQuestion.content.hint.text || "Узнать подробнее"}
</Button>
</Box>
}
2023-12-15 12:12:36 +00:00
</Box>
);
};