резулт показывается после ФК при типа квиза емейл+ единоразовое отправление данных при кликах

This commit is contained in:
Nastya 2023-12-31 03:04:35 +03:00
parent d68285fa3d
commit b4f1bb8909
3 changed files with 64 additions and 38 deletions

@ -16,6 +16,8 @@ import { enqueueSnackbar } from "notistack";
import { sendFC } from "@api/quizRelase";
import { NameplateLogo } from "@icons/NameplateLogo";
import { modes } from "../../utils/themes/Publication/themePublication";
import { QuizQuestionResult } from "@model/questionTypes/result";
import { ApologyPage } from "./ApologyPage";
type ContactFormProps = {
currentQuestion: any;
@ -47,6 +49,9 @@ 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);
@ -54,7 +59,7 @@ export const ContactForm = ({
const theme = useTheme();
const mode = modes;
//@ts-ignore
const resultQuestion = items.find((question) => {
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={{
@ -179,25 +186,38 @@ export const ContactForm = ({
// settings?.cfg.resultInfo.when === "after" &&
(
<Button
disabled={!ready}
disabled={!(ready && !fire)}
variant="contained" onClick={async () => {
//@ts-ignore
if (!checkEmptyData({ resultData: resultQuestion })) {
setFire(true)
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") {
try {
if (settings?.cfg.resultInfo.when === "after" || settings?.cfg.resultInfo.when === "email" && !checkEmptyData({ resultData: resultQuestion })) {
setShowContactForm(false)
setShowResultForm(true)
} catch (e) {
enqueueSnackbar("повторите попытку позже")
}
} else {
enqueueSnackbar("Пожалуйста, заполните поля")
}
}
setFire(false)
}}
>
{settings?.cfg.formContact?.button || "Получить результаты"}
@ -229,12 +249,16 @@ export const ContactForm = ({
gap: "15px"
}}
>
<NameplateLogo style={{ fontSize: "34px",
<NameplateLogo style={{
fontSize: "34px",
//@ts-ignore
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF" }} />
<Typography sx={{ fontSize: "20px",
color: mode[settings.cfg.theme] ? "#151515" : "#FFFFFF"
}} />
<Typography sx={{
fontSize: "20px",
//@ts-ignore
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap" }}>
color: mode[settings.cfg.theme] ? "#4D4D4D" : "#F5F7FF", whiteSpace: "nowrap"
}}>
Сделано на Penasettings
</Typography>
</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}