шаги в линейной публикации, пустые резулты не отображаются
This commit is contained in:
parent
6417e70736
commit
9e00ee4966
@ -10,6 +10,7 @@ import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useQuestionsStore } from "@root/quizData/store";
|
import { useQuestionsStore } from "@root/quizData/store";
|
||||||
|
|
||||||
|
import { checkEmptyData } from "./tools/checkEmptyData";
|
||||||
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { sendFC } from "@api/quizRelase";
|
import { sendFC } from "@api/quizRelase";
|
||||||
@ -36,7 +37,7 @@ export const ContactForm = ({
|
|||||||
setShowContactForm,
|
setShowContactForm,
|
||||||
setShowResultForm,
|
setShowResultForm,
|
||||||
}: ContactFormProps) => {
|
}: ContactFormProps) => {
|
||||||
const { settings } = useQuestionsStore()
|
const { settings, items } = useQuestionsStore()
|
||||||
|
|
||||||
const [ready, setReady] = useState(false)
|
const [ready, setReady] = useState(false)
|
||||||
|
|
||||||
@ -45,6 +46,23 @@ export const ContactForm = ({
|
|||||||
setShowResultForm(true);
|
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 (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -111,7 +129,12 @@ export const ContactForm = ({
|
|||||||
<Button
|
<Button
|
||||||
disabled={!ready}
|
disabled={!ready}
|
||||||
variant="contained" onClick={() => {
|
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>
|
</Button>
|
||||||
@ -200,6 +223,9 @@ const Inputs = (currentQuestion: any) => {
|
|||||||
inputHC()
|
inputHC()
|
||||||
}, [name, email, phone, text, adress])
|
}, [name, email, phone, text, adress])
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
console.log(settings)
|
||||||
|
console.log(settings?.cfg)
|
||||||
|
console.log(settings?.cfg.formContact)
|
||||||
const FC: any = settings?.cfg.formContact
|
const FC: any = settings?.cfg.formContact
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
@ -7,6 +7,7 @@ import { getQuestionById } from "@root/quizData/actions";
|
|||||||
import { useQuizViewStore } from "@root/quizView/store";
|
import { useQuizViewStore } from "@root/quizView/store";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
||||||
|
import { checkEmptyData } from "./tools/checkEmptyData";
|
||||||
|
|
||||||
type FooterProps = {
|
type FooterProps = {
|
||||||
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
|
setCurrentQuestion: (step: AnyTypedQuizQuestion) => void;
|
||||||
@ -21,6 +22,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
const { settings, items } = useQuestionsStore();
|
const { settings, items } = useQuestionsStore();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
|
|
||||||
|
const [stepNumber, setStepNumber] = useState(1);
|
||||||
const [disablePreviousButton, setDisablePreviousButton] = useState<boolean>(false);
|
const [disablePreviousButton, setDisablePreviousButton] = useState<boolean>(false);
|
||||||
const [disableNextButton, setDisableNextButton] = useState<boolean>(false);
|
const [disableNextButton, setDisableNextButton] = useState<boolean>(false);
|
||||||
|
|
||||||
@ -79,13 +81,34 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
}, [question, answers]);
|
}, [question, answers]);
|
||||||
|
|
||||||
const showResult = (nextQuestion: any) => {
|
const showResult = (nextQuestion: any) => {
|
||||||
console.log(nextQuestion);
|
if (nextQuestion && settings?.cfg.resultInfo.when === "email") {
|
||||||
|
|
||||||
if (nextQuestion && settings?.cfg.resultInfo.when === "before") {
|
|
||||||
setShowResultForm(true);
|
|
||||||
} else {
|
|
||||||
setShowContactForm(true);
|
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 = () => {
|
const getNextQuestionId = () => {
|
||||||
@ -125,6 +148,8 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
|
|
||||||
const followPreviousStep = () => {
|
const followPreviousStep = () => {
|
||||||
if (linear) {
|
if (linear) {
|
||||||
|
setStepNumber(q => q - 1)
|
||||||
|
|
||||||
const questionIndex = items.findIndex(({ id }) => id === question.id);
|
const questionIndex = items.findIndex(({ id }) => id === question.id);
|
||||||
|
|
||||||
const previousQuestion = items[questionIndex - 1];
|
const previousQuestion = items[questionIndex - 1];
|
||||||
@ -150,10 +175,11 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
|
|
||||||
const followNextStep = () => {
|
const followNextStep = () => {
|
||||||
if (linear) {
|
if (linear) {
|
||||||
|
setStepNumber(q => q + 1)
|
||||||
|
|
||||||
const questionIndex = items.findIndex(({ id }) => id === question.id);
|
const questionIndex = items.findIndex(({ id }) => id === question.id);
|
||||||
const nextQuestion = items[questionIndex + 1];
|
const nextQuestion = items[questionIndex + 1];
|
||||||
|
|
||||||
console.log(nextQuestion);
|
|
||||||
if (nextQuestion && nextQuestion.type !== "result") {
|
if (nextQuestion && nextQuestion.type !== "result") {
|
||||||
setCurrentQuestion(nextQuestion);
|
setCurrentQuestion(nextQuestion);
|
||||||
} else {
|
} else {
|
||||||
@ -179,7 +205,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
if (nextQuestion?.type && nextQuestion.type !== "result") {
|
if (nextQuestion?.type && nextQuestion.type !== "result") {
|
||||||
setCurrentQuestion(nextQuestion);
|
setCurrentQuestion(nextQuestion);
|
||||||
} else {
|
} else {
|
||||||
showResult(undefined);
|
showResult(nextQuestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -206,6 +232,41 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NameplateLogoFQ style={{ fontSize: "34px", width: "200px", height: "auto" }} />
|
<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
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
@ -16,7 +16,7 @@ const QID =
|
|||||||
process.env.NODE_ENV === "production" ?
|
process.env.NODE_ENV === "production" ?
|
||||||
window.location.pathname.replace(/\//g, '')
|
window.location.pathname.replace(/\//g, '')
|
||||||
:
|
:
|
||||||
"e0857d80-2cdb-43cc-bc00-04c0af725da1"
|
"d9c352bb-8423-483c-9ca2-9398d1d5c60e"
|
||||||
|
|
||||||
|
|
||||||
export const ViewPage = () => {
|
export const ViewPage = () => {
|
||||||
@ -36,7 +36,7 @@ export const ViewPage = () => {
|
|||||||
const parseData = {
|
const parseData = {
|
||||||
settings: {
|
settings: {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
qid: window.location.pathname.replace(/\//g, '') || "e0857d80-2cdb-43cc-bc00-04c0af725da1",
|
qid: QID,
|
||||||
fp: settings.fp,
|
fp: settings.fp,
|
||||||
rep: settings.rep,
|
rep: settings.rep,
|
||||||
name: settings.name,
|
name: settings.name,
|
||||||
|
17
src/pages/ViewPublicationPage/tools/checkEmptyData.ts
Normal file
17
src/pages/ViewPublicationPage/tools/checkEmptyData.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user