From 6761446ea69a6daabe82920e01d0990e09bf8fb6 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 18 May 2023 11:35:22 +0100 Subject: [PATCH 1/8] Make sure to use the chat reportID --- src/components/MoneyRequestHeader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index 0a14315fbbd8..41f75689f970 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -149,7 +149,7 @@ const MoneyRequestHeader = (props) => { currency={props.report.currency} policyID={props.report.policyID} shouldShowPaypal={Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerEmail, 'payPalMeAddress']))} - chatReportID={props.report.chatReportID} + chatReportID={props.chatReport.reportID} iouReport={props.report} onPress={(paymentType) => IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} From a29f4bb63409e0ee085e53537dde4fd0e7044b5d Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 18 May 2023 13:01:45 +0100 Subject: [PATCH 2/8] Remove the optimistic update of report preview --- src/libs/actions/IOU.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 33af1acd67c5..29880dc37d9b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1014,7 +1014,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType * @returns {Object} */ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { - const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID); const optimisticTransaction = TransactionUtils.buildOptimisticTransaction(iouReport.total, iouReport.currency, iouReport.reportID); const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.PAY, @@ -1042,15 +1041,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho lastMessageHtml: optimisticIOUReportAction.message[0].html, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [reportPreviewAction.reportActionID]: { - created: DateUtils.getDBTime(), - }, - }, - }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, From 387a176befc7ce0757fef9e133aa193aed6335e2 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 18 May 2023 13:02:50 +0100 Subject: [PATCH 3/8] Hide the pay button on the transaction view --- src/components/MoneyRequestHeader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index 41f75689f970..9440aea7adab 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -85,7 +85,7 @@ const MoneyRequestHeader = (props) => { : ReportUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerEmail, 'avatar']), moneyRequestReport.managerEmail); const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`]; const shouldShowSettlementButton = - !isSettled && (Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail)); + !isSettled && !props.isSingleTransactionView && (Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail)); return ( Date: Thu, 18 May 2023 13:03:24 +0100 Subject: [PATCH 4/8] Fix styles --- src/components/MoneyRequestHeader.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index 9440aea7adab..7c06891f4461 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -85,7 +85,9 @@ const MoneyRequestHeader = (props) => { : ReportUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerEmail, 'avatar']), moneyRequestReport.managerEmail); const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`]; const shouldShowSettlementButton = - !isSettled && !props.isSingleTransactionView && (Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail)); + !isSettled && + !props.isSingleTransactionView && + (Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail)); return ( Date: Thu, 18 May 2023 13:04:57 +0100 Subject: [PATCH 5/8] Remove the report preview action from failure data --- src/libs/actions/IOU.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 29880dc37d9b..a7dee2f8564f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1094,15 +1094,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho ]; const failureData = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [reportPreviewAction.reportActionID]: { - created: reportPreviewAction.created, - }, - }, - }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, From 4201994b3be1a98cf72dade6f582aa897d5c74da Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 18 May 2023 13:47:24 +0100 Subject: [PATCH 6/8] Fix pay money request optimistic data --- src/libs/ReportUtils.js | 5 +++-- src/libs/actions/IOU.js | 2 ++ src/pages/home/report/ReportActionItem.js | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d17d83c185bf..6122701476f7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1383,9 +1383,10 @@ function getIOUReportActionMessage(type, total, comment, currency, paymentType = * @param {String} [paymentType] - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify). * @param {String} [iouReportID] - Only required if the IOUReportActions type is oneOf(decline, cancel, pay). Generates a randomID as default. * @param {Boolean} [isSettlingUp] - Whether we are settling up an IOU. + * @param {Boolean} [isSendMoneyFlow] - Whether this is send money flow * @returns {Object} */ -function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, transactionID, paymentType = '', iouReportID = '', isSettlingUp = false) { +function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, transactionID, paymentType = '', iouReportID = '', isSettlingUp = false, isSendMoneyFlow = false) { const IOUReportID = iouReportID || generateReportID(); const parser = new ExpensiMark(); const commentText = getParsedComment(comment); @@ -1401,7 +1402,7 @@ function buildOptimisticIOUReportAction(type, amount, currency, comment, partici }; // We store amount, comment, currency in IOUDetails when type = pay - if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) { + if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY && isSendMoneyFlow) { _.each(['amount', 'comment', 'currency'], (key) => { delete originalMessage[key]; }); diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index a7dee2f8564f..ccc133cc56bd 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -882,6 +882,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType optimisticTransaction.transactionID, paymentMethodType, optimisticIOUReport.reportID, + false, + true, ); // First, add data that will be used in all cases diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 41fcf102a138..e0749f698444 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -193,11 +193,10 @@ class ReportActionItem extends Component { originalMessage && (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE || originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT || - (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage.IOUDetails)) + (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && _.has(originalMessage, 'IOUDetails'))) ) { // There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID const iouReportID = originalMessage.IOUReportID ? originalMessage.IOUReportID.toString() : '0'; - children = ( Date: Thu, 18 May 2023 14:07:37 +0100 Subject: [PATCH 7/8] Make sure there is no settled 0 messages showing --- src/components/ReportActionItem/ReportPreview.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 814a38dba5b5..f9aa62c5b7cd 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -100,7 +100,7 @@ const ReportPreview = (props) => { const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); return ( - {_.map(props.action.message, (index) => ( + {_.map(props.action.message, (message, index) => ( { @@ -114,10 +114,12 @@ const ReportPreview = (props) => { > {props.iouReport.hasOutstandingIOU ? ( - {props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount})} + + {lodashGet(message, 'html', props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount}))} + ) : ( - {props.translate('iou.payerSettled', {amount: reportAmount})} + {lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))} {!props.iouReport.hasOutstandingIOU && ( Date: Thu, 18 May 2023 17:24:23 +0100 Subject: [PATCH 8/8] Refactor code for cleaner condition --- src/components/MoneyRequestHeader.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index 7c06891f4461..cc540b108c4f 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -84,10 +84,8 @@ const MoneyRequestHeader = (props) => { ? ReportUtils.getWorkspaceAvatar(moneyRequestReport) : ReportUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerEmail, 'avatar']), moneyRequestReport.managerEmail); const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`]; - const shouldShowSettlementButton = - !isSettled && - !props.isSingleTransactionView && - (Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail)); + const isPayer = Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail); + const shouldShowSettlementButton = !isSettled && !props.isSingleTransactionView && isPayer; return (