From a515fe824cf69ec3f59428cbade1cd694bc2c8e1 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 8 Aug 2024 11:34:35 +0700 Subject: [PATCH 1/4] fix: report title is incorrect for IOU grouped expense in search page --- src/libs/SearchUtils.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index bdb4e7c8e005..cdb6e0e03609 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -9,8 +9,19 @@ import type {SearchAdvancedFiltersForm} from '@src/types/form'; import INPUT_IDS from '@src/types/form/SearchAdvancedFiltersForm'; import type * as OnyxTypes from '@src/types/onyx'; import type SearchResults from '@src/types/onyx/SearchResults'; -import type {SearchAccountDetails, SearchDataTypes, SearchPersonalDetails, SearchTransaction, SearchTypeToItemMap, SectionsType} from '@src/types/onyx/SearchResults'; +import type { + SearchAccountDetails, + SearchDataTypes, + SearchPersonalDetails, + SearchPolicyDetails, + SearchReport, + SearchTransaction, + SearchTypeToItemMap, + SectionsType, +} from '@src/types/onyx/SearchResults'; +import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; +import {translateLocal} from './Localize'; import getTopmostCentralPaneRoute from './Navigation/getTopmostCentralPaneRoute'; import navigationRef from './Navigation/navigationRef'; import type {AuthScreensParamList, RootStackParamList, State} from './Navigation/types'; @@ -170,6 +181,21 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data'], metadata }); } +function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: SearchTransaction & Record & SearchPolicyDetails & SearchReport) { + const payerPersonalDetails = data.personalDetailsList?.[reportItem.managerID] as SearchAccountDetails; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const payerName = payerPersonalDetails?.name || payerPersonalDetails?.displayName || payerPersonalDetails?.login || translateLocal('common.hidden'); + const formattedAmount = CurrencyUtils.convertToDisplayString(reportItem.total ?? 0, reportItem?.currency ?? CONST.CURRENCY.USD); + if (reportItem.action === 'view') { + return translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); + } + + return translateLocal('iou.payerPaidAmount', { + payer: payerName, + amount: formattedAmount, + }); +} + function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): ReportListItemType[] { const shouldShowMerchant = getShouldShowMerchant(data); @@ -182,6 +208,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportItem.reportID}`; const transactions = reportIDToTransactions[reportKey]?.transactions ?? []; const isExpenseReport = reportItem.type === CONST.REPORT.TYPE.EXPENSE; + const isIOUReport = reportItem.type === CONST.REPORT.TYPE.IOU; const to = isExpenseReport ? (data[`${ONYXKEYS.COLLECTION.POLICY}${reportItem.policyID}`] as SearchAccountDetails) @@ -193,6 +220,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx from: data.personalDetailsList?.[reportItem.accountID], to, transactions, + reportName: isIOUReport ? getIOUReportName(data, reportItem) : reportItem.reportName, }; } else if (key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) { const transactionItem = {...data[key]}; From e27ea22cc3ebdcbe43fb325a5e1e4e9a03ef3691 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 14 Aug 2024 09:17:53 +0700 Subject: [PATCH 2/4] Update src/libs/SearchUtils.ts Co-authored-by: Carlos Martins --- src/libs/SearchUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 4ae4272f2994..3b537a2c8ae2 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -186,7 +186,7 @@ function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: Sea // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const payerName = payerPersonalDetails?.name || payerPersonalDetails?.displayName || payerPersonalDetails?.login || translateLocal('common.hidden'); const formattedAmount = CurrencyUtils.convertToDisplayString(reportItem.total ?? 0, reportItem?.currency ?? CONST.CURRENCY.USD); - if (reportItem.action === 'view') { + if (reportItem.action === CONST.SEARCH.ACTION_TYPES.VIEW) { return translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } From 8990a90b59f8c1230b0a610d16c43edfeb1a3685 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 14 Aug 2024 16:59:01 +0700 Subject: [PATCH 3/4] fallback to reportName --- src/libs/SearchUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 3001b258d30f..d72b1cdfee5f 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -193,10 +193,14 @@ function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: Sea return translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } - return translateLocal('iou.payerPaidAmount', { - payer: payerName, - amount: formattedAmount, - }); + if (reportItem.action === CONST.SEARCH.ACTION_TYPES.PAID) { + return translateLocal('iou.payerPaidAmount', { + payer: payerName, + amount: formattedAmount, + }); + } + + return reportItem.reportName; } function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): ReportListItemType[] { From fcda772e8c7d97a0762e2f0880e34c0d804e2216 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 14 Aug 2024 17:03:38 +0700 Subject: [PATCH 4/4] fix style --- src/libs/SearchUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index d72b1cdfee5f..78fe898408c4 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -190,7 +190,10 @@ function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: Sea const payerName = payerPersonalDetails?.name || payerPersonalDetails?.displayName || payerPersonalDetails?.login || translateLocal('common.hidden'); const formattedAmount = CurrencyUtils.convertToDisplayString(reportItem.total ?? 0, reportItem?.currency ?? CONST.CURRENCY.USD); if (reportItem.action === CONST.SEARCH.ACTION_TYPES.VIEW) { - return translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); + return translateLocal('iou.payerOwesAmount', { + payer: payerName, + amount: formattedAmount, + }); } if (reportItem.action === CONST.SEARCH.ACTION_TYPES.PAID) {