2023-12-15 12:12:36 +00:00
|
|
|
|
import { Box, Typography, Button } from "@mui/material";
|
|
|
|
|
|
|
|
|
|
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-15 12:12:36 +00:00
|
|
|
|
|
|
|
|
|
type ContactFormProps = {
|
2023-12-16 09:36:35 +00:00
|
|
|
|
currentQuestion: AnyTypedQuizQuestion;
|
2023-12-15 12:12:36 +00:00
|
|
|
|
showResultForm: boolean;
|
|
|
|
|
setShowContactForm: (show: boolean) => void;
|
|
|
|
|
setShowResultForm: (show: boolean) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ContactForm = ({
|
2023-12-16 09:36:35 +00:00
|
|
|
|
currentQuestion,
|
2023-12-15 12:12:36 +00:00
|
|
|
|
showResultForm,
|
|
|
|
|
setShowContactForm,
|
|
|
|
|
setShowResultForm,
|
|
|
|
|
}: ContactFormProps) => {
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-16 09:36:35 +00:00
|
|
|
|
const { questions } = useQuestionsStore();
|
2023-12-15 12:12:36 +00:00
|
|
|
|
|
|
|
|
|
const followNextForm = () => {
|
|
|
|
|
setShowContactForm(false);
|
|
|
|
|
setShowResultForm(true);
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-16 09:36:35 +00:00
|
|
|
|
const resultQuestion = questions.find(
|
|
|
|
|
(question) =>
|
|
|
|
|
question.type === "result" &&
|
|
|
|
|
question.content.rule.parentId === currentQuestion.content.id
|
|
|
|
|
);
|
|
|
|
|
|
2023-12-15 12:12:36 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography>Форма контактов</Typography>
|
2023-12-16 09:36:35 +00:00
|
|
|
|
{!showResultForm &&
|
|
|
|
|
resultQuestion &&
|
|
|
|
|
quiz?.config.resultInfo.when === "after" && (
|
|
|
|
|
<Button variant="contained" onClick={followNextForm}>
|
|
|
|
|
Показать результат
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2023-12-15 12:12:36 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|