шаги в линейной публикации, пустые резулты не отображаются

This commit is contained in:
Nastya 2023-12-23 21:03:34 +03:00
parent 6417e70736
commit 9e00ee4966
4 changed files with 115 additions and 11 deletions

@ -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 (
<Box
sx={{
@ -111,7 +129,12 @@ export const ContactForm = ({
<Button
disabled={!ready}
variant="contained" onClick={() => {
if (settings?.cfg.resultInfo.when === "after") followNextForm()
//@ts-ignore
if (settings?.cfg.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) {
setShowContactForm(false)
setShowResultForm(true)
}
}}>
Получить результаты
</Button>
@ -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

@ -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<boolean>(false);
const [disableNextButton, setDisableNextButton] = useState<boolean>(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
}}
>
<NameplateLogoFQ style={{ fontSize: "34px", width: "200px", height: "auto" }} />
{linear &&
<>
<Box
sx={{
display: "flex",
alignItems: "center",
gap: "10px",
marginRight: "auto",
color: theme.palette.grey1.main,
}}
>
<Typography>Шаг</Typography>
<Typography
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
fontWeight: "bold",
borderRadius: "50%",
width: "30px",
height: "30px",
color: "#FFF",
background: theme.palette.brightPurple.main,
}}
>
{stepNumber}
</Typography>
<Typography>Из</Typography>
<Typography sx={{ fontWeight: "bold" }}>
{items.filter(q => q.type !== "result").length}
</Typography>
</Box>
</>
}
<Box
sx={{
display: "flex",

@ -16,7 +16,7 @@ const QID =
process.env.NODE_ENV === "production" ?
window.location.pathname.replace(/\//g, '')
:
"e0857d80-2cdb-43cc-bc00-04c0af725da1"
"d9c352bb-8423-483c-9ca2-9398d1d5c60e"
export const ViewPage = () => {
@ -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,

@ -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
}