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) => {