From 9689a3fcf26a065345ddf65277927e699180a15d Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Tue, 18 Nov 2025 01:32:47 +0530 Subject: [PATCH 1/2] Normalize SMS invite logins when building contact options --- src/libs/OptionsListUtils/index.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index c8a52ddce5d4..dc9c1cc6f159 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -1589,25 +1589,29 @@ function getUserToInviteContactOption({ // Handle phone number parsing for either provided phone or searchValue // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const phoneToCheck = phone || searchValue; - const parsedPhoneNumber = parsePhoneNumber(appendCountryCode(Str.removeSMSDomain(phoneToCheck), countryCode)); - - const isCurrentUserLogin = isCurrentUser({login: effectiveSearchValue} as PersonalDetails); - const isInSelectedOption = selectedOptions.some((option) => 'login' in option && option.login === effectiveSearchValue); + const normalizedPhoneNumber = appendCountryCode(Str.removeSMSDomain(phoneToCheck), countryCode); + const parsedPhoneNumber = parsePhoneNumber(normalizedPhoneNumber); // Validate email (either provided email or searchValue) const isValidEmail = Str.isValidEmail(effectiveSearchValue) && !Str.isDomainEmail(effectiveSearchValue) && !Str.endsWith(effectiveSearchValue, CONST.SMS.DOMAIN); const isValidPhoneNumber = parsedPhoneNumber.possible && Str.isValidE164Phone(getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? '')); - const isInOptionToExclude = - optionsToExclude.findIndex((optionToExclude) => 'login' in optionToExclude && optionToExclude.login === addSMSDomainIfPhoneNumber(effectiveSearchValue).toLowerCase()) !== -1; + const sanitizedPhoneLogin = isValidPhoneNumber ? addSMSDomainIfPhoneNumber(parsedPhoneNumber.number?.e164 ?? normalizedPhoneNumber) : ''; + const login = email ? effectiveSearchValue : sanitizedPhoneLogin ?? searchValue; + const normalizedLoginToExclude = addSMSDomainIfPhoneNumber(login).toLowerCase(); + + const isCurrentUserLogin = isCurrentUser({login} as PersonalDetails); + const isInSelectedOption = selectedOptions.some((option) => 'login' in option && option.login === login); + + const isInOptionToExclude = optionsToExclude.findIndex((optionToExclude) => 'login' in optionToExclude && optionToExclude.login === normalizedLoginToExclude) !== -1; if (!effectiveSearchValue || isCurrentUserLogin || isInSelectedOption || (!isValidEmail && !isValidPhoneNumber) || isInOptionToExclude) { return null; } // Generates an optimistic account ID for new users not yet saved in Onyx - const optimisticAccountID = generateAccountID(effectiveSearchValue); + const optimisticAccountID = generateAccountID(login); // Construct display name if firstName/lastName are provided // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -1621,7 +1625,7 @@ function getUserToInviteContactOption({ firstName: firstName ?? '', lastName: lastName ?? '', displayName, - login: effectiveSearchValue, + login, pronouns: '', phoneNumber: phone ?? '', validated: true, @@ -1633,20 +1637,20 @@ function getUserToInviteContactOption({ displayName, firstName, lastName, - alternateText: displayName !== effectiveSearchValue ? effectiveSearchValue : undefined, + alternateText: displayName !== login ? login : undefined, brickRoadIndicator: null, icons: [ { source: userDetails.avatar, type: CONST.ICON_TYPE_AVATAR, - name: effectiveSearchValue, + name: login, id: optimisticAccountID, }, ], tooltipText: null, participantsList: [userDetails], accountID: optimisticAccountID, - login: effectiveSearchValue, + login, reportID: '', phoneNumber: phone ?? '', hasDraftComment: false, From 085f631263e8367ba7d712fe67278cf1828c877b Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Mon, 24 Nov 2025 20:52:23 +0530 Subject: [PATCH 2/2] Prettier fix --- src/libs/OptionsListUtils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 75921112865b..95ed3823a033 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -1599,7 +1599,7 @@ function getUserToInviteContactOption({ const isValidPhoneNumber = parsedPhoneNumber.possible && Str.isValidE164Phone(getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? '')); const sanitizedPhoneLogin = isValidPhoneNumber ? addSMSDomainIfPhoneNumber(parsedPhoneNumber.number?.e164 ?? normalizedPhoneNumber) : ''; - const login = email ? effectiveSearchValue : sanitizedPhoneLogin ?? searchValue; + const login = email ? effectiveSearchValue : (sanitizedPhoneLogin ?? searchValue); const normalizedLoginToExclude = addSMSDomainIfPhoneNumber(login).toLowerCase(); const isCurrentUserLogin = isCurrentUser({login} as PersonalDetails);