@@ -3,7 +3,7 @@ import type {ValueOf} from 'type-fest';
33import { FallbackAvatar } from '@components/Icon/Expensicons' ;
44import useOnyx from '@hooks/useOnyx' ;
55import useReportIsArchived from '@hooks/useReportIsArchived' ;
6- import { getReportAction } from '@libs/ReportActionsUtils' ;
6+ import { getOriginalMessage , getReportAction , isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
77import {
88 getDisplayNameForParticipant ,
99 getIcons ,
@@ -37,7 +37,6 @@ function useReportActionAvatars({
3737 policyID ?: string ;
3838} ) {
3939 /* Get avatar type */
40-
4140 const [ personalDetails ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST , {
4241 canBeMissing : true ,
4342 } ) ;
@@ -50,7 +49,15 @@ function useReportActionAvatars({
5049 const chatReport = isReportAChatReport ? report : reportChatReport ;
5150 const iouReport = isReportAChatReport ? undefined : report ;
5251
53- const action = passedAction ?? ( iouReport ?. parentReportActionID ? getReportAction ( chatReport ?. reportID ?? iouReport ?. chatReportID , iouReport ?. parentReportActionID ) : undefined ) ;
52+ let action ;
53+
54+ if ( passedAction ) {
55+ action = passedAction ;
56+ } else if ( iouReport ?. parentReportActionID ) {
57+ action = getReportAction ( chatReport ?. reportID ?? iouReport ?. chatReportID , iouReport ?. parentReportActionID ) ;
58+ } else if ( ! ! reportChatReport && ! ! chatReport ?. parentReportActionID && ! iouReport ) {
59+ action = getReportAction ( reportChatReport ?. reportID , chatReport . parentReportActionID ) ;
60+ }
5461
5562 const isReportArchived = useReportIsArchived ( iouReport ?. reportID ) ;
5663
@@ -87,8 +94,9 @@ function useReportActionAvatars({
8794 } ;
8895 }
8996
97+ const isWorkspacePolicy = ! ! policy && policy . type !== CONST . POLICY . TYPE . PERSONAL ;
9098 const isATripRoom = isTripRoom ( chatReport ) ;
91- const isWorkspaceWithoutChatReportProp = ! chatReport && policy ?. type !== CONST . POLICY . TYPE . PERSONAL ;
99+ const isWorkspaceWithoutChatReportProp = ! chatReport && isWorkspacePolicy ;
92100 const isAWorkspaceChat = isPolicyExpenseChat ( chatReport ) || isWorkspaceWithoutChatReportProp ;
93101 const isATripPreview = action ?. actionName === CONST . REPORT . ACTIONS . TYPE . TRIP_PREVIEW ;
94102 const isAReportPreviewAction = action ?. actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ;
@@ -101,13 +109,15 @@ function useReportActionAvatars({
101109 const shouldUseAccountIDs = accountIDs . length > 0 ;
102110 const shouldShowAllActors = displayAllActors && ! reportPreviewSenderID ;
103111 const isChatThreadOutsideTripRoom = isChatThread ( chatReport ) && ! isATripRoom ;
104- const shouldShowSubscriptAvatar = shouldReportShowSubscript ( iouReport ?? chatReport , isReportArchived ) && policy ?. type !== CONST . POLICY . TYPE . PERSONAL ;
112+ const shouldShowSubscriptAvatar = shouldReportShowSubscript ( iouReport ?? chatReport , isReportArchived ) && isWorkspacePolicy ;
105113 const shouldShowConvertedSubscriptAvatar = ( shouldStackHorizontally || shouldUseAccountIDs ) && shouldShowSubscriptAvatar && ! reportPreviewSenderID ;
114+ const isExpense = isMoneyRequestAction ( action ) && getOriginalMessage ( action ) ?. type === CONST . IOU . ACTION . CREATE ;
115+ const isWorkspaceExpense = isWorkspacePolicy && isExpense ;
106116
107117 const shouldUseSubscriptAvatar =
108- ( ( ( shouldShowSubscriptAvatar && isReportPreviewOrNoAction ) || isReportPreviewInTripRoom || isATripPreview ) &&
118+ ( ( ( shouldShowSubscriptAvatar && isReportPreviewOrNoAction ) || isReportPreviewInTripRoom || isATripPreview || isWorkspaceExpense ) &&
109119 ! shouldStackHorizontally &&
110- ! isChatThreadOutsideTripRoom &&
120+ ! ( isChatThreadOutsideTripRoom && ! isWorkspaceExpense ) &&
111121 ! shouldShowConvertedSubscriptAvatar ) ||
112122 shouldUseCardFeed ;
113123
@@ -134,6 +144,8 @@ function useReportActionAvatars({
134144
135145 const defaultDisplayName = getDisplayNameForParticipant ( { accountID, personalDetailsData : personalDetails } ) ?? '' ;
136146 const isAInvoiceReport = isInvoiceReport ( iouReport ?? null ) ;
147+ const invoiceReport = [ iouReport , chatReport , reportChatReport ] . find ( isInvoiceReport ) ;
148+ const isNestedInInvoiceReport = ! ! invoiceReport ;
137149 const isWorkspaceActor = isAInvoiceReport || ( isAWorkspaceChat && ( ! actorAccountID || displayAllActors ) ) ;
138150 const isChatReportOnlyProp = ! iouReport && chatReport ;
139151 const isWorkspaceChatWithoutChatReport = ! chatReport && isAWorkspaceChat ;
@@ -206,9 +218,18 @@ function useReportActionAvatars({
206218
207219 const shouldUseMappedAccountIDs = avatarsForAccountIDs . length > 0 && ( avatarType === CONST . REPORT_ACTION_AVATARS . TYPE . MULTIPLE || shouldUseActorAccountID ) ;
208220 const shouldUsePrimaryAvatarID = isWorkspaceActor && ! ! primaryAvatar . id ;
221+ const shouldUseInvoiceExpenseIcons = isWorkspaceExpense && isNestedInInvoiceReport && ! ! accountID ;
222+
223+ let avatars = [ primaryAvatar , secondaryAvatar ] ;
224+
225+ if ( shouldUseInvoiceExpenseIcons ) {
226+ avatars = getIconsWithDefaults ( invoiceReport ) ;
227+ } else if ( shouldUseMappedAccountIDs ) {
228+ avatars = avatarsForAccountIDs ;
229+ }
209230
210231 return {
211- avatars : shouldUseMappedAccountIDs ? avatarsForAccountIDs : [ primaryAvatar , secondaryAvatar ] ,
232+ avatars,
212233 avatarType,
213234 details : {
214235 ...( personalDetails ?. [ accountID ] ?? { } ) ,
0 commit comments