From 73a3a474bb8d07208d3d46faaa1c2fa90d1fcbbc Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 21:54:56 -0600 Subject: [PATCH 01/15] New copy for auto approve --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index 6d579a2af2df..6151c7b17820 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -911,6 +911,7 @@ const translations = { managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} approved ${amount}`, payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`, payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `paid ${amount}. Add a bank account to receive your payment.`, + automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => `automatically approved ${amount} via workspace rules`, approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`, forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`, rejectedThisReport: 'rejected this report', diff --git a/src/languages/es.ts b/src/languages/es.ts index cb19b091b058..7e2e2aacf259 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -904,6 +904,7 @@ const translations = { managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} aprobó ${amount}`, payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`, payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `pagó ${amount}. Agrega una cuenta bancaria para recibir tu pago.`, + automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => `... update me ... aprobó ${amount}`, approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`, forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`, rejectedThisReport: 'rechazó este informe', From 5567b205ced38a4e4cce8d4f3dde27aea75695d2 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 21:55:20 -0600 Subject: [PATCH 02/15] Refactor & new get auto approve message fn --- src/libs/ReportUtils.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 78ebdd92751e..ac5a67b011c9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3790,7 +3790,7 @@ function getReportName( if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { return getRejectedReportMessage(); } - if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { + if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { return getIOUApprovedMessage(parentReportAction); } @@ -4526,7 +4526,11 @@ function getIOUSubmittedMessage(reportAction: ReportAction) { + return Localize.translateLocal('iou.automaticallyApprovedAmount', {amount: getFormattedAmount(reportAction)}); +} + +function getIOUApprovedMessage(reportAction: ReportAction) { return Localize.translateLocal('iou.approvedAmount', {amount: getFormattedAmount(reportAction)}); } @@ -7161,7 +7165,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry, const amount = TransactionUtils.getAmount(transaction, !isEmptyObject(iouReport) && isExpenseReport(iouReport)) ?? 0; const formattedAmount = CurrencyUtils.convertToDisplayString(amount, TransactionUtils.getCurrency(transaction)) ?? ''; - const isRequestSettled = isSettled(originalMessage?.IOUReportID); + const isRequestSettled = isSettled(IOUReportID); const isApproved = isReportApproved(iouReport); if (isRequestSettled) { return Localize.translateLocal('iou.payerSettled', { @@ -8097,6 +8101,7 @@ export { getGroupChatName, getIOUReportActionDisplayMessage, getIOUReportActionMessage, + getReportAutomaticallyApprovedMessage, getIOUApprovedMessage, getIOUForwardedMessage, getRejectedReportMessage, From d4f8bf1111567e97a303a6b5cc6dbdc024622c98 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 21:55:30 -0600 Subject: [PATCH 03/15] Update copied copy for auto approve --- .../home/report/ContextMenu/ContextMenuActions.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 371df4db2b3c..db5f6b3f9168 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -442,8 +442,14 @@ const ContextMenuActions: ContextMenuAction[] = [ } else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { const displayMessage = ReportUtils.getIOUSubmittedMessage(reportAction); Clipboard.setString(displayMessage); - } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { - const displayMessage = ReportUtils.getIOUApprovedMessage(reportAction); + } else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { + const {automaticAction} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {}; + let displayMessage = ''; + if (automaticAction) { + displayMessage = ReportUtils.getReportAutomaticallyApprovedMessage(reportAction); + } else { + displayMessage = ReportUtils.getIOUApprovedMessage(reportAction); + } Clipboard.setString(displayMessage); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { const displayMessage = ReportUtils.getIOUForwardedMessage(reportAction, reportID); From e6a177de36c9b4fd3026d5298fb158c786621bad Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 21:55:41 -0600 Subject: [PATCH 04/15] Add new automaticAction key for approved action --- src/types/onyx/OriginalMessage.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 4572ac26a449..e36239570d3e 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -431,6 +431,9 @@ type OriginalMessageApproved = { /** Approved expense amount */ amount: number; + /** Was the action created automatically, not by a human */ + automaticAction?: boolean; + /** Currency of the approved expense amount */ currency: string; From 176d9cb392e63d34081830f6deb457803442c2cc Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 21:57:41 -0600 Subject: [PATCH 05/15] Update report action copy for auto approval --- src/pages/home/report/ReportActionItem.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 33664e2a4162..ec2489061e08 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -638,8 +638,17 @@ function ReportActionItem({ } else { children = ; } - } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { - children = ; + } else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { + const wasAutoApproved = ReportActionsUtils.getOriginalMessage(action)?.automaticAction ?? false; + if (wasAutoApproved) { + children = ( + + ${ReportUtils.getReportAutomaticallyApprovedMessage(action)}`} /> + + ); + } else { + children = ; + } } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { From 92e739da0eaadf06b690be9f229d180cd03379c8 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 22:01:17 -0600 Subject: [PATCH 06/15] Update LHN for auto approved --- src/libs/OptionsListUtils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 51db5a693f91..1c7b7dcbb397 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -662,8 +662,13 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); } else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(lastReportAction); - } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) { - lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction); + } else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { + const {automaticAction} = ReportActionUtils.getOriginalMessage(lastReportAction) ?? {}; + if (automaticAction) { + lastMessageTextFromReport = ReportUtils.getReportAutomaticallyApprovedMessage(lastReportAction); + } else { + lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction); + } } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction, report); } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { From 6ade3dff1ca79bd739ad028cae498c18225d5a7b Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 22:12:19 -0600 Subject: [PATCH 07/15] prettify --- src/languages/en.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 6151c7b17820..f2dc459a8235 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -911,7 +911,8 @@ const translations = { managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} approved ${amount}`, payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`, payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `paid ${amount}. Add a bank account to receive your payment.`, - automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => `automatically approved ${amount} via workspace rules`, + automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => + `automatically approved ${amount} via workspace rules`, approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`, forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`, rejectedThisReport: 'rejected this report', From 5c828881137e4758aef45844f237360ff913ca5a Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 22:49:41 -0600 Subject: [PATCH 08/15] Update auto-approve thread report title --- src/libs/ReportUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ac5a67b011c9..c2631fecb4cf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3791,6 +3791,10 @@ function getReportName( return getRejectedReportMessage(); } if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { + const {automaticAction} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; + if (automaticAction) { + return Parser.htmlToText(getReportAutomaticallyApprovedMessage(parentReportAction)); + } return getIOUApprovedMessage(parentReportAction); } From 842cd2facbcf0cfaaa9105936464afb6ac1311f1 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Sun, 29 Sep 2024 23:10:21 -0600 Subject: [PATCH 09/15] Updates for auto submitted --- src/libs/OptionsListUtils.ts | 7 ++++++- src/libs/ReportUtils.ts | 4 ++++ src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1c7b7dcbb397..b8f69ab952d3 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -661,7 +661,12 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails } else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); } else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { - lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(lastReportAction); + const {harvesting} = ReportActionUtils.getOriginalMessage(lastReportAction) ?? {}; + if (harvesting) { + lastMessageTextFromReport = ReportUtils.getReportAutomaticallySubmittedMessage(lastReportAction); + } else { + lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(lastReportAction); + } } else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { const {automaticAction} = ReportActionUtils.getOriginalMessage(lastReportAction) ?? {}; if (automaticAction) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c2631fecb4cf..b5a654f0ba4f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3782,6 +3782,10 @@ function getReportName( const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction); if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { + const {harvesting} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; + if (harvesting) { + return Parser.htmlToText(getReportAutomaticallySubmittedMessage(parentReportAction)); + } return getIOUSubmittedMessage(parentReportAction); } if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index db5f6b3f9168..e2f9749edb65 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -440,7 +440,13 @@ const ContextMenuActions: ContextMenuAction[] = [ } else if (ReportActionsUtils.isRenamedAction(reportAction)) { setClipboardMessage(ReportActionsUtils.getRenamedAction(reportAction)); } else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED)) { - const displayMessage = ReportUtils.getIOUSubmittedMessage(reportAction); + const {harvesting} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {}; + let displayMessage = ''; + if (harvesting) { + displayMessage = ReportUtils.getReportAutomaticallySubmittedMessage(reportAction); + } else { + displayMessage = ReportUtils.getIOUSubmittedMessage(reportAction); + } Clipboard.setString(displayMessage); } else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { const {automaticAction} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {}; From beb72d7b47a0d713fcda6a267e3478db94a76ba6 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 30 Sep 2024 14:03:02 -0600 Subject: [PATCH 10/15] Add translations for automatic forward --- src/languages/en.ts | 2 ++ src/languages/es.ts | 1 + src/types/onyx/OriginalMessage.ts | 3 +++ 3 files changed, 6 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index f2dc459a8235..fcc485a12849 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -914,6 +914,8 @@ const translations = { automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => `automatically approved ${amount} via workspace rules`, approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`, + automaticallyForwardedAmount: ({amount}: ForwardedAmountParams) => + `automatically approved ${amount} via workspace rules`, forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`, rejectedThisReport: 'rejected this report', waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} adds a bank account.`, diff --git a/src/languages/es.ts b/src/languages/es.ts index 7e2e2aacf259..be960a04f4a4 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -906,6 +906,7 @@ const translations = { payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `pagó ${amount}. Agrega una cuenta bancaria para recibir tu pago.`, automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => `... update me ... aprobó ${amount}`, approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`, + automaticallyForwardedAmount: ({amount}: ForwardedAmountParams) => `... update me ... aprobó ${amount}`, forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`, rejectedThisReport: 'rechazó este informe', waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`, diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index e36239570d3e..871b30f3a5f9 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -446,6 +446,9 @@ type OriginalMessageForwarded = { /** Forwarded expense amount */ amount: number; + /** Was the action created automatically, not by a human */ + automaticAction?: boolean; + /** Currency of the forwarded expense amount */ currency: string; From 22fad900e812f3b6c67b83595dfd2bce7afa3d93 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 30 Sep 2024 14:17:56 -0600 Subject: [PATCH 11/15] Render auto forwarded action and LHN with new copy --- src/libs/OptionsListUtils.ts | 9 +++++++-- src/pages/home/report/ReportActionItem.tsx | 13 +++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b8f69ab952d3..ab3ee202ce48 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -674,8 +674,13 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails } else { lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction); } - } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { - lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction, report); + } else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) { + const {automaticAction} = ReportActionUtils.getOriginalMessage(lastReportAction) ?? {}; + if (automaticAction) { + lastMessageTextFromReport = ReportUtils.getReportAutomaticallyForwardedMessage(lastReportAction, reportID); + } else { + lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction, report); + } } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { lastMessageTextFromReport = ReportUtils.getRejectedReportMessage(); } else if (ReportActionUtils.isActionableAddPaymentCard(lastReportAction)) { diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index ec2489061e08..dc1a09842bfb 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -649,8 +649,17 @@ function ReportActionItem({ } else { children = ; } - } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { - children = ; + } else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) { + const wasAutoForwarded = ReportActionsUtils.getOriginalMessage(action)?.automaticAction ?? false; + if (wasAutoForwarded) { + children = ( + + ${ReportUtils.getReportAutomaticallyForwardedMessage(action, reportID)}`} /> + + ); + } else { + children = ; + } } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) { From c2a3b4c7515f4a99db9991417678ca592a09f3d6 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 30 Sep 2024 14:18:13 -0600 Subject: [PATCH 12/15] Update auto-forwarded copy for threads and copy text --- src/libs/ReportUtils.ts | 28 +++++++++++++++++-- .../report/ContextMenu/ContextMenuActions.tsx | 10 +++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b5a654f0ba4f..9ba1e4467d9e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3788,7 +3788,11 @@ function getReportName( } return getIOUSubmittedMessage(parentReportAction); } - if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { + if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) { + const {automaticAction} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; + if (automaticAction) { + return Parser.htmlToText(getReportAutomaticallyForwardedMessage(parentReportAction, reportID)); + } return getIOUForwardedMessage(parentReportAction, report); } if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { @@ -4546,7 +4550,26 @@ function getIOUApprovedMessage(reportAction: ReportAction | string) { +function getReportAutomaticallyForwardedMessage(reportAction: ReportAction, reportOrID: OnyxInputOrEntry | string) { + const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID; + const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU; + let formattedAmount; + + // Older FORWARDED action might not have the amount stored in the original message, we'll fallback to getting the amount from the report instead. + if (originalMessage?.amount) { + formattedAmount = getFormattedAmount(reportAction); + } else { + formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(expenseReport).totalDisplaySpend, expenseReport?.currency); + } + + return Localize.translateLocal('iou.automaticallyForwardedAmount', {amount: formattedAmount}); +} + +/** + * We pass the reportID as older FORWARDED actions do not have the amount & currency stored in the message + * so we retrieve the amount from the report instead + */ +function getIOUForwardedMessage(reportAction: ReportAction, reportOrID: OnyxInputOrEntry | string) { const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID; const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU; let formattedAmount; @@ -8111,6 +8134,7 @@ export { getIOUReportActionMessage, getReportAutomaticallyApprovedMessage, getIOUApprovedMessage, + getReportAutomaticallyForwardedMessage, getIOUForwardedMessage, getRejectedReportMessage, getWorkspaceNameUpdatedMessage, diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index e2f9749edb65..4d22ee9c40ba 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -457,8 +457,14 @@ const ContextMenuActions: ContextMenuAction[] = [ displayMessage = ReportUtils.getIOUApprovedMessage(reportAction); } Clipboard.setString(displayMessage); - } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) { - const displayMessage = ReportUtils.getIOUForwardedMessage(reportAction, reportID); + } else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) { + const {automaticAction} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {}; + let displayMessage = ''; + if (automaticAction) { + displayMessage = ReportUtils.getReportAutomaticallyForwardedMessage(reportAction, reportID); + } else { + displayMessage = ReportUtils.getIOUForwardedMessage(reportAction, reportID); + } Clipboard.setString(displayMessage); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) { const displayMessage = ReportUtils.getRejectedReportMessage(); From 82ef5bbecda7c2f1aa34ce6974ceae12c3e50020 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 30 Sep 2024 14:27:36 -0600 Subject: [PATCH 13/15] Update spanish copy --- src/languages/es.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index be960a04f4a4..b92a2f96bcb4 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -904,9 +904,11 @@ const translations = { managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} aprobó ${amount}`, payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`, payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `pagó ${amount}. Agrega una cuenta bancaria para recibir tu pago.`, - automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => `... update me ... aprobó ${amount}`, + automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) => + `aprobado automáticamente ${amount} según las reglas del espacio de trabajo`, approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`, - automaticallyForwardedAmount: ({amount}: ForwardedAmountParams) => `... update me ... aprobó ${amount}`, + automaticallyForwardedAmount: ({amount}: ForwardedAmountParams) => + `aprobado automáticamente ${amount} según las reglas del espacio de trabajo`, forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`, rejectedThisReport: 'rechazó este informe', waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`, From 30be12b9dfe623e4d089231edac267655133ce48 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 3 Oct 2024 16:50:13 -0600 Subject: [PATCH 14/15] Add thread from manual submit action test --- tests/unit/ReportUtilsTest.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 091a8cafa37e..a19baa0dfc80 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -270,6 +270,30 @@ describe('ReportUtils', () => { }); }); }); + + describe('ParentReportAction is', () => { + test('Manually Submitted Report Action', () => { + const threadOfSubmittedReportAction = { + ...LHNTestUtils.getFakeReport(), + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + parentReportID: '101', + policyID: policy.id, + }; + const submittedParentReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, + originalMessage: { + amount: 169, + currency: 'USD', + }, + } as ReportAction; + + expect( + ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction), + ).toBe('submitted $1.69'); + }); + }); }); describe('requiresAttentionFromCurrentUser', () => { From 559b9d8334fd0068a1cbcc263df74c4683c367dd Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 4 Oct 2024 09:28:22 -0600 Subject: [PATCH 15/15] Prettier style fix --- tests/unit/ReportUtilsTest.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index a19baa0dfc80..e4eee7241d80 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -289,9 +289,7 @@ describe('ReportUtils', () => { }, } as ReportAction; - expect( - ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction), - ).toBe('submitted $1.69'); + expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('submitted $1.69'); }); }); });