поле email при несуществовании не влияет на ФК

This commit is contained in:
Nastya 2025-08-11 17:29:00 +03:00
parent b1c3ab7314
commit f330c5c05a

@ -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) => {
</Box>
<Button
disabled={!(ready && !fire && isPhoneValid && isEmailValid)}
disabled={!(ready && !fire && isPhoneValid && (isEmailFieldVisible ? isEmailValid : true))}
variant="contained"
onClick={handleShowResultsClick}
sx={{