2023-12-15 12:12:36 +00:00
|
|
|
|
import { useState, useEffect } from "react";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import { Box, useTheme } from "@mui/material";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
2023-12-15 12:12:36 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
|
|
|
|
import { getQuestionByContentId } from "@root/questions/actions";
|
|
|
|
|
|
2023-11-30 17:39:57 +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";
|
2023-12-15 12:12:36 +00:00
|
|
|
|
import { ContactForm } from "./ContactForm";
|
|
|
|
|
import { ResultForm } from "./ResultForm";
|
2023-12-15 14:12:06 +00:00
|
|
|
|
import { ResultQuestion } from "./ResultQuestion";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
|
|
import type { QuestionType } from "../../model/question/question";
|
|
|
|
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
|
|
|
|
import { NameplateLogoFQDark } from "@icons/NameplateLogoFQDark";
|
|
|
|
|
import { modes } from "@utils/themes/Publication/themePublication";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
|
|
type QuestionProps = {
|
|
|
|
|
questions: AnyTypedQuizQuestion[];
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
|
const QUESTIONS_MAP: any = {
|
2023-11-30 17:39:57 +00:00
|
|
|
|
variant: Variant,
|
|
|
|
|
images: Images,
|
|
|
|
|
varimg: Varimg,
|
|
|
|
|
emoji: Emoji,
|
|
|
|
|
text: Text,
|
|
|
|
|
select: Select,
|
|
|
|
|
date: Date,
|
|
|
|
|
number: Number,
|
|
|
|
|
file: File,
|
|
|
|
|
page: Page,
|
|
|
|
|
rating: Rating,
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-06 12:09:25 +00:00
|
|
|
|
export const Question = ({ questions }: QuestionProps) => {
|
2023-12-03 10:48:00 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const [currentQuestion, setCurrentQuestion] =
|
|
|
|
|
useState<AnyTypedQuizQuestion>();
|
2023-12-15 12:12:36 +00:00
|
|
|
|
const [showContactForm, setShowContactForm] = useState<boolean>(false);
|
|
|
|
|
const [showResultForm, setShowResultForm] = useState<boolean>(false);
|
2023-12-27 18:52:05 +00:00
|
|
|
|
const mode = modes;
|
2023-12-06 12:09:25 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
const nextQuestion = getQuestionByContentId(quiz?.config.haveRoot || "");
|
|
|
|
|
|
|
|
|
|
if (nextQuestion?.type) {
|
|
|
|
|
setCurrentQuestion(nextQuestion);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCurrentQuestion(questions[0]);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (!currentQuestion) return <>не смог отобразить вопрос</>;
|
2023-12-03 10:48:00 +00:00
|
|
|
|
|
2023-12-19 20:19:22 +00:00
|
|
|
|
const QuestionComponent =
|
|
|
|
|
QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">];
|
2023-12-25 23:46:28 +00:00
|
|
|
|
const theme = useTheme();
|
2023-11-30 17:39:57 +00:00
|
|
|
|
return (
|
2023-12-21 11:47:34 +00:00
|
|
|
|
<Box
|
2023-12-31 02:53:25 +00:00
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
}}
|
|
|
|
|
height="100vh"
|
2023-12-21 11:47:34 +00:00
|
|
|
|
>
|
2023-12-16 20:17:42 +00:00
|
|
|
|
{!showContactForm && !showResultForm && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2023-12-21 11:47:34 +00:00
|
|
|
|
height: "calc(100vh - 75px)",
|
2023-12-16 20:17:42 +00:00
|
|
|
|
width: "100%",
|
|
|
|
|
maxWidth: "1440px",
|
|
|
|
|
padding: "40px 25px 20px",
|
|
|
|
|
margin: "0 auto",
|
2023-12-27 18:52:05 +00:00
|
|
|
|
overflow: "auto",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
justifyContent: "space-between",
|
2023-12-16 20:17:42 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-15 12:12:36 +00:00
|
|
|
|
<QuestionComponent currentQuestion={currentQuestion} />
|
2024-01-05 14:43:28 +00:00
|
|
|
|
<Box>
|
|
|
|
|
{mode[quiz.config.theme] ? (
|
|
|
|
|
<NameplateLogoFQ
|
|
|
|
|
style={{ fontSize: "34px", width: "200px", height: "auto" }}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<NameplateLogoFQDark
|
|
|
|
|
style={{ fontSize: "34px", width: "200px", height: "auto" }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2023-12-16 20:17:42 +00:00
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
{showResultForm && quiz?.config.resultInfo.when === "before" && (
|
|
|
|
|
<ResultForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
showContactForm={showContactForm}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{showContactForm && (
|
|
|
|
|
<ContactForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
showResultForm={showResultForm}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
{showResultForm &&
|
|
|
|
|
(quiz?.config.resultInfo.when === "after" ||
|
|
|
|
|
quiz?.config.resultInfo.when === "email") && (
|
|
|
|
|
<ResultForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
showContactForm={showContactForm}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-12-16 09:36:35 +00:00
|
|
|
|
{!showContactForm && !showResultForm && (
|
2023-12-15 12:12:36 +00:00
|
|
|
|
<Footer
|
|
|
|
|
question={currentQuestion}
|
|
|
|
|
setCurrentQuestion={setCurrentQuestion}
|
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-11-30 17:39:57 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|