ветвление умеет искать следующий вопрос с условием необязательности и умеет искать резулт

This commit is contained in:
Nastya 2023-12-27 20:26:55 +03:00
parent 9b47cd018c
commit fddd2d3cba

@ -9,8 +9,8 @@ import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questio
import { getQuestionByContentId } from "@root/questions/actions";
import { enqueueSnackbar } from "notistack";
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
import {NameplateLogoFQDark} from "@icons/NameplateLogoFQDark";
import {modes} from "../../utils/themes/Publication/themePublication";
import { NameplateLogoFQDark } from "@icons/NameplateLogoFQDark";
import { modes } from "../../utils/themes/Publication/themePublication";
import { checkEmptyData } from "../ResultPage/cards/ResultCard";
type FooterProps = {
@ -116,10 +116,14 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
};
const getNextQuestionId = () => {
console.log("net")
console.log(question)
let readyBeNextQuestion = "";
//вопрос обязателен, анализируем ответ и условия ветвления
if (answers.length) {
const answer = answers.find(({ questionId }) => questionId === question.content.id);
let readyBeNextQuestion = "";
(question as QuizQuestionBase).content.rule.main.forEach(({ next, rules }) => {
let longerArray = Math.max(
@ -146,8 +150,23 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
}
});
return readyBeNextQuestion;
if (readyBeNextQuestion) return readyBeNextQuestion;
}
if (!question.required) {//вопрос не обязателен и не нашли совпадений между ответами и условиями ветвления
console.log("вопрос не обязателен ищем дальше")
const defaultQ = question.content.rule.default
if (defaultQ) return defaultQ
}
//ничё не нашли, ищем резулт
console.log("ничё не нашли, ищем резулт ")
return questions.find(q => {
console.log('q.type === "result"', q.type === "result")
console.log('q.content.rule.parentId === question.content.id', q.content.rule.parentId === question.content.id)
return q.type === "result" && q.content.rule.parentId === question.content.id
})?.content.id
};
const followPreviousStep = () => {
@ -195,22 +214,18 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
const nextQuestionId = getNextQuestionId();
console.log(nextQuestionId)
if (nextQuestionId) {
const nextQuestion = getQuestionByContentId(nextQuestionId);
console.log(nextQuestion)
if (nextQuestion?.type && nextQuestion.type !== "result") {
setCurrentQuestion(nextQuestion);
return;
if (nextQuestion?.type && nextQuestion.type === "result") {
showResult(nextQuestion);
} else {
enqueueSnackbar("не могу получить последующий вопрос");
setCurrentQuestion(nextQuestion);
}
} else {
const nextQuestion = getQuestionByContentId(question.content.rule.default);
if (nextQuestion?.type && nextQuestion.type !== "result") {
setCurrentQuestion(nextQuestion);
} else {
showResult(nextQuestion);
}
enqueueSnackbar("не могу получить последующий вопрос");
}
};
@ -237,9 +252,9 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
}}
>
{mode[quiz.config.theme] ? (
<NameplateLogoFQ style={{ fontSize: "34px", width:"200px", height:"auto" }} />
):(
<NameplateLogoFQDark style={{ fontSize: "34px", width:"200px", height:"auto" }} />
<NameplateLogoFQ style={{ fontSize: "34px", width: "200px", height: "auto" }} />
) : (
<NameplateLogoFQDark style={{ fontSize: "34px", width: "200px", height: "auto" }} />
)
}
@ -311,7 +326,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
<Button
disabled={disablePreviousButton}
variant="contained"
sx={{ fontSize: "16px", padding: "10px 15px", "& :disabled": {color: `{hsl((theme.palette.primary.main) 30%)}`} }}
sx={{ fontSize: "16px", padding: "10px 15px", "& :disabled": { color: `{hsl((theme.palette.primary.main) 30%)}` } }}
onClick={followPreviousStep}
>
Назад