2024-05-06 13:47:19 +00:00
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
|
import { Box, Button, Link, Typography, useTheme } from "@mui/material";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2024-05-04 12:57:14 +00:00
|
|
|
|
|
2024-05-06 13:47:19 +00:00
|
|
|
|
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
2024-05-04 12:57:14 +00:00
|
|
|
|
|
2024-05-06 13:47:19 +00:00
|
|
|
|
import { Inputs } from "@/components/ViewPublicationPage/ContactForm/Inputs/Inputs";
|
2024-05-10 10:15:53 +00:00
|
|
|
|
import { ContactTextBlock } from "./ContactTextBlock";
|
2024-05-06 13:47:19 +00:00
|
|
|
|
|
|
|
|
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
|
|
|
|
import { useQuizData } from "@contexts/QuizDataContext";
|
|
|
|
|
|
|
|
|
|
import { sendFC, SendFCParams } from "@api/quizRelase";
|
|
|
|
|
|
|
|
|
|
import { useVkMetricsGoals } from "@/utils/hooks/metrics/useVkMetricsGoals";
|
|
|
|
|
import { useYandexMetricsGoals } from "@/utils/hooks/metrics/useYandexMetricsGoals";
|
|
|
|
|
|
|
|
|
|
import { EMAIL_REGEXP } from "@utils/emailRegexp";
|
|
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
|
|
|
|
import { DESIGN_LIST } from "@utils/designList";
|
|
|
|
|
|
|
|
|
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
|
|
|
|
|
|
|
|
|
import type {
|
2024-05-05 22:07:15 +00:00
|
|
|
|
FormContactFieldData,
|
|
|
|
|
FormContactFieldName,
|
2024-05-06 13:47:19 +00:00
|
|
|
|
} from "@model/settingsData";
|
|
|
|
|
import type { QuizQuestionResult } from "@model/questionTypes/result";
|
|
|
|
|
import type { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
2024-01-05 17:00:30 +00:00
|
|
|
|
|
2024-02-08 13:42:31 +00:00
|
|
|
|
type Props = {
|
2024-04-17 11:28:42 +00:00
|
|
|
|
currentQuestion: AnyTypedQuizQuestion;
|
|
|
|
|
onShowResult: () => void;
|
2023-12-16 14:55:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-04-09 19:52:45 +00:00
|
|
|
|
export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
2024-04-17 11:28:42 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const { settings, questions, quizId, show_badge, preview } = useQuizData();
|
|
|
|
|
|
|
|
|
|
const [ready, setReady] = useState(false);
|
|
|
|
|
const [name, setName] = useState("");
|
|
|
|
|
const [email, setEmail] = useState("");
|
|
|
|
|
const [phone, setPhone] = useState("");
|
|
|
|
|
const [text, setText] = useState("");
|
|
|
|
|
const [adress, setAdress] = useState("");
|
|
|
|
|
const [screenHeight, setScreenHeight] = useState<number>(window.innerHeight);
|
|
|
|
|
|
|
|
|
|
const fireOnce = useRef(true);
|
|
|
|
|
const [fire, setFire] = useState(false);
|
|
|
|
|
const isMobile = useRootContainerSize() < 850;
|
|
|
|
|
const isTablet = useRootContainerSize() < 1000;
|
|
|
|
|
|
2024-05-06 13:47:19 +00:00
|
|
|
|
const vkMetrics = useVkMetricsGoals(settings.cfg.vkMetricsNumber);
|
|
|
|
|
const yandexMetrics = useYandexMetricsGoals(settings.cfg.yandexMetricsNumber);
|
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
function handleResize() {
|
|
|
|
|
setScreenHeight(window.innerHeight);
|
|
|
|
|
}
|
2024-01-30 16:49:33 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
window.addEventListener("resize", handleResize);
|
2024-01-31 12:57:07 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener("resize", handleResize);
|
2024-01-31 12:57:07 +00:00
|
|
|
|
};
|
2024-04-17 11:28:42 +00:00
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const resultQuestion =
|
|
|
|
|
currentQuestion.type === "result"
|
|
|
|
|
? currentQuestion
|
|
|
|
|
: questions.find((question): question is QuizQuestionResult => {
|
2024-05-06 13:47:19 +00:00
|
|
|
|
if (settings?.cfg.haveRoot) {
|
|
|
|
|
return (
|
|
|
|
|
question.type === "result" &&
|
|
|
|
|
question.content.rule.parentId === currentQuestion.content.id
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
question.type === "result" &&
|
|
|
|
|
question.content.rule.parentId === "line"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-01-30 16:49:33 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
if (!resultQuestion) throw new Error("Result question not found");
|
|
|
|
|
|
|
|
|
|
const inputHC = async () => {
|
|
|
|
|
const FC = settings.cfg.formContact.fields || settings.cfg.formContact;
|
2024-04-24 12:53:01 +00:00
|
|
|
|
const body: SendFCParams["body"] = {};
|
2024-04-17 11:28:42 +00:00
|
|
|
|
if (name.length > 0) body.name = name;
|
|
|
|
|
if (email.length > 0) body.email = email;
|
|
|
|
|
if (phone.length > 0) body.phone = phone;
|
|
|
|
|
if (adress.length > 0) body.address = adress;
|
|
|
|
|
if (text.length > 0) body.customs = { [FC.text.text || "Фамилия"]: text };
|
|
|
|
|
|
|
|
|
|
if (Object.keys(body).length > 0) {
|
|
|
|
|
try {
|
|
|
|
|
await sendFC({
|
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
|
body: body,
|
|
|
|
|
qid: quizId,
|
|
|
|
|
preview,
|
|
|
|
|
});
|
2024-02-08 13:42:31 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
"sessions",
|
|
|
|
|
JSON.stringify({ ...sessions, [quizId]: new Date().getTime() })
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
|
}
|
2024-01-30 16:49:33 +00:00
|
|
|
|
}
|
2024-04-17 11:28:42 +00:00
|
|
|
|
};
|
2023-12-24 11:52:09 +00:00
|
|
|
|
|
2024-04-24 12:53:01 +00:00
|
|
|
|
const FCcopy: Record<FormContactFieldName, FormContactFieldData> =
|
2024-04-17 11:28:42 +00:00
|
|
|
|
settings.cfg.formContact.fields || settings.cfg.formContact;
|
2024-02-08 13:42:31 +00:00
|
|
|
|
|
2024-04-24 12:53:01 +00:00
|
|
|
|
const filteredFC: Partial<
|
|
|
|
|
Record<FormContactFieldName, FormContactFieldData>
|
|
|
|
|
> = {};
|
2024-04-17 11:28:42 +00:00
|
|
|
|
for (const i in FCcopy) {
|
2024-04-19 09:44:08 +00:00
|
|
|
|
const field = FCcopy[i as keyof typeof FCcopy];
|
2024-04-17 11:28:42 +00:00
|
|
|
|
if (field.used) {
|
2024-04-19 09:44:08 +00:00
|
|
|
|
filteredFC[i as FormContactFieldName] = field;
|
2024-04-17 11:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-08 13:42:31 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
async function handleShowResultsClick() {
|
2024-04-19 09:44:08 +00:00
|
|
|
|
const FC = settings.cfg.formContact.fields;
|
2024-04-17 11:28:42 +00:00
|
|
|
|
if (FC["email"].used !== EMAIL_REGEXP.test(email)) {
|
|
|
|
|
return enqueueSnackbar("введена некорректная почта");
|
|
|
|
|
}
|
2024-02-08 13:42:31 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
if (fireOnce.current) {
|
|
|
|
|
if (
|
|
|
|
|
name.length === 0 &&
|
|
|
|
|
email.length === 0 &&
|
|
|
|
|
phone.length === 0 &&
|
|
|
|
|
text.length === 0 &&
|
|
|
|
|
adress.length === 0
|
|
|
|
|
)
|
|
|
|
|
return enqueueSnackbar("Пожалуйста, заполните поля");
|
|
|
|
|
|
|
|
|
|
//почта валидна, хоть одно поле заполнено
|
|
|
|
|
setFire(true);
|
|
|
|
|
try {
|
|
|
|
|
await inputHC();
|
|
|
|
|
fireOnce.current = false;
|
2024-04-24 12:53:01 +00:00
|
|
|
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
2024-04-17 11:28:42 +00:00
|
|
|
|
sessions[quizId] = Date.now();
|
|
|
|
|
localStorage.setItem("sessions", JSON.stringify(sessions));
|
2024-05-05 22:07:15 +00:00
|
|
|
|
|
2024-05-06 13:47:19 +00:00
|
|
|
|
vkMetrics.contactsFormFilled();
|
|
|
|
|
yandexMetrics.contactsFormFilled();
|
2024-04-17 11:28:42 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
enqueueSnackbar("повторите попытку позже");
|
|
|
|
|
}
|
|
|
|
|
if (settings.cfg.resultInfo.showResultForm === "after") {
|
|
|
|
|
onShowResult();
|
|
|
|
|
}
|
2024-02-08 13:42:31 +00:00
|
|
|
|
}
|
2023-12-24 11:52:09 +00:00
|
|
|
|
|
2024-04-17 11:28:42 +00:00
|
|
|
|
setFire(false);
|
|
|
|
|
}
|
2024-05-05 22:07:15 +00:00
|
|
|
|
useEffect(() => {
|
2024-05-06 13:47:19 +00:00
|
|
|
|
vkMetrics.contactsFormOpened();
|
|
|
|
|
yandexMetrics.contactsFormOpened();
|
|
|
|
|
}, []);
|
2024-04-17 11:28:42 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
height: screenHeight > 500 ? "100%" : "auto",
|
|
|
|
|
overflow: "auto",
|
|
|
|
|
"&::-webkit-scrollbar": {
|
|
|
|
|
width: "0",
|
|
|
|
|
display: "none",
|
|
|
|
|
msOverflowStyle: "none",
|
|
|
|
|
},
|
|
|
|
|
scrollbarWidth: "none",
|
|
|
|
|
msOverflowStyle: "none",
|
|
|
|
|
backgroundPosition: "center",
|
|
|
|
|
backgroundSize: "cover",
|
|
|
|
|
backgroundImage:
|
|
|
|
|
settings.cfg.design && !isMobile
|
|
|
|
|
? quizThemes[settings.cfg.theme].isLight
|
|
|
|
|
? `url(${DESIGN_LIST[settings.cfg.theme]})`
|
2024-05-06 13:47:19 +00:00
|
|
|
|
: `linear-gradient(90deg, #272626, transparent), url(${
|
|
|
|
|
DESIGN_LIST[settings.cfg.theme]
|
|
|
|
|
})`
|
2024-04-17 11:28:42 +00:00
|
|
|
|
: null,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: !isMobile ? "100%" : isMobile ? undefined : "530px",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
height: isMobile ? "100%" : "auto",
|
|
|
|
|
minHeight: "100%",
|
|
|
|
|
display: isMobile ? undefined : "flex",
|
|
|
|
|
background:
|
|
|
|
|
settings.cfg.design && !isMobile
|
|
|
|
|
? undefined
|
|
|
|
|
: theme.palette.background.default,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-05-10 10:15:53 +00:00
|
|
|
|
<ContactTextBlock settings={settings} />
|
2024-01-06 23:56:13 +00:00
|
|
|
|
<Box
|
2024-04-17 11:28:42 +00:00
|
|
|
|
sx={{
|
2024-05-10 10:15:53 +00:00
|
|
|
|
flexGrow: 0,
|
2024-04-17 11:28:42 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
2024-05-10 10:15:53 +00:00
|
|
|
|
justifyContent: "space-between",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
flexDirection: "column",
|
2024-05-10 10:15:53 +00:00
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
height: "auto",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
2024-01-06 23:56:13 +00:00
|
|
|
|
sx={{
|
2024-04-17 11:28:42 +00:00
|
|
|
|
display: "flex",
|
2024-05-10 10:15:53 +00:00
|
|
|
|
alignItems: isMobile ? undefined : "center",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
justifyContent: "center",
|
|
|
|
|
flexDirection: "column",
|
2024-05-10 10:15:53 +00:00
|
|
|
|
p: isMobile
|
|
|
|
|
? "0 20px"
|
|
|
|
|
: isTablet
|
|
|
|
|
? "0px 40px 30px 60px"
|
|
|
|
|
: "125px 60px 30px 60px",
|
2024-01-06 23:56:13 +00:00
|
|
|
|
}}
|
2024-04-17 11:28:42 +00:00
|
|
|
|
>
|
2024-05-10 10:15:53 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
mt: isMobile ? "10px" : "20px",
|
|
|
|
|
mb: "20px",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
}}
|
2024-05-10 10:15:53 +00:00
|
|
|
|
>
|
|
|
|
|
<Inputs
|
|
|
|
|
name={name}
|
|
|
|
|
setName={setName}
|
|
|
|
|
email={email}
|
|
|
|
|
setEmail={setEmail}
|
|
|
|
|
phone={phone}
|
|
|
|
|
setPhone={setPhone}
|
|
|
|
|
text={text}
|
|
|
|
|
setText={setText}
|
|
|
|
|
adress={adress}
|
|
|
|
|
setAdress={setAdress}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
2024-04-17 11:28:42 +00:00
|
|
|
|
sx={{
|
2024-05-10 10:15:53 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
width: isMobile ? "300px" : "390px",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2024-05-10 10:15:53 +00:00
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label=""
|
|
|
|
|
handleChange={({ target }) => {
|
|
|
|
|
setReady(target.checked);
|
|
|
|
|
}}
|
|
|
|
|
checked={ready}
|
|
|
|
|
colorIcon={theme.palette.primary.main}
|
|
|
|
|
sx={{ marginRight: "0" }}
|
|
|
|
|
/>
|
2024-04-17 11:28:42 +00:00
|
|
|
|
<Typography
|
2024-01-30 16:49:33 +00:00
|
|
|
|
sx={{
|
2024-04-17 11:28:42 +00:00
|
|
|
|
color: theme.palette.text.primary,
|
2024-05-10 10:15:53 +00:00
|
|
|
|
lineHeight: "18.96px",
|
2024-01-30 16:49:33 +00:00
|
|
|
|
}}
|
2024-05-10 10:15:53 +00:00
|
|
|
|
fontSize={"16px"}
|
2024-04-17 11:28:42 +00:00
|
|
|
|
>
|
2024-05-10 10:15:53 +00:00
|
|
|
|
С 
|
|
|
|
|
<Link href={"https://shub.pena.digital/ppdd"} target="_blank">
|
|
|
|
|
Положением об обработке персональных данных{" "}
|
|
|
|
|
</Link>
|
|
|
|
|
 и 
|
|
|
|
|
<Link
|
|
|
|
|
href={"https://shub.pena.digital/docs/privacy"}
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
|
|
|
|
{" "}
|
|
|
|
|
Политикой конфиденциальности{" "}
|
|
|
|
|
</Link>
|
|
|
|
|
 ознакомлен
|
2024-04-17 11:28:42 +00:00
|
|
|
|
</Typography>
|
2024-05-10 10:15:53 +00:00
|
|
|
|
</Box>
|
2024-02-14 11:03:35 +00:00
|
|
|
|
|
2024-05-05 22:07:15 +00:00
|
|
|
|
<Button
|
|
|
|
|
disabled={!(ready && !fire)}
|
|
|
|
|
variant="contained"
|
|
|
|
|
onClick={handleShowResultsClick}
|
|
|
|
|
sx={{
|
|
|
|
|
border: `1px solid ${theme.palette.primary.main}`,
|
|
|
|
|
margin: isMobile ? "auto" : undefined,
|
|
|
|
|
mt: "20px",
|
|
|
|
|
p: "10px 20px",
|
|
|
|
|
"&:disabled": {
|
|
|
|
|
border: "1px solid #9A9AAF",
|
|
|
|
|
color: "#9A9AAF",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{settings.cfg.formContact?.button || "Получить результаты"}
|
|
|
|
|
</Button>
|
2024-05-07 15:25:44 +00:00
|
|
|
|
</Box>
|
2024-04-17 11:28:42 +00:00
|
|
|
|
{show_badge && (
|
|
|
|
|
<Box
|
|
|
|
|
component={Link}
|
|
|
|
|
target={"_blank"}
|
2024-05-06 13:47:19 +00:00
|
|
|
|
href={`https://${
|
|
|
|
|
window.location.hostname.includes("s") ? "s" : ""
|
|
|
|
|
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
|
2024-04-17 11:28:42 +00:00
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
mt: "55px",
|
2024-05-10 10:15:53 +00:00
|
|
|
|
mb: isMobile ? "30px" : isTablet ? "40px" : "50px",
|
2024-04-30 18:57:25 +00:00
|
|
|
|
gap: "10px",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
textDecoration: "none",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<NameplateLogo
|
|
|
|
|
style={{
|
2024-04-30 18:57:25 +00:00
|
|
|
|
fontSize: "20px",
|
2024-04-17 11:28:42 +00:00
|
|
|
|
color: quizThemes[settings.cfg.theme].isLight
|
|
|
|
|
? "#151515"
|
|
|
|
|
: "#FFFFFF",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2024-01-31 12:57:07 +00:00
|
|
|
|
</Box>
|
2024-04-17 11:28:42 +00:00
|
|
|
|
)}
|
2023-12-29 21:31:21 +00:00
|
|
|
|
</Box>
|
2024-04-17 11:28:42 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2024-01-30 16:49:33 +00:00
|
|
|
|
};
|