From f330c5c05a99a1d5aa6141c4611d824722b151cc Mon Sep 17 00:00:00 2001 From: Nastya Date: Mon, 11 Aug 2025 17:29:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=20email=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B5=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=BB=D0=B8=D1=8F=D0=B5=D1=82=20=D0=BD=D0=B0=20=D0=A4=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContactForm/ContactForm.tsx | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx b/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx index a8310d4..4135659 100644 --- a/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx +++ b/lib/components/ViewPublicationPage/ContactForm/ContactForm.tsx @@ -122,13 +122,23 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { async function handleShowResultsClick() { const FC = settings.cfg.formContact.fields; - if (!isDisableEmail && FC["email"].used !== EMAIL_REGEXP.test(email)) { + // Проверяем email только если поле отображается + if (isEmailFieldVisible && !EMAIL_REGEXP.test(email)) { return enqueueSnackbar("Incorrect email entered"); } if (fireOnce.current) { - if (name.length === 0 && email.length === 0 && phone.length === 0 && text.length === 0 && adress.length === 0) + // Проверяем, что хотя бы одно видимое поле заполнено + const hasVisibleFieldsFilled = + (isNameFieldVisible() && name.length > 0) || + (isEmailFieldVisible && email.length > 0) || + (isPhoneFieldVisible() && phone.length > 0) || + (isTextFieldVisible() && text.length > 0) || + (isAddressFieldVisible() && adress.length > 0); + + if (!hasVisibleFieldsFilled) { return enqueueSnackbar(t("Please fill in the fields")); + } //почта валидна, хоть одно поле заполнено setFire(true); @@ -228,6 +238,30 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { const isEmailValid = validateEmail(email); + // Определяем, отображается ли поле email + const isEmailFieldVisible = settings.cfg.formContact.fields?.email?.used && !isDisableEmail; + + // Функции для определения видимости полей + const isNameFieldVisible = () => { + const FC = settings.cfg.formContact.fields; + return Object.values(FC).some((data) => data.used) ? FC["name"].used : true; + }; + + const isPhoneFieldVisible = () => { + const FC = settings.cfg.formContact.fields; + return Object.values(FC).some((data) => data.used) ? FC["phone"].used : true; + }; + + const isTextFieldVisible = () => { + const FC = settings.cfg.formContact.fields; + return Object.values(FC).some((data) => data.used) ? FC["text"].used : false; + }; + + const isAddressFieldVisible = () => { + const FC = settings.cfg.formContact.fields; + return Object.values(FC).some((data) => data.used) ? FC["address"].used : false; + }; + // Обработчик изменения телефона const handlePhoneChange = (newPhone: string) => { setPhone(newPhone); @@ -395,7 +429,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {