Skip to content

Commit

Permalink
Merge pull request #27818 from hoangzinh/df/27283
Browse files Browse the repository at this point in the history
Fix - User is hard to close a Phone account if it contains spaces
  • Loading branch information
Gonals authored Oct 3, 2023
2 parents 36a13fa + 43f188a commit 0b8efb9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pages/settings/Security/CloseAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ function CloseAccountPage(props) {
setReasonForLeaving(values.reasonForLeaving);
};

/**
* Removes spaces and transform the input string to lowercase.
* @param {String} phoneOrEmail - The input string to be sanitized.
* @returns {String} The sanitized string
*/
const sanitizePhoneOrEmail = (phoneOrEmail) => phoneOrEmail.replace(/\s+/g, '').toLowerCase();

const validate = (values) => {
const requiredFields = ['phoneOrEmail'];
const userEmailOrPhone = props.formatPhoneNumber(props.session.email);
const errors = ValidationUtils.getFieldRequiredErrors(values, requiredFields);

if (values.phoneOrEmail && userEmailOrPhone.toLowerCase() !== values.phoneOrEmail.toLowerCase()) {
if (values.phoneOrEmail && sanitizePhoneOrEmail(userEmailOrPhone) !== sanitizePhoneOrEmail(values.phoneOrEmail)) {
errors.phoneOrEmail = 'closeAccountPage.enterYourDefaultContactMethod';
}
return errors;
Expand Down

0 comments on commit 0b8efb9

Please sign in to comment.