страница результатов не отображается если не заполнена

This commit is contained in:
Nastya 2023-12-23 20:24:32 +03:00
parent 1ca17853e9
commit 74d22956a8
2 changed files with 53 additions and 12 deletions

@ -11,6 +11,7 @@ import CustomCheckbox from "@ui_kit/CustomCheckbox";
import { useState } from "react";
import { useQuestionsStore } from "@root/questions/store";
import { checkEmptyData } from "../ResultPage/cards/ResultCard";
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
import { enqueueSnackbar } from "notistack";
@ -44,11 +45,23 @@ export const ContactForm = ({
setShowResultForm(true);
};
const resultQuestion = questions.find(
(question) =>
question.type === "result" &&
question.content.rule.parentId === currentQuestion.content.id
const resultQuestion = questions.find((question) => {
if (quiz?.config.haveRoot) { //ветвимся
return (
question.type === "result" &&
question.content.rule.parentId === currentQuestion.content.id
)
} else {// не ветвимся
return (
question.type === "result" &&
question.content.rule.parentId === "line"
)
}
}
);
return (
<Box
sx={{
@ -117,7 +130,10 @@ export const ContactForm = ({
<Button
disabled={!ready}
variant="contained" onClick={() => {
if (quiz?.config.resultInfo.when === "after") followNextForm()
if (quiz?.config.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) {
setShowContactForm(false)
setShowResultForm(true)
}
}}>
Получить результаты
</Button>

@ -9,6 +9,7 @@ import type { AnyTypedQuizQuestion, QuizQuestionBase } from "../../model/questio
import { getQuestionByContentId } from "@root/questions/actions";
import { enqueueSnackbar } from "notistack";
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
import { checkEmptyData } from "../ResultPage/cards/ResultCard";
type FooterProps = {
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
@ -80,11 +81,35 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
const showResult = (nextQuestion) => {
if (nextQuestion && quiz?.config.resultInfo.when === "before") {
setShowResultForm(true);
} else {
if (nextQuestion && quiz?.config.resultInfo.when === "email") {
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 = () => {
@ -124,7 +149,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
const followPreviousStep = () => {
if (linear) {
setStepNumber(q=>q-1)
setStepNumber(q => q - 1)
const questionIndex = questions.findIndex(({ id }) => id === question.id);
const previousQuestion = questions[questionIndex - 1];
@ -152,7 +177,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
if (linear) {
setStepNumber(q=>q+1)
setStepNumber(q => q + 1)
const questionIndex = questions.findIndex(({ id }) => id === question.id);
const nextQuestion = questions[questionIndex + 1];
@ -161,10 +186,10 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
} else {
showResult(nextQuestion);
}
return;
}
const nextQuestionId = getNextQuestionId();
if (nextQuestionId) {
@ -238,7 +263,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
</Typography>
<Typography>Из</Typography>
<Typography sx={{ fontWeight: "bold" }}>
{questions.filter(q=>q.type !== "result").length}
{questions.filter(q => q.type !== "result").length}
</Typography>
</Box>
</>