diff --git a/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx b/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx index 2e0c454..15a0926 100644 --- a/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx +++ b/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx @@ -13,346 +13,358 @@ import {quizThemes} from "@utils/themes/Publication/themePublication.ts"; import {enqueueSnackbar} from "notistack"; import {useRootContainerSize} from "@contexts/RootContainerWidthContext.ts"; import { - FormContactFieldData, - FormContactFieldName, + FormContactFieldData, + FormContactFieldName, } from "@model/settingsData.ts"; import { - Inputs + Inputs } from "@/components/ViewPublicationPage/ContactForm/Inputs/Inputs.tsx"; import {EMAIL_REGEXP} from "@utils/emailRegexp.tsx"; import { - ContactTextBlock + ContactTextBlock } from "@/components/ViewPublicationPage/ContactForm/ContactTextBlock/ContactTextBlock.tsx"; type Props = { - currentQuestion: AnyTypedQuizQuestion; - onShowResult: () => void; + currentQuestion: AnyTypedQuizQuestion; + onShowResult: () => void; }; -export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { - const theme = useTheme(); - const { settings, questions, quizId, show_badge, preview } = useQuizData(); +export const ContactForm = ({currentQuestion, onShowResult}: Props) => { + 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(window.innerHeight); + 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(window.innerHeight); - const fireOnce = useRef(true); - const [fire, setFire] = useState(false); - const isMobile = useRootContainerSize() < 850; - const isTablet = useRootContainerSize() < 1000; + const fireOnce = useRef(true); + const [fire, setFire] = useState(false); + const isMobile = useRootContainerSize() < 850; + const isTablet = useRootContainerSize() < 1000; - useEffect(() => { - function handleResize() { - setScreenHeight(window.innerHeight); - } - - window.addEventListener("resize", handleResize); - - return () => { - window.removeEventListener("resize", handleResize); - }; - }, []); - - const resultQuestion = - currentQuestion.type === "result" - ? currentQuestion - : questions.find((question): question is QuizQuestionResult => { - 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" - ); + useEffect(() => { + function handleResize() { + setScreenHeight(window.innerHeight); } - }); - if (!resultQuestion) throw new Error("Result question not found"); + window.addEventListener("resize", handleResize); - const inputHC = async () => { - const FC = settings.cfg.formContact.fields || settings.cfg.formContact; - const body: SendFCParams["body"] = {}; - 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 }; + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); - if (Object.keys(body).length > 0) { - try { - await sendFC({ - questionId: currentQuestion.id, - body: body, - qid: quizId, - preview, - }); + const resultQuestion = + currentQuestion.type === "result" + ? currentQuestion + : questions.find((question): question is QuizQuestionResult => { + 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" + ); + } + }); - const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); - localStorage.setItem( - "sessions", - JSON.stringify({ ...sessions, [quizId]: new Date().getTime() }) - ); - } catch (e) { - enqueueSnackbar("ответ не был засчитан"); - } - } - }; + if (!resultQuestion) throw new Error("Result question not found"); - const FCcopy: Record = - settings.cfg.formContact.fields || settings.cfg.formContact; + const inputHC = async () => { + const FC = settings.cfg.formContact.fields || settings.cfg.formContact; + const body: SendFCParams["body"] = {}; + 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}; - const filteredFC: Partial< - Record - > = {}; - for (const i in FCcopy) { - const field = FCcopy[i as keyof typeof FCcopy]; - if (field.used) { - filteredFC[i as FormContactFieldName] = field; - } - } + if (Object.keys(body).length > 0) { + try { + await sendFC({ + questionId: currentQuestion.id, + body: body, + qid: quizId, + preview, + }); - async function handleShowResultsClick() { - const FC = settings.cfg.formContact.fields; - if (FC["email"].used !== EMAIL_REGEXP.test(email)) { - return enqueueSnackbar("введена некорректная почта"); + const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); + localStorage.setItem( + "sessions", + JSON.stringify({ + ...sessions, + [quizId]: new Date().getTime() + }) + ); + } catch (e) { + enqueueSnackbar("ответ не был засчитан"); + } + } + }; + + const FCcopy: Record = + settings.cfg.formContact.fields || settings.cfg.formContact; + + const filteredFC: Partial< + Record + > = {}; + for (const i in FCcopy) { + const field = FCcopy[i as keyof typeof FCcopy]; + if (field.used) { + filteredFC[i as FormContactFieldName] = field; + } } - if (fireOnce.current) { - if ( - name.length === 0 && - email.length === 0 && - phone.length === 0 && - text.length === 0 && - adress.length === 0 - ) - return enqueueSnackbar("Пожалуйста, заполните поля"); + async function handleShowResultsClick() { + const FC = settings.cfg.formContact.fields; + if (FC["email"].used !== EMAIL_REGEXP.test(email)) { + return enqueueSnackbar("введена некорректная почта"); + } - //почта валидна, хоть одно поле заполнено - setFire(true); - try { - await inputHC(); - fireOnce.current = false; - const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); - sessions[quizId] = Date.now(); - localStorage.setItem("sessions", JSON.stringify(sessions)); + 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; + const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); + sessions[quizId] = Date.now(); + localStorage.setItem("sessions", JSON.stringify(sessions)); + + //@ts-ignore + const YM = window?.ym; + //@ts-ignore + const VP = window?._tmr; + if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) { + YM( + settings.cfg.yandexMetricNumber, + "reachGoal", + "penaquiz-contacts" + ); + } + if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) { + VP.push({ + type: "reachGoal", + id: settings.cfg.vkMetricNumber, + goal: "penaquiz-contacts" + }); + } + } catch (e) { + enqueueSnackbar("повторите попытку позже"); + } + if (settings.cfg.resultInfo.showResultForm === "after") { + onShowResult(); + } + } + + setFire(false); + } + + useEffect(() => { //@ts-ignore const YM = window?.ym; //@ts-ignore const VP = window?._tmr; if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) { - YM( - settings.cfg.yandexMetricNumber, - "reachGoal", - "penaquiz-contacts" - ); + YM( + settings.cfg.yandexMetricNumber, + "reachGoal", + "penaquiz-form" + ); } if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) { - VP.push({ - type: "reachGoal", - id: settings.cfg.vkMetricNumber, - goal: "penaquiz-contacts" - }); + VP.push({ + type: "reachGoal", + id: settings.cfg.vkMetricNumber, + goal: "penaquiz-form" + }); } - } catch (e) { - enqueueSnackbar("повторите попытку позже"); - } - if (settings.cfg.resultInfo.showResultForm === "after") { - onShowResult(); - } - } + }, []) - setFire(false); - } - useEffect(() => { - //@ts-ignore - const YM = window?.ym; - //@ts-ignore - const VP = window?._tmr; - if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) { - YM( - settings.cfg.yandexMetricNumber, - "reachGoal", - "penaquiz-form" - ); - } - if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) { - VP.push({ - type: "reachGoal", - id: settings.cfg.vkMetricNumber, - goal: "penaquiz-form" - }); - } - }, []) - - return ( - 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]})` - : `linear-gradient(90deg, rgba(39, 38, 38, 0.95) 7.66%, rgba(42, 42, 46, 0.85) 42.12%, rgba(51, 54, 71, 0.4) 100%), url(${DESIGN_LIST[settings.cfg.theme] - })` - : null, - }} - > - - - - - - - - - { - setReady(target.checked); - }} - checked={ready} - colorIcon={theme.palette.primary.main} - sx={{ marginRight: "0" }} - /> - - С  - - Положением об обработке персональных данных{" "} - -  и  - - {" "} - Политикой конфиденциальности{" "} - -  ознакомлен - - - - - - {show_badge && ( - + - - - )} + justifyContent: "space-between", + flexDirection: "column", + backgroundColor: theme.palette.background.default, + height: "auto", + }}> + + + + + + { + setReady(target.checked); + }} + checked={ready} + colorIcon={theme.palette.primary.main} + sx={{marginRight: "0"}} + /> + + С  + + Положением об обработке персональных + данных{" "} + +  и  + + {" "} + Политикой конфиденциальности{" "} + +  ознакомлен + + + + + + {show_badge && ( + + + + )} + + - - - ); + ); }; diff --git a/lib/components/ViewPublicationPage/ContactForm/ContactTextBlock/ContactTextBlock.tsx b/lib/components/ViewPublicationPage/ContactForm/ContactTextBlock/ContactTextBlock.tsx index b8263e6..e76fda9 100644 --- a/lib/components/ViewPublicationPage/ContactForm/ContactTextBlock/ContactTextBlock.tsx +++ b/lib/components/ViewPublicationPage/ContactForm/ContactTextBlock/ContactTextBlock.tsx @@ -14,7 +14,7 @@ export const ContactTextBlock: FC = ({settings}) => { return ( = ({settings}) => { > >; } -export const CountrySelector:FC = ({setMask}) => { +export const CountrySelector: FC = ({setMask}) => { const theme = useTheme(); const [country, setCountry] = useState('RU'); @@ -24,6 +24,8 @@ export const CountrySelector:FC = ({setMask}) => { PaperProps: { style: { backgroundColor: theme.palette.background.default, + borderRadius: '12px', + scrollbarWidth: "none", }, }, }} @@ -55,7 +57,8 @@ export const CountrySelector:FC = ({setMask}) => { }} > {Object.keys(phoneMasksByCountry).map((countryCode) => { - return {phoneMasksByCountry[countryCode][0]} + return {phoneMasksByCountry[countryCode][0]} })} );