2023-12-31 02:53:25 +00:00
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Typography,
|
|
|
|
|
Button,
|
|
|
|
|
Paper,
|
|
|
|
|
TextField,
|
|
|
|
|
Link,
|
|
|
|
|
InputAdornment,
|
|
|
|
|
useTheme,
|
2024-01-04 21:56:21 +00:00
|
|
|
|
useMediaQuery,
|
2023-12-31 02:53:25 +00:00
|
|
|
|
} from "@mui/material";
|
2023-12-16 12:33:06 +00:00
|
|
|
|
import NameIcon from "@icons/ContactFormIcon/NameIcon";
|
|
|
|
|
import EmailIcon from "@icons/ContactFormIcon/EmailIcon";
|
|
|
|
|
import PhoneIcon from "@icons/ContactFormIcon/PhoneIcon";
|
|
|
|
|
import TextIcon from "@icons/ContactFormIcon/TextIcon";
|
|
|
|
|
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
|
2023-12-15 12:12:36 +00:00
|
|
|
|
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2023-12-21 11:47:34 +00:00
|
|
|
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
2023-12-16 12:33:06 +00:00
|
|
|
|
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
|
|
|
|
import { useState } from "react";
|
2023-12-16 09:36:35 +00:00
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
|
|
|
|
|
2023-12-23 17:24:32 +00:00
|
|
|
|
import { checkEmptyData } from "../ResultPage/cards/ResultCard";
|
2023-12-16 09:36:35 +00:00
|
|
|
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
2023-12-31 02:53:25 +00:00
|
|
|
|
import { modes } from "../../utils/themes/Publication/themePublication";
|
2023-12-23 15:29:33 +00:00
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-12-15 12:12:36 +00:00
|
|
|
|
|
|
|
|
|
type ContactFormProps = {
|
2023-12-16 09:36:35 +00:00
|
|
|
|
currentQuestion: AnyTypedQuizQuestion;
|
2023-12-15 12:12:36 +00:00
|
|
|
|
showResultForm: boolean;
|
|
|
|
|
setShowContactForm: (show: boolean) => void;
|
|
|
|
|
setShowResultForm: (show: boolean) => void;
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-16 12:33:06 +00:00
|
|
|
|
const icons = [
|
2023-12-31 02:53:25 +00:00
|
|
|
|
{
|
|
|
|
|
type: "name",
|
|
|
|
|
icon: NameIcon,
|
|
|
|
|
defaultText: "Введите имя",
|
|
|
|
|
defaultTitle: "имя",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "email",
|
|
|
|
|
icon: EmailIcon,
|
|
|
|
|
defaultText: "Введите Email",
|
|
|
|
|
defaultTitle: "Email",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "phone",
|
|
|
|
|
icon: PhoneIcon,
|
|
|
|
|
defaultText: "Введите номер телефона",
|
|
|
|
|
defaultTitle: "номер телефона",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "text",
|
|
|
|
|
icon: TextIcon,
|
|
|
|
|
defaultText: "Введите фамилию",
|
|
|
|
|
defaultTitle: "фамилию",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "address",
|
|
|
|
|
icon: AddressIcon,
|
|
|
|
|
defaultText: "Введите адрес",
|
|
|
|
|
defaultTitle: "адрес",
|
|
|
|
|
},
|
|
|
|
|
];
|
2023-12-16 12:33:06 +00:00
|
|
|
|
|
2023-12-15 12:12:36 +00:00
|
|
|
|
export const ContactForm = ({
|
2023-12-16 09:36:35 +00:00
|
|
|
|
currentQuestion,
|
2023-12-15 12:12:36 +00:00
|
|
|
|
showResultForm,
|
|
|
|
|
setShowContactForm,
|
|
|
|
|
setShowResultForm,
|
|
|
|
|
}: ContactFormProps) => {
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const mode = modes;
|
2023-12-16 09:36:35 +00:00
|
|
|
|
const { questions } = useQuestionsStore();
|
2023-12-25 23:46:28 +00:00
|
|
|
|
const theme = useTheme();
|
2024-01-04 21:56:21 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const [ready, setReady] = useState(false);
|
2023-12-15 12:12:36 +00:00
|
|
|
|
const followNextForm = () => {
|
|
|
|
|
setShowContactForm(false);
|
|
|
|
|
setShowResultForm(true);
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-23 17:24:32 +00:00
|
|
|
|
const resultQuestion = questions.find((question) => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
if (quiz?.config.haveRoot) {
|
|
|
|
|
//ветвимся
|
2023-12-23 17:24:32 +00:00
|
|
|
|
return (
|
|
|
|
|
question.type === "result" &&
|
|
|
|
|
question.content.rule.parentId === currentQuestion.content.id
|
2023-12-31 02:53:25 +00:00
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// не ветвимся
|
2023-12-23 17:24:32 +00:00
|
|
|
|
return (
|
2023-12-31 02:53:25 +00:00
|
|
|
|
question.type === "result" && question.content.rule.parentId === "line"
|
|
|
|
|
);
|
2023-12-23 17:24:32 +00:00
|
|
|
|
}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
});
|
2023-12-23 17:24:32 +00:00
|
|
|
|
|
2023-12-15 12:12:36 +00:00
|
|
|
|
return (
|
2023-12-16 12:33:06 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
2023-12-25 23:46:28 +00:00
|
|
|
|
backgroundColor: theme.palette.background.default,
|
2023-12-31 02:53:25 +00:00
|
|
|
|
height: "100vh",
|
2023-12-16 12:33:06 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2024-01-04 21:56:21 +00:00
|
|
|
|
width: isMobile ? "330px" : "530px",
|
2023-12-29 23:11:37 +00:00
|
|
|
|
borderRadius: "4px",
|
2024-01-04 21:56:21 +00:00
|
|
|
|
overflow: "auto",
|
|
|
|
|
height: "90vh",
|
2023-12-16 12:33:06 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
textAlign: "center",
|
|
|
|
|
m: "20px 0",
|
2023-12-25 23:46:28 +00:00
|
|
|
|
fontSize: "28px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
color: theme.palette.text.primary,
|
2023-12-16 12:33:06 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
{quiz?.config.formContact.title ||
|
|
|
|
|
"Заполните форму, чтобы получить результаты теста"}
|
2023-12-16 12:33:06 +00:00
|
|
|
|
</Typography>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
{quiz?.config.formContact.desc && (
|
2023-12-21 11:47:34 +00:00
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
2024-01-05 14:43:28 +00:00
|
|
|
|
color: theme.palette.text.primary,
|
2023-12-21 11:47:34 +00:00
|
|
|
|
textAlign: "center",
|
|
|
|
|
m: "20px 0",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
fontSize: "18px",
|
2023-12-21 11:47:34 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{quiz?.config.formContact.desc}
|
|
|
|
|
</Typography>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
)}
|
2023-12-16 12:33:06 +00:00
|
|
|
|
</Box>
|
|
|
|
|
|
2023-12-29 23:11:37 +00:00
|
|
|
|
<Box
|
2023-12-16 12:33:06 +00:00
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
flexDirection: "column",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
p: "30px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-16 12:33:06 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
my: "20px",
|
2023-12-16 12:33:06 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-16 20:52:01 +00:00
|
|
|
|
<Inputs />
|
2023-12-16 12:33:06 +00:00
|
|
|
|
</Box>
|
|
|
|
|
|
2023-12-16 15:59:36 +00:00
|
|
|
|
{
|
|
|
|
|
// resultQuestion &&
|
2023-12-31 02:53:25 +00:00
|
|
|
|
// quiz?.config.resultInfo.when === "after" &&
|
|
|
|
|
<Button
|
|
|
|
|
disabled={!ready}
|
|
|
|
|
variant="contained"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (
|
|
|
|
|
(quiz?.config.resultInfo.when === "after" ||
|
|
|
|
|
quiz?.config.resultInfo.when === "email") &&
|
|
|
|
|
!checkEmptyData({ resultData: resultQuestion })
|
|
|
|
|
) {
|
|
|
|
|
setShowContactForm(false);
|
|
|
|
|
setShowResultForm(true);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{quiz?.config.formContact?.button || "Получить результаты"}
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
2023-12-16 12:33:06 +00:00
|
|
|
|
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
mt: "20px",
|
2024-01-04 21:56:21 +00:00
|
|
|
|
width: isMobile ? "300px" : "450px",
|
2023-12-16 12:33:06 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<CustomCheckbox
|
|
|
|
|
label=""
|
|
|
|
|
handleChange={({ target }) => {
|
|
|
|
|
setReady(target.checked);
|
|
|
|
|
}}
|
|
|
|
|
checked={ready}
|
|
|
|
|
colorIcon={theme.palette.primary.main}
|
|
|
|
|
/>
|
2024-01-05 14:43:28 +00:00
|
|
|
|
<Typography sx={{ color: theme.palette.text.primary }}>
|
2023-12-25 23:46:28 +00:00
|
|
|
|
С 
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<Link> Положением об обработке персональных данных </Link>
|
|
|
|
|
 и 
|
|
|
|
|
<Link> Политикой конфиденциальности </Link>
|
|
|
|
|
 ознакомлен
|
2023-12-16 12:33:06 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
2023-12-21 11:47:34 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
2023-12-25 23:46:28 +00:00
|
|
|
|
mt: "20px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
gap: "15px",
|
2023-12-21 11:47:34 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<NameplateLogo
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: "34px",
|
|
|
|
|
color: mode[quiz.config.theme] ? "#151515" : "#FFFFFF",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "20px",
|
|
|
|
|
color: mode[quiz.config.theme] ? "#4D4D4D" : "#F5F7FF",
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Сделано на PenaQuiz
|
2023-12-25 23:46:28 +00:00
|
|
|
|
</Typography>
|
2023-12-21 11:47:34 +00:00
|
|
|
|
</Box>
|
2023-12-29 23:11:37 +00:00
|
|
|
|
</Box>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-12-15 12:12:36 +00:00
|
|
|
|
);
|
|
|
|
|
};
|
2023-12-16 12:33:06 +00:00
|
|
|
|
|
2023-12-23 15:29:33 +00:00
|
|
|
|
const Inputs = (currentQuestion: any) => {
|
2023-12-16 20:52:01 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const { questions } = useQuestionsStore();
|
2023-12-16 20:52:01 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const [name, setName] = useState("");
|
|
|
|
|
const [email, setEmail] = useState("");
|
|
|
|
|
const [phone, setPhone] = useState("");
|
|
|
|
|
const [text, setText] = useState("");
|
|
|
|
|
const [adress, setAdress] = useState("");
|
2023-12-21 11:47:34 +00:00
|
|
|
|
|
2023-12-23 15:29:33 +00:00
|
|
|
|
//@ts-ignore
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const FC: any = quiz?.config.formContact.fields;
|
2023-12-23 15:29:33 +00:00
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const Name = (
|
|
|
|
|
<CustomInput
|
|
|
|
|
onChange={({ target }) => setName(target.value)}
|
|
|
|
|
id={name}
|
|
|
|
|
title={FC["name"].innerText || "Введите имя"}
|
|
|
|
|
desc={FC["name"].text || "имя"}
|
|
|
|
|
Icon={NameIcon}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2023-12-23 15:29:33 +00:00
|
|
|
|
//@ts-ignore
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const Email = (
|
|
|
|
|
<CustomInput
|
|
|
|
|
onChange={({ target }) => setEmail(target.value)}
|
|
|
|
|
id={email}
|
|
|
|
|
title={FC["email"].innerText || "Введите Email"}
|
|
|
|
|
desc={FC["email"].text || "Email"}
|
|
|
|
|
Icon={EmailIcon}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2023-12-23 15:29:33 +00:00
|
|
|
|
//@ts-ignore
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const Phone = (
|
|
|
|
|
<CustomInput
|
|
|
|
|
onChange={({ target }) => setPhone(target.value)}
|
|
|
|
|
id={phone}
|
|
|
|
|
title={FC["phone"].innerText || "Введите номер телефона"}
|
|
|
|
|
desc={FC["phone"].text || "номер телефона"}
|
|
|
|
|
Icon={PhoneIcon}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2023-12-23 15:29:33 +00:00
|
|
|
|
//@ts-ignore
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const Text = (
|
|
|
|
|
<CustomInput
|
|
|
|
|
onChange={({ target }) => setText(target.value)}
|
|
|
|
|
id={text}
|
|
|
|
|
title={FC["text"].innerText || "Введите фамилию"}
|
|
|
|
|
desc={FC["text"].text || "фамилию"}
|
|
|
|
|
Icon={TextIcon}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2023-12-23 15:29:33 +00:00
|
|
|
|
//@ts-ignore
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const Adress = (
|
|
|
|
|
<CustomInput
|
|
|
|
|
onChange={({ target }) => setAdress(target.value)}
|
|
|
|
|
id={adress}
|
|
|
|
|
title={FC["address"].innerText || "Введите адрес"}
|
|
|
|
|
desc={FC["address"].text || "адрес"}
|
|
|
|
|
Icon={AddressIcon}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2023-12-23 15:29:33 +00:00
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
2023-12-29 23:11:37 +00:00
|
|
|
|
if (Object.values(FC).some((data) => data.used)) {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{FC["name"].used ? Name : <></>}
|
|
|
|
|
{FC["email"].used ? Email : <></>}
|
|
|
|
|
{FC["phone"].used ? Phone : <></>}
|
|
|
|
|
{FC["text"].used ? Text : <></>}
|
|
|
|
|
{FC["address"].used ? Adress : <></>}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-12-16 20:52:01 +00:00
|
|
|
|
} else {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{Name}
|
|
|
|
|
{Email}
|
|
|
|
|
{Phone}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-12-16 20:52:01 +00:00
|
|
|
|
}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
};
|
2023-12-23 15:29:33 +00:00
|
|
|
|
|
2023-12-16 12:33:06 +00:00
|
|
|
|
const CustomInput = ({ title, desc, Icon }: any) => {
|
2024-01-04 21:56:21 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box m="15px 0">
|
2024-01-05 14:43:28 +00:00
|
|
|
|
<Typography mb="7px" color={theme.palette.text.primary}>
|
|
|
|
|
{title}
|
|
|
|
|
</Typography>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<TextField
|
|
|
|
|
sx={{
|
2024-01-04 21:56:21 +00:00
|
|
|
|
width: isMobile ? "300px" : "350px",
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}}
|
|
|
|
|
placeholder={desc}
|
|
|
|
|
InputProps={{
|
|
|
|
|
startAdornment: (
|
|
|
|
|
<InputAdornment position="start">
|
|
|
|
|
<Icon color="gray" />
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|