From 87eed74d81a5082afb0dbb18e95bedc40da75e39 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 20 Sep 2023 06:41:43 +0700 Subject: [PATCH 1/2] Remove spaces before compare email or phone in Close account form --- src/pages/settings/Security/CloseAccountPage.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/settings/Security/CloseAccountPage.js b/src/pages/settings/Security/CloseAccountPage.js index b2370156228a..bc66ae03c947 100644 --- a/src/pages/settings/Security/CloseAccountPage.js +++ b/src/pages/settings/Security/CloseAccountPage.js @@ -62,12 +62,21 @@ 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 The sanitized string + */ + const sanitizePhoneOrEmail = (phoneOrEmail) => { + return 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; From 43f188aa058bbe09ccdeb948d1dea42fb3c45a85 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 20 Sep 2023 10:13:45 +0700 Subject: [PATCH 2/2] Fix linter --- src/pages/settings/Security/CloseAccountPage.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/Security/CloseAccountPage.js b/src/pages/settings/Security/CloseAccountPage.js index bc66ae03c947..63ff9062bb8f 100644 --- a/src/pages/settings/Security/CloseAccountPage.js +++ b/src/pages/settings/Security/CloseAccountPage.js @@ -65,11 +65,9 @@ function CloseAccountPage(props) { /** * Removes spaces and transform the input string to lowercase. * @param {String} phoneOrEmail - The input string to be sanitized. - * @returns The sanitized string + * @returns {String} The sanitized string */ - const sanitizePhoneOrEmail = (phoneOrEmail) => { - return phoneOrEmail.replace(/\s+/g, '').toLowerCase(); - } + const sanitizePhoneOrEmail = (phoneOrEmail) => phoneOrEmail.replace(/\s+/g, '').toLowerCase(); const validate = (values) => { const requiredFields = ['phoneOrEmail'];