From c7b9c0e2b9af775489a89ac27a821491c69636f0 Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Wed, 24 Jul 2024 10:36:43 +0700 Subject: [PATCH 1/2] Fix LHN chat displays owes 0.00 Signed-off-by: Tsaqif --- src/components/LHNOptionsList/LHNOptionsList.tsx | 6 ++++++ src/components/LHNOptionsList/OptionRowLHNData.tsx | 2 ++ src/libs/OptionsListUtils.ts | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index 2cc931303a30..0a6fbfdb94f0 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -19,6 +19,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as DraftCommentUtils from '@libs/DraftCommentUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -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/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index ebe4ffdbe53a..cb365397556e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -662,6 +662,14 @@ function isSearchStringMatchUserDetails(personalDetail: PersonalDetails, searchV return isSearchStringMatch(searchValue.trim(), memberDetails.toLowerCase()); } +function getIOUReportIDOfLastAction(report) { + 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 +2634,7 @@ export { isSearchStringMatchUserDetails, getAllReportErrors, getPolicyExpenseReportOption, + getIOUReportIDOfLastAction, getParticipantsOption, isSearchStringMatch, shouldOptionShowTooltip, From 1c26ea43f49f2a72d7d2718fd6cbec7428e47e86 Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Thu, 25 Jul 2024 10:32:11 +0700 Subject: [PATCH 2/2] Add types and comments Signed-off-by: Tsaqif --- src/components/LHNOptionsList/LHNOptionsList.tsx | 4 ++-- src/components/LHNOptionsList/types.ts | 3 +++ src/libs/OptionsListUtils.ts | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/LHNOptionsList/LHNOptionsList.tsx b/src/components/LHNOptionsList/LHNOptionsList.tsx index 0a6fbfdb94f0..bed516f31287 100644 --- a/src/components/LHNOptionsList/LHNOptionsList.tsx +++ b/src/components/LHNOptionsList/LHNOptionsList.tsx @@ -18,8 +18,8 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as DraftCommentUtils from '@libs/DraftCommentUtils'; -import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -121,7 +121,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1']; const iouReportIDOfLastAction = OptionsListUtils.getIOUReportIDOfLastAction(itemFullReport); - const itemIouReportReportActions = !!iouReportIDOfLastAction ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportIDOfLastAction}`] : undefined; + const itemIouReportReportActions = iouReportIDOfLastAction ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportIDOfLastAction}`] : undefined; const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`]; const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction) 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 cb365397556e..1e418790cdce 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -662,7 +662,13 @@ function isSearchStringMatchUserDetails(personalDetail: PersonalDetails, searchV return isSearchStringMatch(searchValue.trim(), memberDetails.toLowerCase()); } -function getIOUReportIDOfLastAction(report) { +/** + * 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;