diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e8a349daa112..96661f481e7a 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -25,6 +25,19 @@ let preferredLocale; // will update when the OptionsListUtils re-loads. But will stay the same color for the life of the JS session. const defaultAvatarForUserToInvite = getDefaultAvatar(); +/** + * Adds expensify SMS domain (@expensify.sms) if login is a phone number and if it's not included yet + * + * @param {String} login + * @return {String} + */ +function addSMSDomainIfPhoneNumber(login) { + if (Str.isValidPhone(login) && !Str.isValidEmail(login)) { + return login + CONST.SMS.DOMAIN; + } + return login; +} + /** * Returns the personal details for an array of logins * @@ -38,7 +51,7 @@ function getPersonalDetailsForLogins(logins, personalDetails) { if (!personalDetail) { personalDetail = { - login, + login: addSMSDomainIfPhoneNumber(login), displayName: login, avatar: getDefaultAvatar(login), }; @@ -339,7 +352,7 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { && (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) ) { // If the phone number doesn't have an international code then let's prefix it with the - // current users international code based on their IP address. + // current user's international code based on their IP address. const login = (Str.isValidPhone(searchValue) && !searchValue.includes('+')) ? `+${countryCodeByIP}${searchValue}` : searchValue; diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 9ce34322cdfb..2a54da5e2015 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -350,7 +350,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(0); expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+15005550006'); + expect(results.userToInvite.login).toBe(`+15005550006${CONST.SMS.DOMAIN}`); // When we add a search term for which no options exist and the searchValue itself // is a potential phone number with country code added @@ -361,7 +361,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(0); expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+15005550006'); + expect(results.userToInvite.login).toBe(`+15005550006${CONST.SMS.DOMAIN}`); // Test Concierge's existence in new group options results = OptionsListUtils.getNewGroupOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE);