страница результатов не отображается если не заполнена
This commit is contained in:
parent
1ca17853e9
commit
74d22956a8
@ -11,6 +11,7 @@ import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
|
|
||||||
|
import { checkEmptyData } from "../ResultPage/cards/ResultCard";
|
||||||
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
|
|
||||||
@ -44,11 +45,23 @@ export const ContactForm = ({
|
|||||||
setShowResultForm(true);
|
setShowResultForm(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resultQuestion = questions.find(
|
|
||||||
(question) =>
|
const resultQuestion = questions.find((question) => {
|
||||||
question.type === "result" &&
|
if (quiz?.config.haveRoot) { //ветвимся
|
||||||
question.content.rule.parentId === currentQuestion.content.id
|
return (
|
||||||
|
question.type === "result" &&
|
||||||
|
question.content.rule.parentId === currentQuestion.content.id
|
||||||
|
)
|
||||||
|
} else {// не ветвимся
|
||||||
|
return (
|
||||||
|
question.type === "result" &&
|
||||||
|
question.content.rule.parentId === "line"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -117,7 +130,10 @@ export const ContactForm = ({
|
|||||||
<Button
|
<Button
|
||||||
disabled={!ready}
|
disabled={!ready}
|
||||||
variant="contained" onClick={() => {
|
variant="contained" onClick={() => {
|
||||||
if (quiz?.config.resultInfo.when === "after") followNextForm()
|
if (quiz?.config.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) {
|
||||||
|
setShowContactForm(false)
|
||||||
|
setShowResultForm(true)
|
||||||
|
}
|
||||||
}}>
|
}}>
|
||||||
Получить результаты
|
Получить результаты
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questio
|
|||||||
import { getQuestionByContentId } from "@root/questions/actions";
|
import { getQuestionByContentId } from "@root/questions/actions";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
||||||
|
import { checkEmptyData } from "../ResultPage/cards/ResultCard";
|
||||||
|
|
||||||
type FooterProps = {
|
type FooterProps = {
|
||||||
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
|
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
|
||||||
@ -80,11 +81,35 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
|
|
||||||
const showResult = (nextQuestion) => {
|
const showResult = (nextQuestion) => {
|
||||||
|
|
||||||
if (nextQuestion && quiz?.config.resultInfo.when === "before") {
|
|
||||||
setShowResultForm(true);
|
if (nextQuestion && quiz?.config.resultInfo.when === "email") {
|
||||||
} else {
|
|
||||||
setShowContactForm(true);
|
setShowContactForm(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isEmpty = checkEmptyData({ resultData: nextQuestion })
|
||||||
|
console.log("пустой результат? ", isEmpty)
|
||||||
|
if (nextQuestion) {
|
||||||
|
if (nextQuestion && quiz?.config.resultInfo.when === "before") {
|
||||||
|
if (isEmpty) {
|
||||||
|
setShowContactForm(true); //до+пустая = кидать на ФК
|
||||||
|
console.log("до+пустая = кидать на ФК")
|
||||||
|
} else {
|
||||||
|
setShowResultForm(true); //до+заполнена = показать
|
||||||
|
console.log("до+заполнена = показать")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nextQuestion && quiz?.config.resultInfo.when === "after") {
|
||||||
|
if (isEmpty) {
|
||||||
|
setShowContactForm(true); //после+пустая
|
||||||
|
console.log("после+пустая")
|
||||||
|
} else {
|
||||||
|
setShowContactForm(true); //после+заполнена = показать ФК
|
||||||
|
console.log("после+заполнена = показать")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNextQuestionId = () => {
|
const getNextQuestionId = () => {
|
||||||
@ -124,7 +149,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
|
|
||||||
const followPreviousStep = () => {
|
const followPreviousStep = () => {
|
||||||
if (linear) {
|
if (linear) {
|
||||||
setStepNumber(q=>q-1)
|
setStepNumber(q => q - 1)
|
||||||
const questionIndex = questions.findIndex(({ id }) => id === question.id);
|
const questionIndex = questions.findIndex(({ id }) => id === question.id);
|
||||||
|
|
||||||
const previousQuestion = questions[questionIndex - 1];
|
const previousQuestion = questions[questionIndex - 1];
|
||||||
@ -152,7 +177,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
|
|
||||||
|
|
||||||
if (linear) {
|
if (linear) {
|
||||||
setStepNumber(q=>q+1)
|
setStepNumber(q => q + 1)
|
||||||
const questionIndex = questions.findIndex(({ id }) => id === question.id);
|
const questionIndex = questions.findIndex(({ id }) => id === question.id);
|
||||||
const nextQuestion = questions[questionIndex + 1];
|
const nextQuestion = questions[questionIndex + 1];
|
||||||
|
|
||||||
@ -161,10 +186,10 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
} else {
|
} else {
|
||||||
showResult(nextQuestion);
|
showResult(nextQuestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const nextQuestionId = getNextQuestionId();
|
const nextQuestionId = getNextQuestionId();
|
||||||
|
|
||||||
if (nextQuestionId) {
|
if (nextQuestionId) {
|
||||||
@ -238,7 +263,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Typography>Из</Typography>
|
<Typography>Из</Typography>
|
||||||
<Typography sx={{ fontWeight: "bold" }}>
|
<Typography sx={{ fontWeight: "bold" }}>
|
||||||
{questions.filter(q=>q.type !== "result").length}
|
{questions.filter(q => q.type !== "result").length}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user