Skip to content

Commit

Permalink
Merge pull request #47029 from nkdengineer/fix/45414
Browse files Browse the repository at this point in the history
fix: report title is incorrect for IOU grouped expense in search page
  • Loading branch information
luacmartins authored Aug 14, 2024
2 parents d4d5a25 + fcda772 commit 34f128a
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ import type {SearchAdvancedFiltersForm} from '@src/types/form';
import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm';
import type * as OnyxTypes from '@src/types/onyx';
import type SearchResults from '@src/types/onyx/SearchResults';
import type {ListItemDataType, ListItemType, SearchAccountDetails, SearchDataTypes, SearchPersonalDetails, SearchTransaction} from '@src/types/onyx/SearchResults';
import type {
ListItemDataType,
ListItemType,
SearchAccountDetails,
SearchDataTypes,
SearchPersonalDetails,
SearchPolicyDetails,
SearchReport,
SearchTransaction,
} from '@src/types/onyx/SearchResults';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import {translateLocal} from './Localize';
import navigationRef from './Navigation/navigationRef';
import type {AuthScreensParamList, BottomTabNavigatorParamList, RootStackParamList, State} from './Navigation/types';
import * as searchParser from './SearchParser/searchParser';
Expand Down Expand Up @@ -173,6 +184,28 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data'], metadata
});
}

function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: SearchTransaction & Record<string, SearchPersonalDetails> & 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 === CONST.SEARCH.ACTION_TYPES.VIEW) {
return translateLocal('iou.payerOwesAmount', {
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[] {
const shouldShowMerchant = getShouldShowMerchant(data);

Expand All @@ -185,6 +218,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)
Expand All @@ -196,6 +230,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]};
Expand Down

0 comments on commit 34f128a

Please sign in to comment.