Skip to content
3 changes: 1 addition & 2 deletions src/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 ?? '')}
</Text>
{!!isDebugModeEnabled && (
<Text
Expand Down
25 changes: 18 additions & 7 deletions src/components/AccountSwitcherButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ type AccountSwitcherButtonProps = {
isScreenFocused: boolean;
};

const filterMenuItem = (item: PopoverMenuItem, searchInput: string) => 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;
Comment thread
FitseTLT marked this conversation as resolved.
Resolved

/** The "Switch" button and its delegator menu. Renders nothing for accounts that have no other account to switch to. */
function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) {
Expand Down Expand Up @@ -161,11 +171,12 @@ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) {
personalDetails: PersonalDetails | undefined,
errors: Errors | undefined,
additionalProps: Partial<Omit<PopoverMenuItem, 'icon' | 'iconType'>> & 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 ?? ''),
Comment thread
FitseTLT marked this conversation as resolved.
Resolved
rawLogin: Str.removeSMSDomain(personalDetails?.login ?? ''),
Comment thread
FitseTLT marked this conversation as resolved.
Resolved
avatarID: personalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID,
icon: personalDetails?.avatar ?? '',
iconType: CONST.ICON_TYPE_AVATAR,
Expand All @@ -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}) => {
Expand Down Expand Up @@ -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);
Expand All @@ -237,10 +248,10 @@ function AccountSwitcherButton({isScreenFocused}: AccountSwitcherButtonProps) {
},
}),
currentUserMenuItem,
];
].map(stripRawLogin);
}

return shouldShowSearchInput ? filteredMenuItems : allMenuItems;
return (shouldShowSearchInput ? filteredMenuItems : allMenuItems).map(stripRawLogin);
};

const hideDelegatorMenu = () => {
Expand Down
18 changes: 11 additions & 7 deletions src/components/Tables/WorkspaceCompanyCardsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '')
Comment thread
FitseTLT marked this conversation as resolved.
Resolved
? formatPhoneNumber(invitingMemberDetails?.displayName ?? '')
: (invitingMemberDetails?.displayName ?? '');
const invitingMemberTitle = invitingMemberName && invitingMemberName !== invitingMemberEmail ? invitingMemberName : formatPhoneNumber(invitingMemberEmail);
const approverName = temporaryGetDisplayNameOrDefault({
passedPersonalDetails: approverDetails,
defaultValue: workspaceInviteApproverDraft,
Expand Down
Loading