diff --git a/src/components/MultipleAvatars.tsx b/src/components/MultipleAvatars.tsx index febe18f30c7d..b71b379211d9 100644 --- a/src/components/MultipleAvatars.tsx +++ b/src/components/MultipleAvatars.tsx @@ -7,12 +7,19 @@ import * as StyleUtils from '@styles/StyleUtils'; import themeColors from '@styles/themes/default'; import variables from '@styles/variables'; import CONST from '@src/CONST'; +import {PersonalDetails} from '@src/types/onyx'; import type {Icon} from '@src/types/onyx/OnyxCommon'; import Avatar from './Avatar'; import Text from './Text'; import Tooltip from './Tooltip'; import UserDetailsTooltip from './UserDetailsTooltip'; +// TODO: once `src/components/participantPropTypes.js` is migrated to TS, this type should be moved there +type Participant = Pick< + PersonalDetails, + 'accountID' | 'avatar' | 'displayName' | 'firstName' | 'lastName' | 'localCurrencyCode' | 'login' | 'payPalMeAddress' | 'phoneNumber' | 'pronouns' | 'timezone' | 'validated' +>; + type MultipleAvatarsProps = { /** Array of avatar URLs or icons */ icons: Icon[]; @@ -52,6 +59,9 @@ type MultipleAvatarsProps = { /** Prop to limit the amount of avatars displayed horizontally */ maxAvatarsInRow?: number; + + /** List of participants */ + participants: Participant[]; }; type AvatarStyles = { @@ -92,6 +102,7 @@ function MultipleAvatars({ shouldShowTooltip = true, shouldUseCardBackground = false, maxAvatarsInRow = CONST.AVATAR_ROW_SIZE.DEFAULT, + participants = [], }: MultipleAvatarsProps) { let avatarContainerStyles = StyleUtils.getContainerStyles(size, isInReportAction); const {singleAvatarStyle, secondAvatarStyles} = useMemo(() => avatarSizeToStylesMap[size as AvatarSizeToStyles] ?? avatarSizeToStylesMap.default, [size]); @@ -109,6 +120,17 @@ function MultipleAvatars({ return CONST.AVATAR_SIZE.SMALLER; }, [isFocusMode, size]); + const participantsList = useMemo( + () => + participants.reduce>((all, participant) => { + const items = all; + items[participant.accountID] = participant; + + return items; + }, {}), + [participants], + ); + const avatarRows = useMemo(() => { // If we're not displaying avatars in rows or the number of icons is less than or equal to the max avatars in a row, return a single row if (!shouldDisplayAvatarsInRows || icons.length <= maxAvatarsInRow) { @@ -133,7 +155,7 @@ function MultipleAvatars({ if (icons.length === 1 && !shouldStackHorizontally) { return ( ( {icons.length === 2 ? ( ) : ( ; + type SubAvatar = { /** Avatar source to display */ source?: AvatarSource; @@ -44,9 +51,20 @@ type SubscriptAvatarProps = { /** Whether to show the tooltip */ showTooltip?: boolean; + + /** List of the participants of the chat */ + participants: Participant[]; }; -function SubscriptAvatar({mainAvatar = {}, secondaryAvatar = {}, size = CONST.AVATAR_SIZE.DEFAULT, backgroundColor, noMargin = false, showTooltip = true}: SubscriptAvatarProps) { +function SubscriptAvatar({ + mainAvatar = {}, + secondaryAvatar = {}, + size = CONST.AVATAR_SIZE.DEFAULT, + backgroundColor, + noMargin = false, + showTooltip = true, + participants = [], +}: SubscriptAvatarProps) { const theme = useTheme(); const styles = useThemeStyles(); const isSmall = size === CONST.AVATAR_SIZE.SMALL; @@ -57,7 +75,7 @@ function SubscriptAvatar({mainAvatar = {}, secondaryAvatar = {}, size = CONST.AV participant.accountID === mainAvatar.id)} icon={mainAvatar} > @@ -73,7 +91,7 @@ function SubscriptAvatar({mainAvatar = {}, secondaryAvatar = {}, size = CONST.AV participant.accountID === secondaryAvatar.id)} icon={secondaryAvatar} >