diff --git a/src/pages/ViewPublicationPage/ContactForm.tsx b/src/pages/ViewPublicationPage/ContactForm.tsx index d2d33e0..22d016b 100644 --- a/src/pages/ViewPublicationPage/ContactForm.tsx +++ b/src/pages/ViewPublicationPage/ContactForm.tsx @@ -10,6 +10,7 @@ import CustomCheckbox from "@ui_kit/CustomCheckbox"; import { useEffect, useRef, useState } from "react"; import { useQuestionsStore } from "@root/quizData/store"; +import { checkEmptyData } from "./tools/checkEmptyData"; import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; import { enqueueSnackbar } from "notistack"; import { sendFC } from "@api/quizRelase"; @@ -36,7 +37,7 @@ export const ContactForm = ({ setShowContactForm, setShowResultForm, }: ContactFormProps) => { - const { settings } = useQuestionsStore() + const { settings, items } = useQuestionsStore() const [ready, setReady] = useState(false) @@ -45,6 +46,23 @@ export const ContactForm = ({ setShowResultForm(true); }; + const resultQuestion = items.find((question) => { + if (settings?.cfg.haveRoot) { //ветвимся + return ( + question.type === "result" && + //@ts-ignore + question.content.rule.parentId === currentQuestion.content.id + ) + } else {// не ветвимся + return ( + question.type === "result" && + question.content.rule.parentId === "line" + ) + } + + } + ); + return ( { - if (settings?.cfg.resultInfo.when === "after") followNextForm() + //@ts-ignore + if (settings?.cfg.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) { + setShowContactForm(false) + setShowResultForm(true) + } + }}> Получить результаты @@ -200,6 +223,9 @@ const Inputs = (currentQuestion: any) => { inputHC() }, [name, email, phone, text, adress]) //@ts-ignore + console.log(settings) + console.log(settings?.cfg) + console.log(settings?.cfg.formContact) const FC: any = settings?.cfg.formContact //@ts-ignore diff --git a/src/pages/ViewPublicationPage/Footer.tsx b/src/pages/ViewPublicationPage/Footer.tsx index 614ffc3..e532102 100644 --- a/src/pages/ViewPublicationPage/Footer.tsx +++ b/src/pages/ViewPublicationPage/Footer.tsx @@ -7,6 +7,7 @@ import { getQuestionById } from "@root/quizData/actions"; import { useQuizViewStore } from "@root/quizView/store"; import { enqueueSnackbar } from "notistack"; import { NameplateLogoFQ } from "@icons/NameplateLogoFQ"; +import { checkEmptyData } from "./tools/checkEmptyData"; type FooterProps = { setCurrentQuestion: (step: AnyTypedQuizQuestion) => void; @@ -21,6 +22,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh const { settings, items } = useQuestionsStore(); const { answers } = useQuizViewStore(); + const [stepNumber, setStepNumber] = useState(1); const [disablePreviousButton, setDisablePreviousButton] = useState(false); const [disableNextButton, setDisableNextButton] = useState(false); @@ -79,13 +81,34 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh }, [question, answers]); const showResult = (nextQuestion: any) => { - console.log(nextQuestion); - - if (nextQuestion && settings?.cfg.resultInfo.when === "before") { - setShowResultForm(true); - } else { + if (nextQuestion && settings?.cfg.resultInfo.when === "email") { setShowContactForm(true); + return; } + + const isEmpty = checkEmptyData({ resultData: nextQuestion }) + console.log("пустой результат? ", isEmpty) + if (nextQuestion) { + if (nextQuestion && settings?.cfg.resultInfo.when === "before") { + if (isEmpty) { + setShowContactForm(true); //до+пустая = кидать на ФК + console.log("до+пустая = кидать на ФК") + } else { + setShowResultForm(true); //до+заполнена = показать + console.log("до+заполнена = показать") + } + } + if (nextQuestion && settings?.cfg.resultInfo.when === "after") { + if (isEmpty) { + setShowContactForm(true); //после+пустая + console.log("после+пустая") + } else { + setShowContactForm(true); //после+заполнена = показать ФК + console.log("после+заполнена = показать") + } + } + } + }; const getNextQuestionId = () => { @@ -125,6 +148,8 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh const followPreviousStep = () => { if (linear) { + setStepNumber(q => q - 1) + const questionIndex = items.findIndex(({ id }) => id === question.id); const previousQuestion = items[questionIndex - 1]; @@ -150,10 +175,11 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh const followNextStep = () => { if (linear) { + setStepNumber(q => q + 1) + const questionIndex = items.findIndex(({ id }) => id === question.id); const nextQuestion = items[questionIndex + 1]; - console.log(nextQuestion); if (nextQuestion && nextQuestion.type !== "result") { setCurrentQuestion(nextQuestion); } else { @@ -179,7 +205,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh if (nextQuestion?.type && nextQuestion.type !== "result") { setCurrentQuestion(nextQuestion); } else { - showResult(undefined); + showResult(nextQuestion); } } }; @@ -206,6 +232,41 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh }} > + {linear && + <> + + Шаг + + {stepNumber} + + Из + + {items.filter(q => q.type !== "result").length} + + + + } + { @@ -36,7 +36,7 @@ export const ViewPage = () => { const parseData = { settings: { //@ts-ignore - qid: window.location.pathname.replace(/\//g, '') || "e0857d80-2cdb-43cc-bc00-04c0af725da1", + qid: QID, fp: settings.fp, rep: settings.rep, name: settings.name, diff --git a/src/pages/ViewPublicationPage/tools/checkEmptyData.ts b/src/pages/ViewPublicationPage/tools/checkEmptyData.ts new file mode 100644 index 0000000..4946137 --- /dev/null +++ b/src/pages/ViewPublicationPage/tools/checkEmptyData.ts @@ -0,0 +1,17 @@ +import { QuizQuestionResult } from "@model/questionTypes/result" + +export const checkEmptyData = ({ resultData }: { resultData: QuizQuestionResult }) => { + let check = true + if ( + resultData.title.length > 0 || + resultData.description.length > 0 || + resultData.content.back.length > 0 || + resultData.content.originalBack.length > 0 || + resultData.content.innerName.length > 0 || + resultData.content.text.length > 0 || + resultData.content.video.length > 0 || + resultData.content.hint.text.length > 0 + ) check = false + return check + } + \ No newline at end of file