Skip to content

Commit 2ee9b1f

Browse files
authored
Merge pull request Expensify#63133 from nkdengineer/fix/62941
IOU is displayed within the iouReport preview instead of X owes $y
2 parents ae3e452 + 641c161 commit 2ee9b1f

4 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportU
3535
import Navigation from '@libs/Navigation/Navigation';
3636
import Performance from '@libs/Performance';
3737
import {getConnectedIntegration} from '@libs/PolicyUtils';
38-
import {getOriginalMessage, isActionOfType} from '@libs/ReportActionsUtils';
3938
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
4039
import {
4140
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
4241
getBankAccountRoute,
4342
getDisplayNameForParticipant,
4443
getInvoicePayerName,
44+
getMoneyReportPreviewName,
4545
getMoneyRequestSpendBreakdown,
4646
getNonHeldAndFullAmount,
4747
getPolicyName,
@@ -437,14 +437,6 @@ function MoneyRequestReportPreviewContent({
437437
setOptimisticIndex(undefined);
438438
}, [carouselTransactions.length, currentIndex, currentVisibleItems, currentVisibleItems.length, optimisticIndex, visibleItemsOnEndCount]);
439439

440-
const getPreviewName = () => {
441-
if (isInvoice && isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW)) {
442-
const originalMessage = getOriginalMessage(action);
443-
return originalMessage && translate('iou.invoiceReportName', originalMessage);
444-
}
445-
return action.childReportName;
446-
};
447-
448440
const openReportFromPreview = useCallback(() => {
449441
if (!iouReportID) {
450442
return;
@@ -659,7 +651,7 @@ function MoneyRequestReportPreviewContent({
659651
style={[styles.headerText]}
660652
testID="MoneyRequestReportPreview-reportName"
661653
>
662-
{getPreviewName()}
654+
{getMoneyReportPreviewName(action, iouReport, isInvoice)}
663655
</Text>
664656
{!doesReportNameOverflow && <>&nbsp;{approvedOrSettledIcon}</>}
665657
</Text>

src/libs/ReportUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10838,6 +10838,14 @@ function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportA
1083810838
return reportActionList.some((action) => isReopenedAction(action));
1083910839
}
1084010840

10841+
function getMoneyReportPreviewName(action: ReportAction, iouReport: OnyxEntry<Report>, isInvoice?: boolean) {
10842+
if (isInvoice && isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW)) {
10843+
const originalMessage = getOriginalMessage(action);
10844+
return originalMessage && translateLocal('iou.invoiceReportName', originalMessage);
10845+
}
10846+
return getReportName(iouReport) || action.childReportName;
10847+
}
10848+
1084110849
export {
1084210850
addDomainToShortMention,
1084310851
completeShortMention,
@@ -11214,6 +11222,7 @@ export {
1121411222
isWorkspaceEligibleForReportChange,
1121511223
navigateOnDeleteExpense,
1121611224
hasReportBeenReopened,
11225+
getMoneyReportPreviewName,
1121711226
};
1121811227

1121911228
export type {

tests/ui/MoneyRequestReportPreview.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('MoneyRequestReportPreview', () => {
137137
renderPage({});
138138
await waitForBatchedUpdatesWithAct();
139139
await Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, mockOnyxTransactions).then(waitForBatchedUpdates);
140-
const {childReportName: moneyRequestReportPreviewName = ''} = mockAction;
140+
const {reportName: moneyRequestReportPreviewName = ''} = mockChatReport;
141141
for (const transaction of arrayOfTransactions) {
142142
const {transactionDisplayAmount, transactionHeaderText} = getTransactionDisplayAmountAndHeaderText(transaction);
143143

tests/unit/ReportUtilsTest.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
getGroupChatName,
3333
getIconsForParticipants,
3434
getInvoiceChatByParticipants,
35+
getMoneyReportPreviewName,
3536
getMostRecentlyVisitedReport,
3637
getParticipantsList,
3738
getPolicyExpenseChat,
@@ -2800,6 +2801,30 @@ describe('ReportUtils', () => {
28002801
});
28012802
});
28022803

2804+
describe('getMoneyReportPreviewName', () => {
2805+
it('should return the report name if present', () => {
2806+
const action: ReportAction = {
2807+
...createRandomReportAction(1),
2808+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
2809+
};
2810+
const report: Report = {
2811+
...createRandomReport(1),
2812+
};
2813+
const result = getMoneyReportPreviewName(action, report);
2814+
expect(result).toBe('Five, Four, One, Three, Two...');
2815+
});
2816+
2817+
it('should return the child report name if the report name is not present', () => {
2818+
const action: ReportAction = {
2819+
...createRandomReportAction(1),
2820+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
2821+
childReportName: 'Child Report',
2822+
};
2823+
const result = getMoneyReportPreviewName(action, undefined);
2824+
expect(result).toBe('Child Report');
2825+
});
2826+
});
2827+
28032828
describe('canAddTransaction', () => {
28042829
it('should return true for a non-archived report', async () => {
28052830
// Given a non-archived expense report

0 commit comments

Comments
 (0)