2023-12-16 14:55:56 +00:00
|
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
import { Box } from "@mui/material";
|
|
|
|
|
|
2023-12-17 13:22:21 +00:00
|
|
|
|
import { useQuestionsStore } from "@root/quizData/store"
|
|
|
|
|
import { getQuestionById } from "@root/quizData/actions";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
|
|
import { Variant } from "./questions/Variant";
|
|
|
|
|
import { Images } from "./questions/Images";
|
|
|
|
|
import { Varimg } from "./questions/Varimg";
|
|
|
|
|
import { Emoji } from "./questions/Emoji";
|
|
|
|
|
import { Text } from "./questions/Text";
|
|
|
|
|
import { Select } from "./questions/Select";
|
|
|
|
|
import { Date } from "./questions/Date";
|
|
|
|
|
import { Number } from "./questions/Number";
|
|
|
|
|
import { File } from "./questions/File";
|
|
|
|
|
import { Page } from "./questions/Page";
|
|
|
|
|
import { Rating } from "./questions/Rating";
|
|
|
|
|
import { Footer } from "./Footer";
|
|
|
|
|
import { ContactForm } from "./ContactForm";
|
|
|
|
|
import { ResultForm } from "./ResultForm";
|
|
|
|
|
|
2023-12-17 13:22:21 +00:00
|
|
|
|
import type { QuestionType } from "@model/questionTypes/shared";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
|
|
|
|
|
|
|
|
|
type QuestionProps = {
|
|
|
|
|
questions: AnyTypedQuizQuestion[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const QUESTIONS_MAP: any = {
|
|
|
|
|
variant: Variant,
|
|
|
|
|
images: Images,
|
|
|
|
|
varimg: Varimg,
|
|
|
|
|
emoji: Emoji,
|
|
|
|
|
text: Text,
|
|
|
|
|
select: Select,
|
|
|
|
|
date: Date,
|
|
|
|
|
number: Number,
|
|
|
|
|
file: File,
|
|
|
|
|
page: Page,
|
|
|
|
|
rating: Rating,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const Question = ({ questions }: QuestionProps) => {
|
2023-12-17 13:22:21 +00:00
|
|
|
|
const { settings, cnt, items } = useQuestionsStore()
|
2023-12-21 19:22:06 +00:00
|
|
|
|
const [currentQuestion, setCurrentQuestion] = useState<AnyTypedQuizQuestion>();
|
2023-12-16 14:55:56 +00:00
|
|
|
|
const [showContactForm, setShowContactForm] = useState<boolean>(false);
|
|
|
|
|
const [showResultForm, setShowResultForm] = useState<boolean>(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
2023-12-21 19:22:06 +00:00
|
|
|
|
if (settings?.cfg.haveRoot) {//ветвимся
|
|
|
|
|
const nextQuestion = getQuestionById(settings?.cfg.haveRoot || "");
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
2023-12-21 19:22:06 +00:00
|
|
|
|
if (nextQuestion?.type) {
|
|
|
|
|
setCurrentQuestion(nextQuestion);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {//идём прямо
|
|
|
|
|
setCurrentQuestion(questions[0]);
|
2023-12-16 14:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (!currentQuestion) return <>не смог отобразить вопрос</>;
|
|
|
|
|
|
|
|
|
|
const QuestionComponent =
|
|
|
|
|
QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">];
|
|
|
|
|
|
|
|
|
|
return (
|
2023-12-21 19:22:06 +00:00
|
|
|
|
<Box
|
|
|
|
|
height="100vh"
|
|
|
|
|
>
|
2023-12-17 13:22:21 +00:00
|
|
|
|
{!showContactForm && !showResultForm && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
minHeight: "calc(100vh - 75px)",
|
|
|
|
|
width: "100%",
|
|
|
|
|
maxWidth: "1440px",
|
|
|
|
|
padding: "40px 25px 20px",
|
|
|
|
|
margin: "0 auto",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-16 14:55:56 +00:00
|
|
|
|
<QuestionComponent currentQuestion={currentQuestion} />
|
2023-12-17 13:22:21 +00:00
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2023-12-17 18:15:59 +00:00
|
|
|
|
{showResultForm && settings?.cfg.resultInfo.when === "before" && (
|
2023-12-17 13:22:21 +00:00
|
|
|
|
<ResultForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
showContactForm={showContactForm}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{showContactForm && (
|
|
|
|
|
<ContactForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
showResultForm={showResultForm}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-12-17 18:15:59 +00:00
|
|
|
|
{showResultForm && settings?.cfg.resultInfo.when === "after" && (
|
2023-12-17 13:22:21 +00:00
|
|
|
|
<ResultForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
showContactForm={showContactForm}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-12-16 14:55:56 +00:00
|
|
|
|
{!showContactForm && !showResultForm && (
|
|
|
|
|
<Footer
|
|
|
|
|
question={currentQuestion}
|
|
|
|
|
setCurrentQuestion={setCurrentQuestion}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|