резулт показывается после ФК при типа квиза емейл+ единоразовое отправление данных при кликах
This commit is contained in:
parent
d68285fa3d
commit
b4f1bb8909
@ -15,7 +15,9 @@ 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";
|
||||||
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,14 +49,17 @@ 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);
|
||||||
};
|
};
|
||||||
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={{
|
||||||
@ -125,7 +132,7 @@ export const ContactForm = ({
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
m: "20px 0",
|
m: "20px 0",
|
||||||
fontSize: "28px",
|
fontSize: "28px",
|
||||||
color: theme.palette.text.primary
|
color: theme.palette.text.primary
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{settings?.cfg.formContact.title || "Заполните форму, чтобы получить результаты теста"}
|
{settings?.cfg.formContact.title || "Заполните форму, чтобы получить результаты теста"}
|
||||||
@ -152,7 +159,7 @@ export const ContactForm = ({
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
backgroundColor: theme.palette.background.default,
|
backgroundColor: theme.palette.background.default,
|
||||||
p: "30px"
|
p: "30px"
|
||||||
}}>
|
}}>
|
||||||
|
|
||||||
@ -179,27 +186,40 @@ 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 })) {
|
|
||||||
try {
|
|
||||||
await inputHC()
|
|
||||||
} catch (e) {
|
|
||||||
enqueueSnackbar("повторите попытку позже")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (settings?.cfg.resultInfo.when === "after") {
|
if (fireOnce.current) {
|
||||||
try {
|
if (
|
||||||
setShowContactForm(false)
|
name.length > 0 ||
|
||||||
setShowResultForm(true)
|
email.length > 0 ||
|
||||||
} catch (e) {
|
phone.length > 0 ||
|
||||||
enqueueSnackbar("повторите попытку позже")
|
text.length > 0 ||
|
||||||
|
adress.length > 0
|
||||||
|
) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
await inputHC()
|
||||||
|
fireOnce.current = false
|
||||||
|
enqueueSnackbar("Данные успешно отправлены")
|
||||||
|
} catch (e) {
|
||||||
|
enqueueSnackbar("повторите попытку позже")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email" && !checkEmptyData({ resultData: resultQuestion })) {
|
||||||
|
setShowContactForm(false)
|
||||||
|
setShowResultForm(true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enqueueSnackbar("Пожалуйста, заполните поля")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFire(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{settings?.cfg.formContact?.button || "Получить результаты"}
|
{settings?.cfg.formContact?.button || "Получить результаты"}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@ -211,13 +231,13 @@ export const ContactForm = ({
|
|||||||
width: "450px",
|
width: "450px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CustomCheckbox label="" handleChange={({ target }) => { setReady(target.checked) }} checked={ready} colorIcon={theme.palette.primary.main}/>
|
<CustomCheckbox label="" handleChange={({ target }) => { setReady(target.checked) }} checked={ready} colorIcon={theme.palette.primary.main} />
|
||||||
<Typography>
|
<Typography>
|
||||||
С 
|
С 
|
||||||
<Link> Положением об обработке персональных данных </Link>
|
<Link> Положением об обработке персональных данных </Link>
|
||||||
 и 
|
 и 
|
||||||
<Link> Политикой конфиденциальности </Link>
|
<Link> Политикой конфиденциальности </Link>
|
||||||
 ознакомлен
|
 ознакомлен
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
@ -226,16 +246,20 @@ export const ContactForm = ({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
mt: "20px",
|
mt: "20px",
|
||||||
gap: "15px"
|
gap: "15px"
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NameplateLogo style={{ fontSize: "34px",
|
<NameplateLogo style={{
|
||||||
//@ts-ignore
|
fontSize: "34px",
|
||||||
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF" }} />
|
//@ts-ignore
|
||||||
<Typography sx={{ fontSize: "20px",
|
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF"
|
||||||
//@ts-ignore
|
}} />
|
||||||
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap" }}>
|
<Typography sx={{
|
||||||
Сделано на Penasettings
|
fontSize: "20px",
|
||||||
|
//@ts-ignore
|
||||||
|
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap"
|
||||||
|
}}>
|
||||||
|
Сделано на Penasettings
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</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