From 74d22956a8e14b7af2d900b8ef5963d32581d32b Mon Sep 17 00:00:00 2001 From: Nastya Date: Sat, 23 Dec 2023 20:24:32 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=BD=D0=B5=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/ViewPublicationPage/ContactForm.tsx | 26 ++++++++++--- src/pages/ViewPublicationPage/Footer.tsx | 39 +++++++++++++++---- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/pages/ViewPublicationPage/ContactForm.tsx b/src/pages/ViewPublicationPage/ContactForm.tsx index 153a00c6..b3b8621d 100644 --- a/src/pages/ViewPublicationPage/ContactForm.tsx +++ b/src/pages/ViewPublicationPage/ContactForm.tsx @@ -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 ( { - if (quiz?.config.resultInfo.when === "after") followNextForm() + if (quiz?.config.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) { + setShowContactForm(false) + setShowResultForm(true) + } }}> Получить результаты diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index 4bf9cd4a..3ea19249 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -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 Из - {questions.filter(q=>q.type !== "result").length} + {questions.filter(q => q.type !== "result").length}