diff --git a/src/components/AccountSwitcher.tsx b/src/components/AccountSwitcher.tsx index b89f5784760c..82bd8e38afc6 100644 --- a/src/components/AccountSwitcher.tsx +++ b/src/components/AccountSwitcher.tsx @@ -10,7 +10,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {accountIDSelector} from '@selectors/Session'; -import {Str} from 'expensify-common'; import React from 'react'; import {View} from 'react-native'; @@ -87,7 +86,7 @@ function AccountSwitcher({isScreenFocused, shouldShowSwitchButton = true}: Accou numberOfLines={1} style={[styles.colorMuted, styles.fontSizeLabel, shouldStackHeader && styles.textAlignCenter]} > - {Str.removeSMSDomain(currentUserPersonalDetails.login ?? '')} + {formatPhoneNumber(currentUserPersonalDetails.login ?? '')} {!!isDebugModeEnabled && ( tokenizedSearch([item], searchInput, (option) => [option.text, option.description ?? '']).length > 0; +type AccountSwitcherMenuItem = PopoverMenuItem & { + /** The account's unformatted login with the SMS domain stripped, so search still matches typed digits or the bare login even though `description` is reformatted for readability via formatPhoneNumber. */ + rawLogin: string; +}; + +const filterMenuItem = (item: AccountSwitcherMenuItem, searchInput: string) => + tokenizedSearch([item], searchInput, (option) => [option.text, option.description ?? '', option.rawLogin]).length > 0; + +// PopoverMenu spreads every field it doesn't explicitly destructure onto the rendered MenuItem, so rawLogin (search-only, +// never rendered) has to be stripped before an item is handed to it, or it leaks through as an unrecognized prop. +const stripRawLogin = ({rawLogin: _rawLogin, ...item}: AccountSwitcherMenuItem): PopoverMenuItem => item; /** The "Switch" button and its delegator menu. Renders nothing for accounts that have no other account to switch to. */ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) { @@ -161,11 +171,12 @@ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) { personalDetails: PersonalDetails | undefined, errors: Errors | undefined, additionalProps: Partial> & WithRequiredSentryLabel, - ): PopoverMenuItem => { + ): AccountSwitcherMenuItem => { const error = Object.values(errors ?? {}).at(0) ?? ''; return { text: formatPhoneNumber(personalDetails?.displayName ?? personalDetails?.login ?? ''), - description: Str.removeSMSDomain(personalDetails?.login ?? ''), + description: formatPhoneNumber(personalDetails?.login ?? ''), + rawLogin: Str.removeSMSDomain(personalDetails?.login ?? ''), avatarID: personalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID, icon: personalDetails?.avatar ?? '', iconType: CONST.ICON_TYPE_AVATAR, @@ -180,7 +191,7 @@ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) { }; const currentUserMenuItem = createBaseMenuItem(currentUserPersonalDetails, undefined, {isSelected: true, sentryLabel: CONST.SENTRY_LABEL.ACCOUNT_SWITCHER.ACCOUNT_MENU.CURRENT_ACCOUNT}); - const delegatorMenuItems: PopoverMenuItem[] = sortAlphabetically( + const delegatorMenuItems: AccountSwitcherMenuItem[] = sortAlphabetically( delegators .filter(({email}) => email !== currentUserPersonalDetails.login) .map(({email, role}) => { @@ -214,7 +225,7 @@ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) { if (isActingAsDelegate) { // Avoid duplicating the current user in the list when switching accounts if (delegate === currentUserPersonalDetails.login) { - return [currentUserMenuItem]; + return [currentUserMenuItem].map(stripRawLogin); } const error = getLatestError(account?.delegatedAccess?.errorFields?.disconnect); @@ -237,10 +248,10 @@ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) { }, }), currentUserMenuItem, - ]; + ].map(stripRawLogin); } - return shouldShowSearchInput ? filteredMenuItems : allMenuItems; + return (shouldShowSearchInput ? filteredMenuItems : allMenuItems).map(stripRawLogin); }; const hideDelegatorMenu = () => { diff --git a/src/components/Tables/WorkspaceCompanyCardsTable/index.tsx b/src/components/Tables/WorkspaceCompanyCardsTable/index.tsx index 183e8d5229a7..1dd9d9340d47 100644 --- a/src/components/Tables/WorkspaceCompanyCardsTable/index.tsx +++ b/src/components/Tables/WorkspaceCompanyCardsTable/index.tsx @@ -220,13 +220,17 @@ function WorkspaceCompanyCardsTable({ }, dynamicSizing: { // Whichever of the cardholder's name (or the unassigned label) or their login renders wider decides the column's width. - getContentToMeasure: (item) => [ - { - text: item.isAssigned ? Str.removeSMSDomain(item.cardholder?.displayName ?? '') : translate('workspace.moreFeatures.companyCards.unassignedCards'), - fontSize: fontScale.text, - }, - {text: item.isAssigned ? Str.removeSMSDomain(item.cardholder?.login ?? '') : '', fontSize: fontScale.label}, - ], + getContentToMeasure: (item) => { + const cardholderDisplayName = item.cardholder?.displayName ?? ''; + const formattedCardholderDisplayName = Str.isSMSLogin(cardholderDisplayName) ? formatPhoneNumber(cardholderDisplayName) : cardholderDisplayName; + return [ + { + text: item.isAssigned ? formattedCardholderDisplayName : translate('workspace.moreFeatures.companyCards.unassignedCards'), + fontSize: fontScale.text, + }, + {text: item.isAssigned ? formatPhoneNumber(item.cardholder?.login ?? '') : '', fontSize: fontScale.label}, + ]; + }, extraWidth: variables.tableMemberCellAvatarWidth, }, }, diff --git a/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx b/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx index 6dd1823efea8..58b983bfc38a 100644 --- a/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx +++ b/src/pages/workspace/members/WorkspaceInviteMessageComponent.tsx @@ -283,8 +283,13 @@ function WorkspaceInviteMessageComponent({ const invitingMemberEmail = Object.keys(invitedEmailsToAccountIDsDraft ?? {}).at(0) ?? ''; const invitingMemberDetails = usePersonalDetailByLogin(invitingMemberEmail); - const invitingMemberName = Str.removeSMSDomain(invitingMemberDetails?.displayName ?? ''); - const invitingMemberTitle = invitingMemberName && invitingMemberName !== invitingMemberEmail ? invitingMemberName : invitingMemberEmail; + // formatPhoneNumber replaces spaces with a non-breaking space unconditionally, even for strings it otherwise + // returns unchanged, so an ordinary multi-word display name would get its spaces silently swapped. Only format + // when the display name is actually an SMS login. + const invitingMemberName = Str.isSMSLogin(invitingMemberDetails?.displayName ?? '') + ? formatPhoneNumber(invitingMemberDetails?.displayName ?? '') + : (invitingMemberDetails?.displayName ?? ''); + const invitingMemberTitle = invitingMemberName && invitingMemberName !== invitingMemberEmail ? invitingMemberName : formatPhoneNumber(invitingMemberEmail); const approverName = temporaryGetDisplayNameOrDefault({ passedPersonalDetails: approverDetails, defaultValue: workspaceInviteApproverDraft,