Skip to content

Commit

Permalink
fix: Contact email and phone validation not working properly (#33653)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris authored Oct 18, 2024
1 parent 3505c76 commit bb2a324
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,24 @@ const EditContactInfo = ({ contactData, onClose, onCancel }: ContactNewEditProps
return t('error-invalid-email-address');
}

const { contact } = await getContact({ email: emailValue });
return (!contact || contact._id === contactData?._id) && !isDuplicated ? true : t('Email_already_exists');
try {
const { contact } = await getContact({ email: emailValue });
return (!contact || contact._id === contactData?._id) && !isDuplicated ? true : t('Email_already_exists');
} catch (error) {
return !isDuplicated ? true : t('Email_already_exists');
}
};

const validatePhone = async (phoneValue: string) => {
const currentPhones = phones.map(({ phoneNumber }) => phoneNumber);
const isDuplicated = currentPhones.filter((phone) => phone === phoneValue).length > 1;

const { contact } = await getContact({ phone: phoneValue });
return (!contact || contact._id === contactData?._id) && !isDuplicated ? true : t('Phone_already_exists');
try {
const { contact } = await getContact({ phone: phoneValue });
return (!contact || contact._id === contactData?._id) && !isDuplicated ? true : t('Phone_already_exists');
} catch (error) {
return !isDuplicated ? true : t('Phone_already_exists');
}
};

const validateName = (v: string): string | boolean => (!v.trim() ? t('Required_field', { field: t('Name') }) : true);
Expand Down

0 comments on commit bb2a324

Please sign in to comment.