From d2c07a2ad45bc76302b4017c5f49056200ec2196 Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 8 Jun 2023 16:28:01 +0700 Subject: [PATCH 01/27] Display displayName instead of primaryLogin in report preview --- src/components/ReportActionItem/ReportPreview.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index e7ba7fde70d5..22aa7b6e509a 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -117,12 +117,12 @@ const ReportPreview = (props) => { {props.iouReport.hasOutstandingIOU ? ( - {lodashGet(message, 'html', props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount}))} + {props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount})} ) : ( - {lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))} + {props.translate('iou.payerSettled', {amount: reportAmount})} {!props.iouReport.hasOutstandingIOU && ( From 5e1b4c79ba5ace0852e087fdc55e42a944127c49 Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 8 Jun 2023 17:49:07 +0700 Subject: [PATCH 02/27] Show report preview action in LHN --- src/libs/ReportActionsUtils.js | 9 +++++++++ src/libs/ReportUtils.js | 6 ++++-- src/libs/SidebarUtils.js | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index c255760f5d87..7d44f89cc9aa 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -56,6 +56,14 @@ function isMoneyRequestAction(reportAction) { return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.IOU; } +/** + * @param {Object} reportAction + * @returns {Boolean} + */ +function isReportReviewAction(reportAction) { + return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; +} + /** * @param {Object} reportAction * @returns {Boolean} @@ -423,4 +431,5 @@ export { isTransactionThread, getFormattedAmount, isSentMoneyReportAction, + isReportReviewAction, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 790f827ae989..e3abd7b36dff 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -970,11 +970,12 @@ function getPolicyExpenseChatName(report) { * Get the title for a IOU or expense chat which will be showing the payer and the amount * * @param {Object} report + * @param {Boolean} [shouldUseDisplayNameShortForm] * @returns {String} */ -function getMoneyRequestReportName(report) { +function getMoneyRequestReportName(report, shouldUseDisplayNameShortForm = false) { const formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(report), report.currency); - const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail); + const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail, shouldUseDisplayNameShortForm); return Localize.translateLocal(report.hasOutstandingIOU ? 'iou.payerOwesAmount' : 'iou.payerPaidAmount', {payer: payerName, amount: formattedAmount}); } @@ -2241,4 +2242,5 @@ export { getMoneyRequestAction, getBankAccountRoute, getParentReport, + getMoneyRequestReportName, }; diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 87e8b97d0bd0..fa8333d86941 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -269,6 +269,9 @@ function getOptionData(reportID) { let lastMessageTextFromReport = ''; if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; + } else if (ReportActionsUtils.isReportReviewAction(lastReportActions[report.reportID])) { + const iouReport = ReportUtils.getReport(report.iouReportID); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportName(iouReport, true); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; } From 4338186b6503ea64700aaee32dccfa560d3af45e Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 8 Jun 2023 17:49:35 +0700 Subject: [PATCH 03/27] Refactor code using existing util to display money request message --- .../ReportActionItem/ReportPreview.js | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 22aa7b6e509a..2c39261deabf 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -95,11 +95,10 @@ const defaultProps = { }; const ReportPreview = (props) => { - const reportAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.iouReport), props.iouReport.currency); const managerEmail = props.iouReport.managerEmail || ''; - const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerEmail, true); const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); + const displayingMessage = ReportUtils.getMoneyRequestReportName(props.iouReport, true) return ( {_.map(props.action.message, (message, index) => ( @@ -115,26 +114,20 @@ const ReportPreview = (props) => { focusable > - {props.iouReport.hasOutstandingIOU ? ( + - {props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount})} + {displayingMessage} - ) : ( - - - {props.translate('iou.payerSettled', {amount: reportAmount})} - - {!props.iouReport.hasOutstandingIOU && ( - - - - )} - - )} + {!props.iouReport.hasOutstandingIOU && ( + + + + )} + Date: Thu, 8 Jun 2023 18:02:12 +0700 Subject: [PATCH 04/27] Fix linter --- src/components/ReportActionItem/ReportPreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 2c39261deabf..ba99e89a3526 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -16,7 +16,6 @@ import ControlSelection from '../../libs/ControlSelection'; import * as DeviceCapabilities from '../../libs/DeviceCapabilities'; import {showContextMenuForReport} from '../ShowContextMenuContext'; import * as StyleUtils from '../../styles/StyleUtils'; -import * as CurrencyUtils from '../../libs/CurrencyUtils'; import * as ReportUtils from '../../libs/ReportUtils'; import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; From 3b8bb486e571d2ae49668577d4a3d06e90340c4f Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 8 Jun 2023 18:11:37 +0700 Subject: [PATCH 05/27] Fix linter --- src/components/ReportActionItem/ReportPreview.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index ba99e89a3526..267fce89d16c 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -97,7 +97,7 @@ const ReportPreview = (props) => { const managerEmail = props.iouReport.managerEmail || ''; const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); - const displayingMessage = ReportUtils.getMoneyRequestReportName(props.iouReport, true) + const displayingMessage = ReportUtils.getMoneyRequestReportName(props.iouReport, true); return ( {_.map(props.action.message, (message, index) => ( @@ -114,9 +114,7 @@ const ReportPreview = (props) => { > - - {displayingMessage} - + {displayingMessage} {!props.iouReport.hasOutstandingIOU && ( Date: Wed, 14 Jun 2023 18:35:18 +0700 Subject: [PATCH 06/27] Add a new utils to get money request message --- .../ReportActionItem/ReportPreview.js | 2 +- src/libs/ReportUtils.js | 22 ++++++++++++++++--- src/libs/SidebarUtils.js | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 267fce89d16c..fab462ed02cd 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -97,7 +97,7 @@ const ReportPreview = (props) => { const managerEmail = props.iouReport.managerEmail || ''; const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); - const displayingMessage = ReportUtils.getMoneyRequestReportName(props.iouReport, true); + const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport); return ( {_.map(props.action.message, (message, index) => ( diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 12e461e3aaf8..93694eb4041e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -939,12 +939,11 @@ function getPolicyExpenseChatName(report) { * Get the title for a IOU or expense chat which will be showing the payer and the amount * * @param {Object} report - * @param {Boolean} [shouldUseDisplayNameShortForm] * @returns {String} */ -function getMoneyRequestReportName(report, shouldUseDisplayNameShortForm = false) { +function getMoneyRequestReportName(report) { const formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(report), report.currency); - const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail, shouldUseDisplayNameShortForm); + const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail); return Localize.translateLocal(report.hasOutstandingIOU ? 'iou.payerOwesAmount' : 'iou.payerPaidAmount', {payer: payerName, amount: formattedAmount}); } @@ -962,6 +961,22 @@ function getTransactionReportName(reportAction) { }); } +/** + * Get money request message for a IOU report + * + * @param {Object} iouReport + * @returns {String} + */ +function getMoneyRequestReportActionMessage(iouReport) { + const formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(iouReport), iouReport.currency); + const payerName = isExpenseReport(iouReport) ? getPolicyName(iouReport) : getDisplayNameForParticipant(iouReport.managerEmail, true); + + if (iouReport.hasOutstandingIOU) { + return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); + } + return Localize.translateLocal('iou.payerSettled', {amount: formattedAmount}); +} + /** * Get the title for a report. * @@ -2268,4 +2283,5 @@ export { getBankAccountRoute, getParentReport, getMoneyRequestReportName, + getMoneyRequestReportActionMessage, }; diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index fa8333d86941..3aaa070db338 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -271,7 +271,7 @@ function getOptionData(reportID) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else if (ReportActionsUtils.isReportReviewAction(lastReportActions[report.reportID])) { const iouReport = ReportUtils.getReport(report.iouReportID); - lastMessageTextFromReport = ReportUtils.getMoneyRequestReportName(iouReport, true); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; } From 0da6a76e8ef2831183ae33e1f1729a4b1fd7357a Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 14 Jun 2023 18:36:43 +0700 Subject: [PATCH 07/27] remove redundant export --- src/libs/ReportUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 93694eb4041e..43d1506c5ef3 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2282,6 +2282,5 @@ export { getMoneyRequestAction, getBankAccountRoute, getParentReport, - getMoneyRequestReportName, getMoneyRequestReportActionMessage, }; From 644d71f890ffc63d203121a0886b7df43e43b08a Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 14 Jun 2023 21:14:01 +0700 Subject: [PATCH 08/27] Fix settled message is 0 amount in LHN --- src/libs/ReportActionsUtils.js | 11 +++++++++++ src/libs/SidebarUtils.js | 3 ++- src/pages/home/report/ReportActionItem.js | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 91073e248400..c5c540d124ad 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -425,6 +425,16 @@ function getReportPreviewAction(chatReportID, iouReportID) { ); } +/** + * Get the iouReportID for a given report action. + * + * @param {*} reportAction + * @returns {String} + */ +function getIouReportID(reportAction) { + return lodashGet(reportAction, 'originalMessage.linkedReportID', ''); +} + function isCreatedTaskReportAction(reportAction) { return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID'); } @@ -452,4 +462,5 @@ export { getFormattedAmount, isSentMoneyReportAction, isReportReviewAction, + getIouReportID, }; diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 3aaa070db338..2585688131b0 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -270,7 +270,8 @@ function getOptionData(reportID) { if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else if (ReportActionsUtils.isReportReviewAction(lastReportActions[report.reportID])) { - const iouReport = ReportUtils.getReport(report.iouReportID); + const iouReportID = ReportActionsUtils.getIouReportID(lastReportActions[report.reportID]); + const iouReport = ReportUtils.getReport(iouReportID); lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index c0c335ca5efe..51dd30a36940 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -227,7 +227,7 @@ function ReportActionItem(props) { } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) { children = ( Date: Wed, 14 Jun 2023 21:58:22 +0700 Subject: [PATCH 09/27] Fix amount is 0 after sign in --- .../ReportActionItem/ReportPreview.js | 2 +- src/libs/ReportUtils.js | 27 ++++++++++++++----- src/libs/SidebarUtils.js | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 33fd81dbe987..81b18caf99fb 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -97,7 +97,7 @@ function ReportPreview(props) { const managerEmail = props.iouReport.managerEmail || ''; const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); - const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport); + const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport, props.action) return ( {_.map(props.action.message, (message, index) => ( diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 43d1506c5ef3..ce87c625826e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -964,14 +964,29 @@ function getTransactionReportName(reportAction) { /** * Get money request message for a IOU report * - * @param {Object} iouReport + * @param {Object} report + * @param {Object} reportAction * @returns {String} */ -function getMoneyRequestReportActionMessage(iouReport) { - const formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestTotal(iouReport), iouReport.currency); - const payerName = isExpenseReport(iouReport) ? getPolicyName(iouReport) : getDisplayNameForParticipant(iouReport.managerEmail, true); - - if (iouReport.hasOutstandingIOU) { +function getMoneyRequestReportActionMessage(report, reportAction) { + let formattedAmount = null; + let isHavingOustandingIOU = null; + const totalAmount = getMoneyRequestTotal(report); + const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail, true); + + if (totalAmount > 0) { + formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); + isHavingOustandingIOU = report.hasOutstandingIOU; + } else { + const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); + + // The totalAmount is 0 after sign in/sign up because OpenApp API won't return iouReports if it's paid, so we need to retrieve it from the reportActionMessage + // reportActionMessage is in the format of either "payer@mail.com paid $1.00" or "paid $1.00" + formattedAmount = _.last(reportActionMessage.split(' ')); + isHavingOustandingIOU = Boolean(reportActionMessage.match(/ paid /)); + } + + if (isHavingOustandingIOU) { return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } return Localize.translateLocal('iou.payerSettled', {amount: formattedAmount}); diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 2585688131b0..bf1405e34f83 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -272,7 +272,7 @@ function getOptionData(reportID) { } else if (ReportActionsUtils.isReportReviewAction(lastReportActions[report.reportID])) { const iouReportID = ReportActionsUtils.getIouReportID(lastReportActions[report.reportID]); const iouReport = ReportUtils.getReport(iouReportID); - lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportActions[report.reportID]); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; } From e3291733f7e85099ed85f13030992f8e983918be Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 14 Jun 2023 22:11:04 +0700 Subject: [PATCH 10/27] Fix linter --- src/components/ReportActionItem/ReportPreview.js | 2 +- src/libs/ReportActionsUtils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 81b18caf99fb..666ec99287c6 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -97,7 +97,7 @@ function ReportPreview(props) { const managerEmail = props.iouReport.managerEmail || ''; const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); - const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport, props.action) + const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport, props.action); return ( {_.map(props.action.message, (message, index) => ( diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index c5c540d124ad..357147371345 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -427,7 +427,7 @@ function getReportPreviewAction(chatReportID, iouReportID) { /** * Get the iouReportID for a given report action. - * + * * @param {*} reportAction * @returns {String} */ From caa45ea3d8078ef22f96f9411f0862685b442e6f Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 15 Jun 2023 10:44:44 +0700 Subject: [PATCH 11/27] Fix checking isHavingOustandingIOU --- src/libs/ReportUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ce87c625826e..c8c80b96d842 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -980,10 +980,10 @@ function getMoneyRequestReportActionMessage(report, reportAction) { } else { const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); - // The totalAmount is 0 after sign in/sign up because OpenApp API won't return iouReports if it's paid, so we need to retrieve it from the reportActionMessage - // reportActionMessage is in the format of either "payer@mail.com paid $1.00" or "paid $1.00" + // The totalAmount is 0 after Sign in because OpenApp API won't return iouReports if it's paid, so we need to retrieve it from the reportActionMessage + // reportActionMessage is in the format of either "payer@mail.com owes $1.00" or "paid $1.00" formattedAmount = _.last(reportActionMessage.split(' ')); - isHavingOustandingIOU = Boolean(reportActionMessage.match(/ paid /)); + isHavingOustandingIOU = Boolean(reportActionMessage.match(/ owes /)); } if (isHavingOustandingIOU) { From b57b89795ff87bc354fda16c1a5af1b46787dfbb Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 15 Jun 2023 10:47:49 +0700 Subject: [PATCH 12/27] Correct the method name --- src/libs/ReportActionsUtils.js | 8 ++++---- src/libs/SidebarUtils.js | 4 ++-- src/pages/home/report/ReportActionItem.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 357147371345..164d6ea7d32e 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -60,7 +60,7 @@ function isMoneyRequestAction(reportAction) { * @param {Object} reportAction * @returns {Boolean} */ -function isReportReviewAction(reportAction) { +function isReportPreviewAction(reportAction) { return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; } @@ -431,7 +431,7 @@ function getReportPreviewAction(chatReportID, iouReportID) { * @param {*} reportAction * @returns {String} */ -function getIouReportID(reportAction) { +function getIOUReportID(reportAction) { return lodashGet(reportAction, 'originalMessage.linkedReportID', ''); } @@ -461,6 +461,6 @@ export { isTransactionThread, getFormattedAmount, isSentMoneyReportAction, - isReportReviewAction, - getIouReportID, + isReportPreviewAction, + getIOUReportID, }; diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index bf1405e34f83..d8acdfbdb597 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -269,8 +269,8 @@ function getOptionData(reportID) { let lastMessageTextFromReport = ''; if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; - } else if (ReportActionsUtils.isReportReviewAction(lastReportActions[report.reportID])) { - const iouReportID = ReportActionsUtils.getIouReportID(lastReportActions[report.reportID]); + } else if (ReportActionsUtils.isReportPreviewAction(lastReportActions[report.reportID])) { + const iouReportID = ReportActionsUtils.getIOUReportID(lastReportActions[report.reportID]); const iouReport = ReportUtils.getReport(iouReportID); lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportActions[report.reportID]); } else { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 1d2a4851fa0c..74d5d72f5f19 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -231,7 +231,7 @@ function ReportActionItem(props) { } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) { children = ( Date: Thu, 15 Jun 2023 10:55:31 +0700 Subject: [PATCH 13/27] Refactor as feedbacks --- src/libs/SidebarUtils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index d8acdfbdb597..37d4c0016602 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -262,6 +262,7 @@ function getOptionData(reportID) { const login = Str.removeSMSDomain(lodashGet(personalDetail, 'login', '')); const formattedLogin = Str.isSMSLogin(login) ? LocalePhoneNumber.formatPhoneNumber(login) : login; + const lastReportAction = lastReportActions[report.reportID]; // We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade. const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((participantPersonalDetailList || []).slice(0, 10), hasMultipleParticipants); @@ -269,10 +270,9 @@ function getOptionData(reportID) { let lastMessageTextFromReport = ''; if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; - } else if (ReportActionsUtils.isReportPreviewAction(lastReportActions[report.reportID])) { - const iouReportID = ReportActionsUtils.getIOUReportID(lastReportActions[report.reportID]); - const iouReport = ReportUtils.getReport(iouReportID); - lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportActions[report.reportID]); + } else if (ReportActionsUtils.isReportPreviewAction(lastReportAction)) { + const iouReport = ReportUtils.getReport(ReportActionsUtils.getIOUReportID(lastReportAction)); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportAction); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; } From f4e1390963e174204b7531aa89251933296a83df Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 15 Jun 2023 23:52:56 +0700 Subject: [PATCH 14/27] Update variable name --- src/libs/ReportActionsUtils.js | 2 +- src/libs/ReportUtils.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 164d6ea7d32e..b3faa0185795 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -428,7 +428,7 @@ function getReportPreviewAction(chatReportID, iouReportID) { /** * Get the iouReportID for a given report action. * - * @param {*} reportAction + * @param {Object} reportAction * @returns {String} */ function getIOUReportID(reportAction) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index c8c80b96d842..0540b41dbe19 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -970,23 +970,23 @@ function getTransactionReportName(reportAction) { */ function getMoneyRequestReportActionMessage(report, reportAction) { let formattedAmount = null; - let isHavingOustandingIOU = null; + let reportHasOutstandingIOU = null; const totalAmount = getMoneyRequestTotal(report); const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail, true); if (totalAmount > 0) { formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); - isHavingOustandingIOU = report.hasOutstandingIOU; + reportHasOutstandingIOU = report.hasOutstandingIOU; } else { const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); // The totalAmount is 0 after Sign in because OpenApp API won't return iouReports if it's paid, so we need to retrieve it from the reportActionMessage // reportActionMessage is in the format of either "payer@mail.com owes $1.00" or "paid $1.00" formattedAmount = _.last(reportActionMessage.split(' ')); - isHavingOustandingIOU = Boolean(reportActionMessage.match(/ owes /)); + reportHasOutstandingIOU = Boolean(reportActionMessage.match(/ owes /)); } - if (isHavingOustandingIOU) { + if (reportHasOutstandingIOU) { return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } return Localize.translateLocal('iou.payerSettled', {amount: formattedAmount}); From 5bd7268f59c181f0d9fe4f7b8e688e7677e92d67 Mon Sep 17 00:00:00 2001 From: Vinh Hoang Date: Fri, 16 Jun 2023 17:00:05 +0700 Subject: [PATCH 15/27] Correct typo Co-authored-by: Carlos Martins --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0d00b0d4c3bf..e02a8437e46e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -979,7 +979,7 @@ function getTransactionReportName(reportAction) { } /** - * Get money request message for a IOU report + * Get money request message for an IOU report * * @param {Object} report * @param {Object} reportAction From 20b7a1ae73c25487d1258484cca83e4283fb7a68 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 21 Jun 2023 11:08:12 +0700 Subject: [PATCH 16/27] Show report review action message in LHN --- src/libs/OptionsListUtils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index af2309c3eda8..cb281149c119 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -375,9 +375,14 @@ function getAllReportErrors(report, reportActions) { * @returns {String} */ function getLastMessageTextForReport(report) { + const lastReportAction = lastReportActions[report.reportID]; let lastMessageTextFromReport = ''; + if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; + } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { + const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportID(lastReportAction)); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportAction); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; From e59d39fe3b4456ce1cded965ef64e6621d55ad46 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 21 Jun 2023 11:11:32 +0700 Subject: [PATCH 17/27] Remove map action.message --- .../ReportActionItem/ReportPreview.js | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index d1bbae50fe8d..53e72b6988a5 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -100,28 +100,25 @@ function ReportPreview(props) { const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport, props.action); return ( - {_.map(props.action.message, (message, index) => ( - { - Navigation.navigate(ROUTES.getReportRoute(props.iouReportID)); - }} - onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} - onPressOut={() => ControlSelection.unblock()} - onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)} - style={[styles.flexRow, styles.justifyContentBetween]} - accessibilityRole="button" - accessibilityLabel={props.translate('iou.viewDetails')} - > - - {displayingMessage} - - - - ))} + { + Navigation.navigate(ROUTES.getReportRoute(props.iouReportID)); + }} + onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} + onPressOut={() => ControlSelection.unblock()} + onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)} + style={[styles.flexRow, styles.justifyContentBetween]} + accessibilityRole="button" + accessibilityLabel={props.translate('iou.viewDetails')} + > + + {displayingMessage} + + + {isCurrentUserManager && !ReportUtils.isSettled(props.iouReport.reportID) && ( Date: Wed, 21 Jun 2023 11:14:19 +0700 Subject: [PATCH 18/27] Rename method to scope it only for reportAction preview --- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportActionsUtils.js | 4 ++-- src/pages/home/report/ReportActionItem.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index cb281149c119..e39ec33da68b 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -381,7 +381,7 @@ function getLastMessageTextForReport(report) { if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { - const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportID(lastReportAction)); + const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportAction); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index d86123f48989..1b4536a348bc 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -435,7 +435,7 @@ function getReportPreviewAction(chatReportID, iouReportID) { * @param {Object} reportAction * @returns {String} */ -function getIOUReportID(reportAction) { +function getIOUReportIDFromReportActionPreview(reportAction) { return lodashGet(reportAction, 'originalMessage.linkedReportID', ''); } @@ -480,7 +480,7 @@ export { getFormattedAmount, isSentMoneyReportAction, isReportPreviewAction, - getIOUReportID, + getIOUReportIDFromReportActionPreview, isMessageDeleted, isWhisperAction, }; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index ab94be13a0dd..f5818f6fc91f 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -248,7 +248,7 @@ function ReportActionItem(props) { } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) { children = ( Date: Wed, 21 Jun 2023 14:14:38 +0700 Subject: [PATCH 19/27] Fix eslint --- src/components/ReportActionItem/ReportPreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 53e72b6988a5..99ba312281a5 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -3,7 +3,6 @@ import {View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import lodashGet from 'lodash/get'; -import _ from 'underscore'; import Text from '../Text'; import Icon from '../Icon'; import * as Expensicons from '../Icon/Expensicons'; From a5d0633b1681110137cdf904dacd277a7ef29b30 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 21 Jun 2023 14:14:54 +0700 Subject: [PATCH 20/27] Fix get payerName --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 295f50fb24d8..82643b36c28d 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -997,7 +997,7 @@ function getMoneyRequestReportActionMessage(report, reportAction) { let formattedAmount = null; let reportHasOutstandingIOU = null; const totalAmount = getMoneyRequestTotal(report); - const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail, true); + const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerID, true); if (totalAmount > 0) { formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); From e0189135afd00d4e1c87efbfe4a2b101bf421728 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 21 Jun 2023 14:15:28 +0700 Subject: [PATCH 21/27] Use last visible action instead of last action --- src/libs/OptionsListUtils.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e39ec33da68b..89a9bba93212 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -375,14 +375,15 @@ function getAllReportErrors(report, reportActions) { * @returns {String} */ function getLastMessageTextForReport(report) { - const lastReportAction = lastReportActions[report.reportID]; + const lastVisibleReportAction = ReportActionUtils.getLastVisibleAction(report.reportID); + let lastMessageTextFromReport = ''; if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; - } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { - const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); - lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportAction); + } else if (ReportActionUtils.isReportPreviewAction(lastVisibleReportAction)) { + const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastVisibleReportAction)); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastVisibleReportAction); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; From 894253613fde3bd6486a18e132db95414a604eaf Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 21 Jun 2023 14:17:04 +0700 Subject: [PATCH 22/27] Remove redundant empty line --- src/libs/OptionsListUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 89a9bba93212..fe3444590ef0 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -376,7 +376,6 @@ function getAllReportErrors(report, reportActions) { */ function getLastMessageTextForReport(report) { const lastVisibleReportAction = ReportActionUtils.getLastVisibleAction(report.reportID); - let lastMessageTextFromReport = ''; if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { From ba57e73e436b2b3e5add4442d60d698349767b49 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 21 Jun 2023 15:35:41 +0700 Subject: [PATCH 23/27] Revert back to lastReportAction because new reportActionView is optimistic empty string --- src/libs/OptionsListUtils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index fe3444590ef0..e39ec33da68b 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -375,14 +375,14 @@ function getAllReportErrors(report, reportActions) { * @returns {String} */ function getLastMessageTextForReport(report) { - const lastVisibleReportAction = ReportActionUtils.getLastVisibleAction(report.reportID); + const lastReportAction = lastReportActions[report.reportID]; let lastMessageTextFromReport = ''; if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; - } else if (ReportActionUtils.isReportPreviewAction(lastVisibleReportAction)) { - const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastVisibleReportAction)); - lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastVisibleReportAction); + } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { + const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); + lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportAction); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; From 8142f02d554231e9549bbbd3465f6ab508f2ee2b Mon Sep 17 00:00:00 2001 From: VH Date: Mon, 26 Jun 2023 01:03:17 +0700 Subject: [PATCH 24/27] If iouReport is not found locally then use BE message other parse BE message then localize --- src/languages/en.js | 3 ++- src/languages/es.js | 3 ++- src/libs/ReportUtils.js | 30 +++++++++++++----------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index 192d9954e5ff..50ee6be7e3aa 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -359,7 +359,8 @@ export default { amountEach: ({amount}) => `${amount} each`, payerOwesAmount: ({payer, amount}) => `${payer} owes ${amount}`, payerPaidAmount: ({payer, amount}) => `${payer} paid ${amount}`, - payerSettled: ({amount}) => `paid ${amount}`, + settledElsewhereWithAmount: ({amount}) => `paid ${amount} elsewhere`, + settledPaypalMeWithAmount: ({amount}) => `paid ${amount} using Paypal.me`, noReimbursableExpenses: 'This report has an invalid amount', pendingConversionMessage: "Total will update when you're back online", threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`, diff --git a/src/languages/es.js b/src/languages/es.js index d54fa5110117..27be7afc4f96 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -358,7 +358,8 @@ export default { amountEach: ({amount}) => `${amount} cada uno`, payerOwesAmount: ({payer, amount}) => `${payer} debe ${amount}`, payerPaidAmount: ({payer, amount}) => `${payer} pagó ${amount}`, - payerSettled: ({amount}) => `pagó ${amount}`, + settledElsewhereWithAmount: ({amount}) => `paid ${amount} de otra forma`, + settledPaypalMeWithAmount: ({amount}) => `paid ${amount} con PayPal.me`, noReimbursableExpenses: 'El monto de este informe es inválido', pendingConversionMessage: 'El total se actualizará cuando estés online', threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 82643b36c28d..eb2280033873 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -994,27 +994,23 @@ function getTransactionReportName(reportAction) { * @returns {String} */ function getMoneyRequestReportActionMessage(report, reportAction) { - let formattedAmount = null; - let reportHasOutstandingIOU = null; + if (_.isEmpty(report) || !report.reportID) { + // The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled + // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE + return lodashGet(reportAction, 'message[0].html', ''); + } + const totalAmount = getMoneyRequestTotal(report); const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerID, true); + const formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); - if (totalAmount > 0) { - formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); - reportHasOutstandingIOU = report.hasOutstandingIOU; - } else { - const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); - - // The totalAmount is 0 after Sign in because OpenApp API won't return iouReports if it's paid, so we need to retrieve it from the reportActionMessage - // reportActionMessage is in the format of either "payer@mail.com owes $1.00" or "paid $1.00" - formattedAmount = _.last(reportActionMessage.split(' ')); - reportHasOutstandingIOU = Boolean(reportActionMessage.match(/ owes /)); - } - - if (reportHasOutstandingIOU) { - return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); + if (isSettled(report.reportID)) { + // A settled message is in the format of either "paid $1.00 elsewhere" or "paid $1.00 using Paypal.me" + const isSettledPaypalMe = Boolean(report.lastMessageText.match(/ Paypal.me$/)); + const translatePhraseKey = isSettledPaypalMe ? 'iou.settledPaypalMeWithAmount' : 'iou.settledElsewhereWithAmount'; + return Localize.translateLocal(translatePhraseKey, {amount: formattedAmount}); } - return Localize.translateLocal('iou.payerSettled', {amount: formattedAmount}); + return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); } /** From d1e4aae3f6453a2bfd8669b692208a9f9dd2af04 Mon Sep 17 00:00:00 2001 From: VH Date: Mon, 26 Jun 2023 06:42:17 +0700 Subject: [PATCH 25/27] Use report action message instead report last message text --- src/libs/ReportUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index eb2280033873..eb3384d525ee 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -994,10 +994,12 @@ function getTransactionReportName(reportAction) { * @returns {String} */ function getMoneyRequestReportActionMessage(report, reportAction) { + const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); + if (_.isEmpty(report) || !report.reportID) { // The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE - return lodashGet(reportAction, 'message[0].html', ''); + return reportActionMessage; } const totalAmount = getMoneyRequestTotal(report); @@ -1006,7 +1008,7 @@ function getMoneyRequestReportActionMessage(report, reportAction) { if (isSettled(report.reportID)) { // A settled message is in the format of either "paid $1.00 elsewhere" or "paid $1.00 using Paypal.me" - const isSettledPaypalMe = Boolean(report.lastMessageText.match(/ Paypal.me$/)); + const isSettledPaypalMe = Boolean(reportActionMessage.match(/ Paypal.me$/)); const translatePhraseKey = isSettledPaypalMe ? 'iou.settledPaypalMeWithAmount' : 'iou.settledElsewhereWithAmount'; return Localize.translateLocal(translatePhraseKey, {amount: formattedAmount}); } From c9a25e5ea74d054e4063f3a9841cda917382570b Mon Sep 17 00:00:00 2001 From: VH Date: Mon, 26 Jun 2023 07:04:15 +0700 Subject: [PATCH 26/27] Fix translate settled message to ES --- src/languages/es.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/es.js b/src/languages/es.js index 6b9e3ea8ef9d..1267a59b7043 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -358,8 +358,8 @@ export default { amountEach: ({amount}) => `${amount} cada uno`, payerOwesAmount: ({payer, amount}) => `${payer} debe ${amount}`, payerPaidAmount: ({payer, amount}) => `${payer} pagó ${amount}`, - settledElsewhereWithAmount: ({amount}) => `paid ${amount} de otra forma`, - settledPaypalMeWithAmount: ({amount}) => `paid ${amount} con PayPal.me`, + settledElsewhereWithAmount: ({amount}) => `pagó ${amount} de otra forma`, + settledPaypalMeWithAmount: ({amount}) => `pagó ${amount} con PayPal.me`, noReimbursableExpenses: 'El monto de este informe es inválido', pendingConversionMessage: 'El total se actualizará cuando estés online', threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, From 331cc43bed4182ce2ee5ba85f4f63941b3c977fe Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 27 Jun 2023 05:33:09 +0700 Subject: [PATCH 27/27] Rename method to avoid confusing --- src/components/ReportActionItem/ReportPreview.js | 2 +- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 99ba312281a5..8321fcde825a 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -96,7 +96,7 @@ function ReportPreview(props) { const managerEmail = props.iouReport.managerEmail || ''; const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); - const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport, props.action); + const displayingMessage = ReportUtils.getReportPreviewMessage(props.iouReport, props.action); return (