1- import React , { useMemo } from 'react' ;
2- import type { ColorValue , StyleProp , ViewStyle } from 'react-native' ;
1+ import React from 'react' ;
2+ import type { ColorValue , ViewStyle } from 'react-native' ;
33import type { OnyxEntry } from 'react-native-onyx' ;
44import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
55import { shouldOptionShowTooltip } from '@libs/OptionsListUtils' ;
@@ -15,51 +15,41 @@ type OptionRowAvatarProps = {
1515 isInFocusMode : boolean ;
1616 subscriptAvatarBorderColor : ColorValue ;
1717 secondaryAvatarBackgroundColor : ColorValue ;
18- singleAvatarContainerStyle : StyleProp < ViewStyle > ;
18+ singleAvatarContainerStyle : ViewStyle [ ] ;
1919} ;
2020
2121function OptionRowAvatar ( { optionItem, report, isInFocusMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor, singleAvatarContainerStyle} : OptionRowAvatarProps ) {
2222 const personalDetails = usePersonalDetails ( ) ;
2323
24- const delegateAccountID = useMemo (
25- ( ) => getDelegateAccountIDFromReportAction ( optionItem ?. parentReportAction ) ,
26- // eslint-disable-next-line react-hooks/exhaustive-deps -- getDelegateAccountIDFromReportAction is a stable import; only parentReportAction determines the result
27- [ optionItem ?. parentReportAction ] ,
28- ) ;
24+ const delegateAccountID = getDelegateAccountIDFromReportAction ( optionItem ?. parentReportAction ) ;
2925
3026 // Match the header's delegate avatar logic: when a delegate exists on the
3127 // parent report action, the header (useReportActionAvatars) shows the
3228 // delegate's avatar as primary instead of the report owner's.
3329 const skipDelegate = report ?. type === CONST . REPORT . TYPE . INVOICE || ( optionItem ?. isTaskReport && ! report ?. chatReportID ) ;
3430
35- const icons = useMemo ( ( ) => {
36- let result = optionItem ?. icons ?? [ ] ;
37- if ( ! skipDelegate && delegateAccountID && personalDetails && result . length > 0 ) {
38- const delegateDetails = personalDetails [ delegateAccountID ] ;
39- if ( delegateDetails ) {
40- const updatedIcons = [ ...result ] ;
41- const firstIcon = updatedIcons . at ( 0 ) ;
42- if ( firstIcon ) {
43- updatedIcons [ 0 ] = {
44- ...firstIcon ,
45- source : delegateDetails . avatar ?? '' ,
46- name : delegateDetails . displayName ?? '' ,
47- id : delegateAccountID ,
48- } ;
49- }
50- result = updatedIcons ;
31+ let icons = optionItem ?. icons ?? [ ] ;
32+ if ( ! skipDelegate && delegateAccountID && personalDetails && icons . length > 0 ) {
33+ const delegateDetails = personalDetails [ delegateAccountID ] ;
34+ if ( delegateDetails ) {
35+ const updatedIcons = [ ...icons ] ;
36+ const firstDelegateIcon = updatedIcons . at ( 0 ) ;
37+ if ( firstDelegateIcon ) {
38+ updatedIcons [ 0 ] = {
39+ ...firstDelegateIcon ,
40+ source : delegateDetails . avatar ?? '' ,
41+ name : delegateDetails . displayName ?? '' ,
42+ id : delegateAccountID ,
43+ } ;
5144 }
45+ icons = updatedIcons ;
5246 }
47+ }
5348
54- return result ;
55- } , [ optionItem ?. icons , skipDelegate , delegateAccountID , personalDetails ] ) ;
56-
57- const delegateTooltipAccountID = useMemo ( ( ) => {
58- if ( ! skipDelegate && delegateAccountID && personalDetails ?. [ delegateAccountID ] && optionItem ?. icons ?. length ) {
59- return Number ( optionItem . icons . at ( 0 ) ?. id ?? CONST . DEFAULT_NUMBER_ID ) ;
60- }
61- return undefined ;
62- } , [ skipDelegate , delegateAccountID , personalDetails , optionItem ?. icons ] ) ;
49+ let delegateTooltipAccountID : number | undefined ;
50+ if ( ! skipDelegate && delegateAccountID && personalDetails ?. [ delegateAccountID ] && optionItem ?. icons ?. length ) {
51+ delegateTooltipAccountID = Number ( optionItem . icons . at ( 0 ) ?. id ?? CONST . DEFAULT_NUMBER_ID ) ;
52+ }
6353
6454 const firstIcon = optionItem . icons ?. at ( 0 ) ;
6555
0 commit comments