From 2273b634def2476924ebf80f686fa89ef0ee3ce5 Mon Sep 17 00:00:00 2001 From: Jakub Korytko Date: Wed, 6 Aug 2025 11:09:31 +0200 Subject: [PATCH] Add a logic for single expense & invoices --- .../useReportActionAvatars.ts | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/components/ReportActionAvatars/useReportActionAvatars.ts b/src/components/ReportActionAvatars/useReportActionAvatars.ts index 9b83da182ef6e..590bb9480e876 100644 --- a/src/components/ReportActionAvatars/useReportActionAvatars.ts +++ b/src/components/ReportActionAvatars/useReportActionAvatars.ts @@ -3,7 +3,7 @@ import type {ValueOf} from 'type-fest'; import {FallbackAvatar} from '@components/Icon/Expensicons'; import useOnyx from '@hooks/useOnyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; -import {getReportAction} from '@libs/ReportActionsUtils'; +import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; import { getDisplayNameForParticipant, getIcons, @@ -37,7 +37,6 @@ function useReportActionAvatars({ policyID?: string; }) { /* Get avatar type */ - const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, { canBeMissing: true, }); @@ -50,7 +49,15 @@ function useReportActionAvatars({ const chatReport = isReportAChatReport ? report : reportChatReport; const iouReport = isReportAChatReport ? undefined : report; - const action = passedAction ?? (iouReport?.parentReportActionID ? getReportAction(chatReport?.reportID ?? iouReport?.chatReportID, iouReport?.parentReportActionID) : undefined); + let action; + + if (passedAction) { + action = passedAction; + } else if (iouReport?.parentReportActionID) { + action = getReportAction(chatReport?.reportID ?? iouReport?.chatReportID, iouReport?.parentReportActionID); + } else if (!!reportChatReport && !!chatReport?.parentReportActionID && !iouReport) { + action = getReportAction(reportChatReport?.reportID, chatReport.parentReportActionID); + } const isReportArchived = useReportIsArchived(iouReport?.reportID); @@ -87,8 +94,9 @@ function useReportActionAvatars({ }; } + const isWorkspacePolicy = !!policy && policy.type !== CONST.POLICY.TYPE.PERSONAL; const isATripRoom = isTripRoom(chatReport); - const isWorkspaceWithoutChatReportProp = !chatReport && policy?.type !== CONST.POLICY.TYPE.PERSONAL; + const isWorkspaceWithoutChatReportProp = !chatReport && isWorkspacePolicy; const isAWorkspaceChat = isPolicyExpenseChat(chatReport) || isWorkspaceWithoutChatReportProp; const isATripPreview = action?.actionName === CONST.REPORT.ACTIONS.TYPE.TRIP_PREVIEW; const isAReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW; @@ -101,13 +109,15 @@ function useReportActionAvatars({ const shouldUseAccountIDs = accountIDs.length > 0; const shouldShowAllActors = displayAllActors && !reportPreviewSenderID; const isChatThreadOutsideTripRoom = isChatThread(chatReport) && !isATripRoom; - const shouldShowSubscriptAvatar = shouldReportShowSubscript(iouReport ?? chatReport, isReportArchived) && policy?.type !== CONST.POLICY.TYPE.PERSONAL; + const shouldShowSubscriptAvatar = shouldReportShowSubscript(iouReport ?? chatReport, isReportArchived) && isWorkspacePolicy; const shouldShowConvertedSubscriptAvatar = (shouldStackHorizontally || shouldUseAccountIDs) && shouldShowSubscriptAvatar && !reportPreviewSenderID; + const isExpense = isMoneyRequestAction(action) && getOriginalMessage(action)?.type === CONST.IOU.ACTION.CREATE; + const isWorkspaceExpense = isWorkspacePolicy && isExpense; const shouldUseSubscriptAvatar = - (((shouldShowSubscriptAvatar && isReportPreviewOrNoAction) || isReportPreviewInTripRoom || isATripPreview) && + (((shouldShowSubscriptAvatar && isReportPreviewOrNoAction) || isReportPreviewInTripRoom || isATripPreview || isWorkspaceExpense) && !shouldStackHorizontally && - !isChatThreadOutsideTripRoom && + !(isChatThreadOutsideTripRoom && !isWorkspaceExpense) && !shouldShowConvertedSubscriptAvatar) || shouldUseCardFeed; @@ -134,6 +144,8 @@ function useReportActionAvatars({ const defaultDisplayName = getDisplayNameForParticipant({accountID, personalDetailsData: personalDetails}) ?? ''; const isAInvoiceReport = isInvoiceReport(iouReport ?? null); + const invoiceReport = [iouReport, chatReport, reportChatReport].find(isInvoiceReport); + const isNestedInInvoiceReport = !!invoiceReport; const isWorkspaceActor = isAInvoiceReport || (isAWorkspaceChat && (!actorAccountID || displayAllActors)); const isChatReportOnlyProp = !iouReport && chatReport; const isWorkspaceChatWithoutChatReport = !chatReport && isAWorkspaceChat; @@ -206,9 +218,18 @@ function useReportActionAvatars({ const shouldUseMappedAccountIDs = avatarsForAccountIDs.length > 0 && (avatarType === CONST.REPORT_ACTION_AVATARS.TYPE.MULTIPLE || shouldUseActorAccountID); const shouldUsePrimaryAvatarID = isWorkspaceActor && !!primaryAvatar.id; + const shouldUseInvoiceExpenseIcons = isWorkspaceExpense && isNestedInInvoiceReport && !!accountID; + + let avatars = [primaryAvatar, secondaryAvatar]; + + if (shouldUseInvoiceExpenseIcons) { + avatars = getIconsWithDefaults(invoiceReport); + } else if (shouldUseMappedAccountIDs) { + avatars = avatarsForAccountIDs; + } return { - avatars: shouldUseMappedAccountIDs ? avatarsForAccountIDs : [primaryAvatar, secondaryAvatar], + avatars, avatarType, details: { ...(personalDetails?.[accountID] ?? {}),