diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index 2cc931303a30..bed516f31287 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -18,6 +18,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as DraftCommentUtils from '@libs/DraftCommentUtils'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; @@ -118,6 +119,10 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`]; const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1']; + + const iouReportIDOfLastAction = OptionsListUtils.getIOUReportIDOfLastAction(itemFullReport); + const itemIouReportReportActions = iouReportIDOfLastAction ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportIDOfLastAction}`] : undefined; + const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`]; const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction) ? ReportActionsUtils.getOriginalMessage(itemParentReportAction)?.IOUTransactionID ?? '-1' @@ -141,6 +146,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio fullReport={itemFullReport} reportActions={itemReportActions} parentReportAction={itemParentReportAction} + iouReportReportActions={itemIouReportReportActions} policy={itemPolicy} personalDetails={personalDetails ?? {}} transaction={itemTransaction} diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index 2afd9e10b80c..30ea32642190 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -23,6 +23,7 @@ function OptionRowLHNData({ policy, receiptTransactions, parentReportAction, + iouReportReportActions, transaction, lastReportActionTransaction, transactionViolations, @@ -68,6 +69,7 @@ function OptionRowLHNData({ preferredLocale, policy, parentReportAction, + iouReportReportActions, transaction, transactionViolations, canUseViolations, diff --git a/src/components/LHNOptionsList/types.ts b/src/components/LHNOptionsList/types.ts index 2a4b09e8fcec..2c3637fa5c8e 100644 --- a/src/components/LHNOptionsList/types.ts +++ b/src/components/LHNOptionsList/types.ts @@ -71,6 +71,9 @@ type OptionRowLHNDataProps = { /** Array of report actions for this report */ reportActions: OnyxEntry; + /** Array of report actions of IOU report related to this report last action */ + iouReportReportActions: OnyxEntry; + /** List of transaction violation */ transactionViolations: OnyxCollection; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index ebe4ffdbe53a..1e418790cdce 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -662,6 +662,20 @@ function isSearchStringMatchUserDetails(personalDetail: PersonalDetails, searchV return isSearchStringMatch(searchValue.trim(), memberDetails.toLowerCase()); } +/** + * Get IOU report ID of report last action if the action is report action preview + */ +function getIOUReportIDOfLastAction(report: OnyxEntry): string | undefined { + if (!report?.reportID) { + return; + } + const lastAction = visibleReportActionItems[report.reportID]; + if (!ReportActionUtils.isReportPreviewAction(lastAction)) { + return; + } + return getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastAction))?.reportID; +} + /** * Get the last message text from the report directly or from other sources for special cases. */ @@ -2626,6 +2640,7 @@ export { isSearchStringMatchUserDetails, getAllReportErrors, getPolicyExpenseReportOption, + getIOUReportIDOfLastAction, getParticipantsOption, isSearchStringMatch, shouldOptionShowTooltip,