резулт показывается после ФК при типа квиза емейл+ единоразовое отправление данных при кликах
This commit is contained in:
parent
d68285fa3d
commit
b4f1bb8909
@ -16,6 +16,8 @@ import { enqueueSnackbar } from "notistack";
|
|||||||
import { sendFC } from "@api/quizRelase";
|
import { sendFC } from "@api/quizRelase";
|
||||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||||
import { modes } from "../../utils/themes/Publication/themePublication";
|
import { modes } from "../../utils/themes/Publication/themePublication";
|
||||||
|
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||||
|
import { ApologyPage } from "./ApologyPage";
|
||||||
|
|
||||||
type ContactFormProps = {
|
type ContactFormProps = {
|
||||||
currentQuestion: any;
|
currentQuestion: any;
|
||||||
@ -47,6 +49,9 @@ export const ContactForm = ({
|
|||||||
const [text, setText] = useState("")
|
const [text, setText] = useState("")
|
||||||
const [adress, setAdress] = useState("")
|
const [adress, setAdress] = useState("")
|
||||||
|
|
||||||
|
const fireOnce = useRef(true)
|
||||||
|
const [fire, setFire] = useState(false)
|
||||||
|
|
||||||
const followNextForm = () => {
|
const followNextForm = () => {
|
||||||
setShowContactForm(false);
|
setShowContactForm(false);
|
||||||
setShowResultForm(true);
|
setShowResultForm(true);
|
||||||
@ -54,7 +59,7 @@ export const ContactForm = ({
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const mode = modes;
|
const mode = modes;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const resultQuestion = items.find((question) => {
|
const resultQuestion: QuizQuestionResult = items.find((question) => {
|
||||||
if (settings?.cfg.haveRoot) { //ветвимся
|
if (settings?.cfg.haveRoot) { //ветвимся
|
||||||
return (
|
return (
|
||||||
question.type === "result" &&
|
question.type === "result" &&
|
||||||
@ -101,6 +106,8 @@ export const ContactForm = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!resultQuestion) return <ApologyPage message="не получилось найти результат для этой ветки :(" />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -179,25 +186,38 @@ export const ContactForm = ({
|
|||||||
// settings?.cfg.resultInfo.when === "after" &&
|
// settings?.cfg.resultInfo.when === "after" &&
|
||||||
(
|
(
|
||||||
<Button
|
<Button
|
||||||
disabled={!ready}
|
disabled={!(ready && !fire)}
|
||||||
variant="contained" onClick={async () => {
|
variant="contained" onClick={async () => {
|
||||||
//@ts-ignore
|
setFire(true)
|
||||||
if (!checkEmptyData({ resultData: resultQuestion })) {
|
|
||||||
|
|
||||||
|
if (fireOnce.current) {
|
||||||
|
if (
|
||||||
|
name.length > 0 ||
|
||||||
|
email.length > 0 ||
|
||||||
|
phone.length > 0 ||
|
||||||
|
text.length > 0 ||
|
||||||
|
adress.length > 0
|
||||||
|
) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await inputHC()
|
await inputHC()
|
||||||
|
fireOnce.current = false
|
||||||
|
enqueueSnackbar("Данные успешно отправлены")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("повторите попытку позже")
|
enqueueSnackbar("повторите попытку позже")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email" && !checkEmptyData({ resultData: resultQuestion })) {
|
||||||
if (settings?.cfg.resultInfo.when === "after") {
|
|
||||||
try {
|
|
||||||
setShowContactForm(false)
|
setShowContactForm(false)
|
||||||
setShowResultForm(true)
|
setShowResultForm(true)
|
||||||
} catch (e) {
|
}
|
||||||
enqueueSnackbar("повторите попытку позже")
|
} else {
|
||||||
|
enqueueSnackbar("Пожалуйста, заполните поля")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFire(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{settings?.cfg.formContact?.button || "Получить результаты"}
|
{settings?.cfg.formContact?.button || "Получить результаты"}
|
||||||
@ -229,12 +249,16 @@ export const ContactForm = ({
|
|||||||
gap: "15px"
|
gap: "15px"
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NameplateLogo style={{ fontSize: "34px",
|
<NameplateLogo style={{
|
||||||
|
fontSize: "34px",
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF" }} />
|
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF"
|
||||||
<Typography sx={{ fontSize: "20px",
|
}} />
|
||||||
|
<Typography sx={{
|
||||||
|
fontSize: "20px",
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap" }}>
|
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap"
|
||||||
|
}}>
|
||||||
Сделано на Penasettings
|
Сделано на Penasettings
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -103,7 +103,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextQuestion && settings?.cfg.resultInfo.when === "after") {
|
if (nextQuestion && (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email")) {
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
setShowContactForm(true); //после+пустая
|
setShowContactForm(true); //после+пустая
|
||||||
|
|
||||||
@ -117,8 +117,9 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getNextQuestionId = () => {
|
const getNextQuestionId = () => {
|
||||||
console.log("net")
|
console.log("Смотрим какой вопрос будет дальше. Что у нас сегодня вкусненького? Щя покажу от какого вопроса мы ищем следующий шаг")
|
||||||
console.log(question)
|
console.log(question)
|
||||||
|
console.log("От вот этого /|")
|
||||||
let readyBeNextQuestion = "";
|
let readyBeNextQuestion = "";
|
||||||
|
|
||||||
//вопрос обязателен, анализируем ответ и условия ветвления
|
//вопрос обязателен, анализируем ответ и условия ветвления
|
||||||
@ -157,7 +158,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
if (!question.required) {//вопрос не обязателен и не нашли совпадений между ответами и условиями ветвления
|
if (!question.required) {//вопрос не обязателен и не нашли совпадений между ответами и условиями ветвления
|
||||||
console.log("вопрос не обязателен ищем дальше")
|
console.log("вопрос не обязателен ищем дальше")
|
||||||
const defaultQ = question.content.rule.default
|
const defaultQ = question.content.rule.default
|
||||||
if (defaultQ) return defaultQ
|
if (defaultQ.length > 1 && defaultQ !== " ") return defaultQ
|
||||||
//Вопросы типа страница, ползунок, своё поле для ввода и дата не могут иметь больше 1 ребёнка. Пользователь не может настроить там дефолт
|
//Вопросы типа страница, ползунок, своё поле для ввода и дата не могут иметь больше 1 ребёнка. Пользователь не может настроить там дефолт
|
||||||
//Кинуть на ребёнка надо даже если там нет дефолта
|
//Кинуть на ребёнка надо даже если там нет дефолта
|
||||||
if (
|
if (
|
||||||
@ -227,6 +228,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nextQuestionId = getNextQuestionId();
|
const nextQuestionId = getNextQuestionId();
|
||||||
|
console.log(nextQuestionId)
|
||||||
|
|
||||||
if (nextQuestionId) {
|
if (nextQuestionId) {
|
||||||
const nextQuestion = getQuestionById(nextQuestionId);
|
const nextQuestion = getQuestionById(nextQuestionId);
|
||||||
|
@ -118,7 +118,7 @@ export const Question = ({ questions }: QuestionProps) => {
|
|||||||
setShowResultForm={setShowResultForm}
|
setShowResultForm={setShowResultForm}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showResultForm && settings?.cfg.resultInfo.when === "after" && (
|
{showResultForm && (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email") && (
|
||||||
<ResultForm
|
<ResultForm
|
||||||
currentQuestion={currentQuestion}
|
currentQuestion={currentQuestion}
|
||||||
showContactForm={showContactForm}
|
showContactForm={showContactForm}
|
||||||
|
Loading…
Reference in New Issue
Block a user