резулт показывается после ФК при типа квиза емейл+ единоразовое отправление данных при кликах
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 { sendFC } from "@api/quizRelase";
|
||||
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 = {
|
||||
currentQuestion: any;
|
||||
@ -47,14 +49,17 @@ export const ContactForm = ({
|
||||
const [text, setText] = useState("")
|
||||
const [adress, setAdress] = useState("")
|
||||
|
||||
const fireOnce = useRef(true)
|
||||
const [fire, setFire] = useState(false)
|
||||
|
||||
const followNextForm = () => {
|
||||
setShowContactForm(false);
|
||||
setShowResultForm(true);
|
||||
};
|
||||
const theme = useTheme();
|
||||
const mode = modes;
|
||||
//@ts-ignore
|
||||
const resultQuestion = items.find((question) => {
|
||||
//@ts-ignore
|
||||
const resultQuestion: QuizQuestionResult = items.find((question) => {
|
||||
if (settings?.cfg.haveRoot) { //ветвимся
|
||||
return (
|
||||
question.type === "result" &&
|
||||
@ -101,6 +106,8 @@ export const ContactForm = ({
|
||||
}
|
||||
}
|
||||
|
||||
if (!resultQuestion) return <ApologyPage message="не получилось найти результат для этой ветки :(" />
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@ -125,7 +132,7 @@ export const ContactForm = ({
|
||||
textAlign: "center",
|
||||
m: "20px 0",
|
||||
fontSize: "28px",
|
||||
color: theme.palette.text.primary
|
||||
color: theme.palette.text.primary
|
||||
}}
|
||||
>
|
||||
{settings?.cfg.formContact.title || "Заполните форму, чтобы получить результаты теста"}
|
||||
@ -152,7 +159,7 @@ export const ContactForm = ({
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexDirection: "column",
|
||||
backgroundColor: theme.palette.background.default,
|
||||
backgroundColor: theme.palette.background.default,
|
||||
p: "30px"
|
||||
}}>
|
||||
|
||||
@ -179,27 +186,40 @@ export const ContactForm = ({
|
||||
// settings?.cfg.resultInfo.when === "after" &&
|
||||
(
|
||||
<Button
|
||||
disabled={!ready}
|
||||
disabled={!(ready && !fire)}
|
||||
variant="contained" onClick={async () => {
|
||||
//@ts-ignore
|
||||
if (!checkEmptyData({ resultData: resultQuestion })) {
|
||||
try {
|
||||
await inputHC()
|
||||
} catch (e) {
|
||||
enqueueSnackbar("повторите попытку позже")
|
||||
}
|
||||
setFire(true)
|
||||
|
||||
}
|
||||
if (settings?.cfg.resultInfo.when === "after") {
|
||||
try {
|
||||
setShowContactForm(false)
|
||||
setShowResultForm(true)
|
||||
} catch (e) {
|
||||
enqueueSnackbar("повторите попытку позже")
|
||||
|
||||
if (fireOnce.current) {
|
||||
if (
|
||||
name.length > 0 ||
|
||||
email.length > 0 ||
|
||||
phone.length > 0 ||
|
||||
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 || "Получить результаты"}
|
||||
</Button>
|
||||
)}
|
||||
@ -211,13 +231,13 @@ export const ContactForm = ({
|
||||
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>
|
||||
С 
|
||||
<Link> Положением об обработке персональных данных </Link>
|
||||
 и 
|
||||
<Link> Политикой конфиденциальности </Link>
|
||||
 ознакомлен
|
||||
<Link> Положением об обработке персональных данных </Link>
|
||||
 и 
|
||||
<Link> Политикой конфиденциальности </Link>
|
||||
 ознакомлен
|
||||
</Typography>
|
||||
|
||||
</Box>
|
||||
@ -226,16 +246,20 @@ export const ContactForm = ({
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
mt: "20px",
|
||||
gap: "15px"
|
||||
gap: "15px"
|
||||
}}
|
||||
>
|
||||
<NameplateLogo style={{ fontSize: "34px",
|
||||
//@ts-ignore
|
||||
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF" }} />
|
||||
<Typography sx={{ fontSize: "20px",
|
||||
//@ts-ignore
|
||||
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap" }}>
|
||||
Сделано на Penasettings
|
||||
<NameplateLogo style={{
|
||||
fontSize: "34px",
|
||||
//@ts-ignore
|
||||
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF"
|
||||
}} />
|
||||
<Typography sx={{
|
||||
fontSize: "20px",
|
||||
//@ts-ignore
|
||||
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap"
|
||||
}}>
|
||||
Сделано на Penasettings
|
||||
</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) {
|
||||
setShowContactForm(true); //после+пустая
|
||||
|
||||
@ -117,8 +117,9 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
};
|
||||
|
||||
const getNextQuestionId = () => {
|
||||
console.log("net")
|
||||
console.log("Смотрим какой вопрос будет дальше. Что у нас сегодня вкусненького? Щя покажу от какого вопроса мы ищем следующий шаг")
|
||||
console.log(question)
|
||||
console.log("От вот этого /|")
|
||||
let readyBeNextQuestion = "";
|
||||
|
||||
//вопрос обязателен, анализируем ответ и условия ветвления
|
||||
@ -157,7 +158,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
if (!question.required) {//вопрос не обязателен и не нашли совпадений между ответами и условиями ветвления
|
||||
console.log("вопрос не обязателен ищем дальше")
|
||||
const defaultQ = question.content.rule.default
|
||||
if (defaultQ) return defaultQ
|
||||
if (defaultQ.length > 1 && defaultQ !== " ") return defaultQ
|
||||
//Вопросы типа страница, ползунок, своё поле для ввода и дата не могут иметь больше 1 ребёнка. Пользователь не может настроить там дефолт
|
||||
//Кинуть на ребёнка надо даже если там нет дефолта
|
||||
if (
|
||||
@ -227,6 +228,7 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
}
|
||||
|
||||
const nextQuestionId = getNextQuestionId();
|
||||
console.log(nextQuestionId)
|
||||
|
||||
if (nextQuestionId) {
|
||||
const nextQuestion = getQuestionById(nextQuestionId);
|
||||
|
@ -118,7 +118,7 @@ export const Question = ({ questions }: QuestionProps) => {
|
||||
setShowResultForm={setShowResultForm}
|
||||
/>
|
||||
)}
|
||||
{showResultForm && settings?.cfg.resultInfo.when === "after" && (
|
||||
{showResultForm && (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email") && (
|
||||
<ResultForm
|
||||
currentQuestion={currentQuestion}
|
||||
showContactForm={showContactForm}
|
||||
|
Loading…
Reference in New Issue
Block a user