From e6854394b21a81c0a936690d4b79183099f8e938 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sun, 11 Feb 2024 01:39:48 +0700 Subject: [PATCH 1/3] consistent system paid message --- src/libs/ReportUtils.ts | 8 ++++++-- .../home/report/ContextMenu/ContextMenuActions.tsx | 10 +++++++++- src/pages/home/report/ReportActionItemMessage.tsx | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 26280f95447d..4884f9ecd319 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2232,6 +2232,7 @@ function getReportPreviewMessage( isPreviewMessageForParentChatReport = false, policy: OnyxEntry = null, isForListPreview = false, + shouldHidePayer = false, ): string { const reportActionMessage = reportAction?.message?.[0].html ?? ''; @@ -2296,7 +2297,10 @@ function getReportPreviewMessage( if (isSettled(report.reportID) || (report.isWaitingOnBankAccount && isPreviewMessageForParentChatReport)) { // A settled report preview message can come in three formats "paid ... elsewhere" or "paid ... with Expensify" let translatePhraseKey: TranslationPaths = 'iou.paidElsewhereWithAmount'; - if ( + + if (isPreviewMessageForParentChatReport) { + translatePhraseKey = 'iou.payerPaidAmount'; + } else if ( [CONST.IOU.PAYMENT_TYPE.VBBA, CONST.IOU.PAYMENT_TYPE.EXPENSIFY].some((paymentType) => paymentType === originalMessage?.paymentType) || !!reportActionMessage.match(/ (with Expensify|using Expensify)$/) || report.isWaitingOnBankAccount @@ -2304,7 +2308,7 @@ function getReportPreviewMessage( translatePhraseKey = 'iou.paidWithExpensifyWithAmount'; } - let actualPayerName = report.managerID === currentUserAccountID ? '' : getDisplayNameForParticipant(report.managerID, true); + let actualPayerName = report.managerID === currentUserAccountID || shouldHidePayer ? '' : getDisplayNameForParticipant(report.managerID, true); actualPayerName = actualPayerName && isForListPreview && !isPreviewMessageForParentChatReport ? `${actualPayerName}:` : actualPayerName; const payerDisplayName = isPreviewMessageForParentChatReport ? payerName : actualPayerName; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 64a7d1813255..cb34ffccb0ce 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -354,7 +354,15 @@ const ContextMenuActions: ContextMenuAction[] = [ const modifyExpenseMessage = ModifiedExpenseMessage.getForReportAction(reportID, reportAction); Clipboard.setString(modifyExpenseMessage); } else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { - const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction); + const displayMessage = ReportUtils.getReportPreviewMessage( + ReportUtils.getReport(ReportUtils.getOriginalReportID(reportID, reportAction)), + reportAction, + false, + false, + null, + false, + true, + ); Clipboard.setString(displayMessage); } else if (ReportActionsUtils.isCreatedTaskReportAction(reportAction)) { const taskPreviewMessage = TaskUtils.getTaskCreatedMessage(reportAction); diff --git a/src/pages/home/report/ReportActionItemMessage.tsx b/src/pages/home/report/ReportActionItemMessage.tsx index 0ffb8b9f6964..ad571eb66f10 100644 --- a/src/pages/home/report/ReportActionItemMessage.tsx +++ b/src/pages/home/report/ReportActionItemMessage.tsx @@ -58,7 +58,7 @@ function ReportActionItemMessage({action, displayAsGroup, reportID, style, isHid const originalMessage = action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? action.originalMessage : null; const iouReportID = originalMessage?.IOUReportID; if (iouReportID) { - iouMessage = ReportUtils.getReportPreviewMessage(ReportUtils.getReport(iouReportID), action); + iouMessage = ReportUtils.getReportPreviewMessage(ReportUtils.getReport(iouReportID), action, false, false, null, false, true); } } From b9bbf24c278c4d89b0a4ce96836bb00fc150d896 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 16 Feb 2024 14:52:16 +0700 Subject: [PATCH 2/3] resolve conflict --- src/pages/home/report/ReportActionItemMessage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemMessage.tsx b/src/pages/home/report/ReportActionItemMessage.tsx index ac3238002906..ad571eb66f10 100644 --- a/src/pages/home/report/ReportActionItemMessage.tsx +++ b/src/pages/home/report/ReportActionItemMessage.tsx @@ -58,7 +58,7 @@ function ReportActionItemMessage({action, displayAsGroup, reportID, style, isHid const originalMessage = action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? action.originalMessage : null; const iouReportID = originalMessage?.IOUReportID; if (iouReportID) { - iouMessage = ReportUtils.getIOUReportActionDisplayMessage(action); + iouMessage = ReportUtils.getReportPreviewMessage(ReportUtils.getReport(iouReportID), action, false, false, null, false, true); } } From e145012dc17a52f7924c0b4e578cdb88bc60390a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 16 Feb 2024 16:15:58 +0700 Subject: [PATCH 3/3] remove getIOUReportActionDisplayMessage function --- src/libs/ReportUtils.ts | 57 ------------------------ tests/perf-test/ReportUtils.perf-test.ts | 19 -------- 2 files changed, 76 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4594cae3ec06..38ddfe379d9e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4603,62 +4603,6 @@ function getVisibleMemberIDs(report: OnyxEntry): number[] { return visibleChatMemberAccountIDs; } -/** - * Return iou report action display message - */ -function getIOUReportActionDisplayMessage(reportAction: OnyxEntry): string { - if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU) { - return ''; - } - const originalMessage = reportAction.originalMessage; - const {IOUReportID} = originalMessage; - const iouReport = getReport(IOUReportID); - let translationKey: TranslationPaths; - if (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY) { - // The `REPORT_ACTION_TYPE.PAY` action type is used for both fulfilling existing requests and sending money. To - // differentiate between these two scenarios, we check if the `originalMessage` contains the `IOUDetails` - // property. If it does, it indicates that this is a 'Send money' action. - const {amount, currency} = originalMessage.IOUDetails ?? originalMessage; - const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(amount), currency) ?? ''; - const payerName = isExpenseReport(iouReport) ? getPolicyName(iouReport) : getDisplayNameForParticipant(iouReport?.managerID, true); - - switch (originalMessage.paymentType) { - case CONST.IOU.PAYMENT_TYPE.ELSEWHERE: - translationKey = 'iou.paidElsewhereWithAmount'; - break; - case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: - case CONST.IOU.PAYMENT_TYPE.VBBA: - translationKey = 'iou.paidWithExpensifyWithAmount'; - break; - default: - translationKey = 'iou.payerPaidAmount'; - break; - } - return Localize.translateLocal(translationKey, {amount: formattedAmount, payer: payerName ?? ''}); - } - - const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? ''); - const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : null); - const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency); - const isRequestSettled = isSettled(originalMessage.IOUReportID); - const isApproved = isReportApproved(iouReport); - if (isRequestSettled) { - return Localize.translateLocal('iou.payerSettled', { - amount: formattedAmount, - }); - } - if (isApproved) { - return Localize.translateLocal('iou.approvedAmount', { - amount: formattedAmount, - }); - } - translationKey = ReportActionsUtils.isSplitBillAction(reportAction) ? 'iou.didSplitAmount' : 'iou.requestedAmount'; - return Localize.translateLocal(translationKey, { - formattedAmount, - comment: transactionDetails?.comment ?? '', - }); -} - /** * Checks if a report is a group chat. * @@ -5088,7 +5032,6 @@ export { hasOnlyTransactionsWithPendingRoutes, hasNonReimbursableTransactions, hasMissingSmartscanFields, - getIOUReportActionDisplayMessage, isWaitingForAssigneeToCompleteTask, isGroupChat, isDraftExpenseReport, diff --git a/tests/perf-test/ReportUtils.perf-test.ts b/tests/perf-test/ReportUtils.perf-test.ts index ae3429bb9c01..ee3c54608436 100644 --- a/tests/perf-test/ReportUtils.perf-test.ts +++ b/tests/perf-test/ReportUtils.perf-test.ts @@ -184,23 +184,4 @@ describe('ReportUtils', () => { await waitForBatchedUpdates(); await measureFunction(() => ReportUtils.getTransactionDetails(transaction, 'yyyy-MM-dd')); }); - - test('[ReportUtils] getIOUReportActionDisplayMessage on 1k policies', async () => { - const reportAction = { - ...createRandomReportAction(1), - actionName: CONST.REPORT.ACTIONS.TYPE.IOU, - originalMessage: { - IOUReportID: '1', - IOUTransactionID: '1', - amount: 100, - participantAccountID: 1, - currency: CONST.CURRENCY.USD, - type: CONST.IOU.REPORT_ACTION_TYPE.PAY, - paymentType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY, - }, - }; - - await waitForBatchedUpdates(); - await measureFunction(() => ReportUtils.getIOUReportActionDisplayMessage(reportAction)); - }); });