From 0aafe65be60dc8c4fd08a0712461ea815aac9d67 Mon Sep 17 00:00:00 2001 From: Luthfi Date: Sun, 14 May 2023 12:21:29 +0700 Subject: [PATCH 1/3] new method to get money request action --- src/libs/ReportUtils.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index bf891ec11ecf..c9713c6a1f15 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -937,6 +937,32 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) }); } +/** + * We get the amount, currency and comment money request value from the action.originalMessage. + * But for the send money action, the above value is put in the IOUDetails object. + * + * @param {Object} reportAction + * @param {Number} reportAction.amount + * @param {String} reportAction.currency + * @param {String} reportAction.comment + * @param {Object} reportAction.IOUDetails + * @returns {Object} + */ +function getMoneyRequestAction(reportAction = {}) { + const originalMessage = lodashGet(reportAction, 'originalMessage', {}); + let total = originalMessage.amount || 0; + let currency = originalMessage.currency || CONST.CURRENCY.USD; + let comment = originalMessage.comment || ''; + + if (_.has(originalMessage, 'IOUDetails')) { + total = lodashGet(originalMessage, 'IOUDetails.amount', 0); + currency = lodashGet(originalMessage, 'IOUDetails.currency', CONST.CURRENCY.USD); + comment = lodashGet(originalMessage, 'IOUDetails.comment', ''); + } + + return {total, currency, comment}; +} + /** * @param {Object} report * @param {String} report.iouReportID @@ -2105,4 +2131,5 @@ export { shouldReportShowSubscript, isReportDataReady, isSettled, + getMoneyRequestAction, }; From 9e95b53f6d222d7e42e887199c3bfa41a92f7b33 Mon Sep 17 00:00:00 2001 From: Luthfi Date: Sun, 14 May 2023 12:22:10 +0700 Subject: [PATCH 2/3] use the formatted money request action --- src/components/ReportActionItem/IOUPreview.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/IOUPreview.js b/src/components/ReportActionItem/IOUPreview.js index 65cc6ed4929f..77e6f07e111a 100644 --- a/src/components/ReportActionItem/IOUPreview.js +++ b/src/components/ReportActionItem/IOUPreview.js @@ -146,9 +146,11 @@ const IOUPreview = (props) => { // Pay button should only be visible to the manager of the report. const isCurrentUserManager = managerEmail === sessionEmail; + const moneyRequestAction = ReportUtils.getMoneyRequestAction(props.action); + // If props.action is undefined then we are displaying within IOUDetailsModal and should use the full report amount - const requestAmount = props.isIOUAction ? lodashGet(props.action, 'originalMessage.amount', 0) : ReportUtils.getMoneyRequestTotal(props.iouReport); - const requestCurrency = props.isIOUAction ? lodashGet(props.action, 'originalMessage.currency', CONST.CURRENCY.USD) : props.iouReport.currency; + const requestAmount = props.isIOUAction ? moneyRequestAction.total : ReportUtils.getMoneyRequestTotal(props.iouReport); + const requestCurrency = props.isIOUAction ? moneyRequestAction.currency : props.iouReport.currency; const getSettledMessage = () => { switch (lodashGet(props.action, 'originalMessage.paymentType', '')) { @@ -229,7 +231,7 @@ const IOUPreview = (props) => { {props.translate('iou.pendingConversionMessage')} )} - {Str.htmlDecode(lodashGet(props.action, 'originalMessage.comment', ''))} + {Str.htmlDecode(moneyRequestAction.comment)} From 7ea993084d05ce964df4c6f54820d6ea9ed424c2 Mon Sep 17 00:00:00 2001 From: Luthfi Date: Sun, 14 May 2023 20:03:50 +0700 Subject: [PATCH 3/3] fix the JSDoc object --- 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 c9713c6a1f15..09ba8681ceda 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -945,7 +945,7 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) * @param {Number} reportAction.amount * @param {String} reportAction.currency * @param {String} reportAction.comment - * @param {Object} reportAction.IOUDetails + * @param {Object} [reportAction.IOUDetails] * @returns {Object} */ function getMoneyRequestAction(reportAction = {}) {