diff --git a/src/components/ReportActionAvatars/ReportActionAvatar.tsx b/src/components/ReportActionAvatars/ReportActionAvatar.tsx index 1e8efbe9cb860..b7369d806e67a 100644 --- a/src/components/ReportActionAvatars/ReportActionAvatar.tsx +++ b/src/components/ReportActionAvatars/ReportActionAvatar.tsx @@ -107,6 +107,7 @@ function ReportActionAvatarSingle({ fallbackIcon, isInReportAction, useProfileNavigationWrapper, + fallbackDisplayName, }: { avatar: IconType | undefined; size: ValueOf; @@ -117,6 +118,7 @@ function ReportActionAvatarSingle({ fallbackIcon?: AvatarSource; isInReportAction?: boolean; useProfileNavigationWrapper?: boolean; + fallbackDisplayName?: string; }) { const StyleUtils = useStyleUtils(); const avatarContainerStyles = StyleUtils.getContainerStyles(size, isInReportAction); @@ -127,7 +129,8 @@ function ReportActionAvatarSingle({ delegateAccountID={delegateAccountID} icon={avatar} fallbackUserDetails={{ - displayName: avatar?.name, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + displayName: fallbackDisplayName || avatar?.name, }} shouldRender={shouldShowTooltip} > @@ -157,6 +160,7 @@ function ReportActionAvatarSubscript({ noRightMarginOnContainer, subscriptAvatarBorderColor, subscriptCardFeed, + fallbackDisplayName, useProfileNavigationWrapper, }: { primaryAvatar: IconType; @@ -166,6 +170,7 @@ function ReportActionAvatarSubscript({ noRightMarginOnContainer?: boolean; subscriptAvatarBorderColor?: ColorValue; subscriptCardFeed?: CompanyCardFeed | typeof CONST.EXPENSIFY_CARD.BANK; + fallbackDisplayName?: string; useProfileNavigationWrapper?: boolean; }) { const theme = useTheme(); @@ -204,7 +209,8 @@ function ReportActionAvatarSubscript({ accountID={Number(primaryAvatar.id ?? CONST.DEFAULT_NUMBER_ID)} icon={primaryAvatar} fallbackUserDetails={{ - displayName: primaryAvatar.name, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + displayName: fallbackDisplayName || primaryAvatar.name, }} > @@ -310,11 +316,13 @@ function ReportActionAvatarMultipleHorizontal({ isInReportAction, sort: sortAvatars, useProfileNavigationWrapper, + fallbackDisplayName, }: HorizontalStacking & { size: ValueOf; shouldShowTooltip: boolean; icons: IconType[]; isInReportAction: boolean; + fallbackDisplayName?: string; useProfileNavigationWrapper?: boolean; }) { const theme = useTheme(); @@ -375,7 +383,8 @@ function ReportActionAvatarMultipleHorizontal({ accountID={Number(icon.id)} icon={icon} fallbackUserDetails={{ - displayName: icon.name, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + displayName: fallbackDisplayName || icon.name, }} shouldRender={shouldShowTooltip} > @@ -451,6 +460,7 @@ function ReportActionAvatarMultipleDiagonal({ secondaryAvatarContainerStyle, isHovered = false, useProfileNavigationWrapper, + fallbackDisplayName, }: { size: ValueOf; shouldShowTooltip: boolean; @@ -460,6 +470,7 @@ function ReportActionAvatarMultipleDiagonal({ secondaryAvatarContainerStyle?: StyleProp; isHovered?: boolean; useProfileNavigationWrapper?: boolean; + fallbackDisplayName?: string; }) { const theme = useTheme(); const styles = useThemeStyles(); @@ -520,7 +531,8 @@ function ReportActionAvatarMultipleDiagonal({ accountID={Number(icons.at(0)?.id)} icon={icons.at(0)} fallbackUserDetails={{ - displayName: icons.at(0)?.name, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + displayName: fallbackDisplayName || icons.at(0)?.name, }} shouldRender={shouldShowTooltip} > @@ -551,7 +563,8 @@ function ReportActionAvatarMultipleDiagonal({ accountID={Number(icons.at(1)?.id)} icon={icons.at(1)} fallbackUserDetails={{ - displayName: icons.at(1)?.name, + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + displayName: fallbackDisplayName || icons.at(1)?.name, }} shouldRender={shouldShowTooltip} > diff --git a/src/components/ReportActionAvatars/index.tsx b/src/components/ReportActionAvatars/index.tsx index ddafc76fbb485..f3ec5b24563b5 100644 --- a/src/components/ReportActionAvatars/index.tsx +++ b/src/components/ReportActionAvatars/index.tsx @@ -54,6 +54,9 @@ type ReportActionAvatarsProps = { /** Whether we want to be redirected to profile on avatars click */ useProfileNavigationWrapper?: boolean; + + /** Display name used as a fallback for avatar tooltip */ + fallbackDisplayName?: string; }; /** @@ -81,6 +84,7 @@ function ReportActionAvatars({ useMidSubscriptSizeForMultipleAvatars = false, isInReportAction = false, useProfileNavigationWrapper, + fallbackDisplayName, }: ReportActionAvatarsProps) { const accountIDs = passedAccountIDs.filter((accountID) => accountID !== CONST.DEFAULT_NUMBER_ID); @@ -131,6 +135,7 @@ function ReportActionAvatars({ subscriptAvatarBorderColor={subscriptAvatarBorderColor} subscriptCardFeed={subscriptCardFeed} useProfileNavigationWrapper={useProfileNavigationWrapper} + fallbackDisplayName={fallbackDisplayName} /> ); } @@ -145,6 +150,7 @@ function ReportActionAvatars({ isInReportAction={isInReportAction} shouldShowTooltip={shouldShowTooltip} useProfileNavigationWrapper={useProfileNavigationWrapper} + fallbackDisplayName={fallbackDisplayName} /> ); } @@ -159,6 +165,7 @@ function ReportActionAvatars({ useMidSubscriptSize={useMidSubscriptSizeForMultipleAvatars} secondaryAvatarContainerStyle={secondaryAvatarContainerStyle} isHovered={isHovered} + fallbackDisplayName={fallbackDisplayName} useProfileNavigationWrapper={useProfileNavigationWrapper} /> ); @@ -173,6 +180,7 @@ function ReportActionAvatars({ accountID={Number(delegateAccountID ?? primaryAvatar.id ?? CONST.DEFAULT_NUMBER_ID)} delegateAccountID={source.action?.delegateAccountID} fallbackIcon={primaryAvatar.fallbackIcon} + fallbackDisplayName={fallbackDisplayName} useProfileNavigationWrapper={useProfileNavigationWrapper} /> ); diff --git a/src/components/ReportActionAvatars/useReportActionAvatars.ts b/src/components/ReportActionAvatars/useReportActionAvatars.ts index 1fb0ef57c89c8..9b83da182ef6e 100644 --- a/src/components/ReportActionAvatars/useReportActionAvatars.ts +++ b/src/components/ReportActionAvatars/useReportActionAvatars.ts @@ -194,22 +194,28 @@ function useReportActionAvatars({ fallbackIcon, }; - const avatarsForAccountIDs: IconType[] = accountIDs.map((id) => ({ + const shouldUseActorAccountID = isAInvoiceReport && !isAReportPreviewAction; + const accountIDsToMap = shouldUseActorAccountID && actorAccountID ? [actorAccountID] : accountIDs; + + const avatarsForAccountIDs: IconType[] = accountIDsToMap.map((id) => ({ id, type: CONST.ICON_TYPE_AVATAR, source: personalDetails?.[id]?.avatar ?? FallbackAvatar, - name: personalDetails?.[id]?.login ?? '', + name: personalDetails?.[id]?.[shouldUseActorAccountID ? 'displayName' : 'login'] ?? '', })); + const shouldUseMappedAccountIDs = avatarsForAccountIDs.length > 0 && (avatarType === CONST.REPORT_ACTION_AVATARS.TYPE.MULTIPLE || shouldUseActorAccountID); + const shouldUsePrimaryAvatarID = isWorkspaceActor && !!primaryAvatar.id; + return { - avatars: avatarsForAccountIDs.length > 0 && avatarType === CONST.REPORT_ACTION_AVATARS.TYPE.MULTIPLE ? avatarsForAccountIDs : [primaryAvatar, secondaryAvatar], + avatars: shouldUseMappedAccountIDs ? avatarsForAccountIDs : [primaryAvatar, secondaryAvatar], avatarType, details: { ...(personalDetails?.[accountID] ?? {}), shouldDisplayAllActors: displayAllActors, isWorkspaceActor, // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - actorHint: String(isWorkspaceActor ? primaryAvatar.id : login || (defaultDisplayName ?? '')).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''), + actorHint: String(shouldUsePrimaryAvatarID ? primaryAvatar.id : login || defaultDisplayName || 'Unknown user').replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''), accountID, delegateAccountID: !isWorkspaceActor && delegatePersonalDetails ? actorAccountID : undefined, }, diff --git a/src/components/SelectionList/InviteMemberListItem.tsx b/src/components/SelectionList/InviteMemberListItem.tsx index bf863ec29fd7a..bd9ae8ea5c985 100644 --- a/src/components/SelectionList/InviteMemberListItem.tsx +++ b/src/components/SelectionList/InviteMemberListItem.tsx @@ -63,6 +63,11 @@ function InviteMemberListItem({ } }, [item, onCheckboxPress, onSelectRow]); + const firstItemIconID = Number(item?.icons?.at(0)?.id); + + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const accountID = !item.reportID ? item.accountID || firstItemIconID : undefined; + return ( ({ wrapperStyle={styles.productTrainingTooltipWrapper} > - {!!item.icons && ( + {(!!item.reportID || !!accountID) && ( ({ ]} singleAvatarContainerStyle={[styles.actionAvatar, styles.mr3]} reportID={item.reportID} - accountIDs={!item.reportID && item.accountID ? [item.accountID] : undefined} + accountIDs={accountID ? [accountID] : undefined} /> )} diff --git a/src/components/SelectionList/UserListItem.tsx b/src/components/SelectionList/UserListItem.tsx index 7d623962295f8..a26b55286f02b 100644 --- a/src/components/SelectionList/UserListItem.tsx +++ b/src/components/SelectionList/UserListItem.tsx @@ -112,6 +112,7 @@ function UserListItem({ accountIDs={[Number(item.accountID)]} policyID={!item.reportID && !item.accountID ? item.policyID : undefined} singleAvatarContainerStyle={[styles.actionAvatar, styles.mr3]} + fallbackDisplayName={item.text ?? item.alternateText ?? undefined} /> )}