import AddressIcon from "@icons/ContactFormIcon/AddressIcon"; import EmailIcon from "@icons/ContactFormIcon/EmailIcon"; import NameIcon from "@icons/ContactFormIcon/NameIcon"; import PhoneIcon from "@icons/ContactFormIcon/PhoneIcon"; import TextIcon from "@icons/ContactFormIcon/TextIcon"; import { Box, Button, InputAdornment, Link, TextField as MuiTextField, TextFieldProps, Typography, useTheme } from "@mui/material"; import CustomCheckbox from "@ui_kit/CustomCheckbox"; import { FC, useRef, useState } from "react"; import { sendFC } from "@api/quizRelase"; import { NameplateLogo } from "@icons/NameplateLogo"; import { QuizQuestionResult } from "@model/questionTypes/result"; import { useQuizData } from "@utils/hooks/useQuizData"; import { quizThemes } from "@utils/themes/Publication/themePublication"; import { enqueueSnackbar } from "notistack"; import { useRootContainerSize } from "../../contexts/RootContainerWidthContext"; import { ApologyPage } from "./ApologyPage"; import { checkEmptyData } from "./tools/checkEmptyData"; const TextField = MuiTextField as unknown as FC; // temporary fix ts(2590) const EMAIL_REGEXP = /^(([^<>()[\].,:\s@"]+(\.[^<>()[\].,:\s@"]+)*)|(".+"))@(([^<>()[\].,:\s@"]+\.)+[^<>()[\].,:\s@"]{2,})$/iu; type ContactFormProps = { currentQuestion: any; showResultForm: boolean; setShowContactForm: (show: boolean) => void; setShowResultForm: (show: boolean) => void; }; const icons = [ { type: "name", icon: NameIcon, defaultText: "Введите имя", defaultTitle: "имя", backendName: "name", }, { type: "email", icon: EmailIcon, defaultText: "Введите Email", defaultTitle: "Email", backendName: "email", }, { type: "phone", icon: PhoneIcon, defaultText: "Введите номер телефона", defaultTitle: "номер телефона", backendName: "phone", }, { type: "text", icon: TextIcon, defaultText: "Введите фамилию", defaultTitle: "фамилию", backendName: "adress", }, { type: "address", icon: AddressIcon, defaultText: "Введите адрес", defaultTitle: "адрес", backendName: "adress", }, ]; export const ContactForm = ({ currentQuestion, showResultForm, setShowContactForm, setShowResultForm, }: ContactFormProps) => { const theme = useTheme(); const { settings, questions } = 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 fireOnce = useRef(true); const [fire, setFire] = useState(false); const isMobile = useRootContainerSize() < 850; const followNextForm = () => { setShowContactForm(false); setShowResultForm(true); }; //@ts-ignore const resultQuestion: QuizQuestionResult = questions.find((question) => { if (settings?.cfg.haveRoot) { //ветвимся return ( question.type === "result" && //@ts-ignore question.content.rule.parentId === currentQuestion.content.id ); } else { // не ветвимся return ( question.type === "result" && question.content.rule.parentId === "line" ); } }); const inputHC = async () => { //@ts-ignore const FC = settings?.cfg.formContact.fields || settings?.cfg.formContact; const body = {}; //@ts-ignore if (name.length > 0) body.name = name; //@ts-ignore if (email.length > 0) body.email = email; //@ts-ignore if (phone.length > 0) body.phone = phone; //@ts-ignore if (adress.length > 0) body.address = adress; //@ts-ignore if (text.length > 0) body.customs = { [FC.text.text || "Фамилия"]: text }; if (Object.keys(body).length > 0) { try { await sendFC({ questionId: resultQuestion?.id, body: body, qid: settings.qid, }); const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); localStorage.setItem( "sessions", JSON.stringify({ ...sessions, [settings.qid]: new Date().getTime() }) ); } catch (e) { enqueueSnackbar("ответ не был засчитан"); } } }; //@ts-ignore let FCcopy: any = settings?.cfg.formContact.fields || settings?.cfg.formContact; let filteredFC: any = {}; for (let i in FCcopy) { let field = FCcopy[i]; console.log(filteredFC); if (field.used) { filteredFC[i] = field; } } let isWide = Object.keys(filteredFC).length > 2; if (!resultQuestion) return ( ); return ( {settings?.cfg.formContact.title || "Заполните форму, чтобы получить результаты теста"} {settings?.cfg.formContact.desc && ( {settings?.cfg.formContact.desc} )} { // resultQuestion && // settings?.cfg.resultInfo.when === "after" && } { setReady(target.checked); }} checked={ready} colorIcon={theme.palette.primary.main} /> С  Положением об обработке персональных данных{" "}  и  {" "} Политикой конфиденциальности{" "}  ознакомлен Сделано на PenaQuiz ); }; const Inputs = ({ name, setName, email, setEmail, phone, setPhone, text, setText, adress, setAdress, }: any) => { const { settings } = useQuizData(); // @ts-ignore const FC = settings?.cfg.formContact.fields || settings?.cfg.formContact; if (!FC) return null; //@ts-ignore const Name = ( setName(target.value)} id={name} title={FC["name"].innerText || "Введите имя"} desc={FC["name"].text || "имя"} Icon={NameIcon} /> ); //@ts-ignore const Email = ( setEmail(target.value)} id={email} title={FC["email"].innerText || "Введите Email"} desc={FC["email"].text || "Email"} Icon={EmailIcon} /> ); const Phone = ( setPhone(target.value)} id={phone} title={FC["phone"].innerText || "Введите номер телефона"} desc={FC["phone"].text || "номер телефона"} Icon={PhoneIcon} /> ); //@ts-ignore const Text = ( setText(target.value)} id={text} title={FC["text"].text || "Введите фамилию"} desc={FC["text"].innerText || "фамилию"} Icon={TextIcon} /> ); //@ts-ignore const Adress = ( setAdress(target.value)} id={adress} title={FC["address"].innerText || "Введите адрес"} desc={FC["address"].text || "адрес"} Icon={AddressIcon} /> ); //@ts-ignore if (Object.values(FC).some((data) => data.used)) { return ( <> {FC["name"].used ? Name : <>} {FC["email"].used ? Email : <>} {FC["phone"].used ? Phone : <>} {FC["text"].used ? Text : <>} {FC["address"].used ? Adress : <>} ); } else { return ( <> {Name} {Email} {Phone} ); } }; const CustomInput = ({ title, desc, Icon, onChange }: any) => { const theme = useTheme(); const isMobile = useRootContainerSize() < 600; //@ts-ignore return ( {title} ), }} /> ); };