2023-12-16 14:55:56 +00:00
|
|
|
|
import { useState, useEffect } from "react";
|
2024-01-05 21:15:59 +00:00
|
|
|
|
import {Box, useMediaQuery, useTheme} from "@mui/material";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
2024-01-19 11:46:17 +00:00
|
|
|
|
import { useQuestionsStore } from "@stores/quizData/store"
|
|
|
|
|
import { getQuestionById } from "@stores/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";
|
|
|
|
|
|
2023-12-29 00:58:19 +00:00
|
|
|
|
import {NameplateLogoFQ} from "@icons/NameplateLogoFQ";
|
|
|
|
|
import {NameplateLogoFQDark} from "@icons/NameplateLogoFQDark";
|
|
|
|
|
import {modes} from "../../utils/themes/Publication/themePublication";
|
|
|
|
|
|
2023-12-16 14:55:56 +00:00
|
|
|
|
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-29 00:58:19 +00:00
|
|
|
|
const { settings } = useQuestionsStore()
|
2024-01-05 21:15:59 +00:00
|
|
|
|
const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(650));
|
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);
|
2023-12-29 00:58:19 +00:00
|
|
|
|
const mode = modes;
|
|
|
|
|
console.log("currentQuestion ", currentQuestion)
|
2023-12-16 14:55:56 +00:00
|
|
|
|
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">];
|
2024-01-05 21:15:59 +00:00
|
|
|
|
|
2023-12-16 14:55:56 +00:00
|
|
|
|
return (
|
2023-12-21 19:22:06 +00:00
|
|
|
|
<Box
|
2023-12-29 00:58:19 +00:00
|
|
|
|
sx={{
|
2024-01-05 21:15:59 +00:00
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
height: isMobile ? undefined : "100vh"
|
2023-12-29 00:58:19 +00:00
|
|
|
|
}}
|
|
|
|
|
|
2023-12-21 19:22:06 +00:00
|
|
|
|
>
|
2023-12-17 13:22:21 +00:00
|
|
|
|
{!showContactForm && !showResultForm && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2023-12-29 00:58:19 +00:00
|
|
|
|
height: "calc(100vh - 75px)",
|
2023-12-17 13:22:21 +00:00
|
|
|
|
width: "100%",
|
|
|
|
|
maxWidth: "1440px",
|
|
|
|
|
padding: "40px 25px 20px",
|
|
|
|
|
margin: "0 auto",
|
2023-12-29 00:58:19 +00:00
|
|
|
|
overflow: "auto",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
justifyContent: "space-between"
|
2023-12-17 13:22:21 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-16 14:55:56 +00:00
|
|
|
|
<QuestionComponent currentQuestion={currentQuestion} />
|
2023-12-29 00:58:19 +00:00
|
|
|
|
{mode[settings?.cfg.theme] ? (
|
|
|
|
|
<NameplateLogoFQ style={{ fontSize: "34px", width: "200px", height: "auto" }} />
|
|
|
|
|
) : (
|
|
|
|
|
<NameplateLogoFQDark style={{ fontSize: "34px", width: "200px", height: "auto" }} />
|
|
|
|
|
)}
|
2023-12-17 13:22:21 +00:00
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2024-01-10 18:02:37 +00:00
|
|
|
|
{showResultForm && settings?.cfg.resultInfo.showResultForm === "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}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-01-10 18:02:37 +00:00
|
|
|
|
{showResultForm && settings?.cfg.resultInfo.showResultForm === "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>
|
|
|
|
|
);
|
2023-12-29 00:58:19 +00:00
|
|
|
|
|
2023-12-16 14:55:56 +00:00
|
|
|
|
};
|