From 766ceed5987bc2a260c4f40abe3d1e0cdcc8ecdd Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 7 Sep 2023 01:17:15 +0800 Subject: [PATCH 1/4] Make sure we dont need report preview to make payment --- src/libs/actions/IOU.js | 46 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8d1de1dc4d60..437cd6a90c7f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1538,7 +1538,11 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho true, ); - const optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID)); + const optimisticReportPreviewAction = null; + const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID); + if (reportPreviewAction) { + optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction); + } const optimisticData = [ { @@ -1564,13 +1568,18 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [optimisticReportPreviewAction.reportActionID]: optimisticReportPreviewAction, - }, - }, + ...(optimisticReportPreviewAction + ? [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticReportPreviewAction.reportActionID]: optimisticReportPreviewAction, + }, + }, + ] + : [] + ), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, @@ -1611,15 +1620,20 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [optimisticReportPreviewAction.reportActionID]: { - created: optimisticReportPreviewAction.created, + ...(optimisticReportPreviewAction + ? [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticReportPreviewAction.reportActionID]: { + created: optimisticReportPreviewAction.created, + }, + }, }, - }, - }, + ] + : [] + ), ]; return { From fed3153cbeb3336ff8f43fa34cca4f71c6e445dc Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 7 Sep 2023 01:40:29 +0800 Subject: [PATCH 2/4] Prettier --- src/libs/actions/IOU.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 437cd6a90c7f..1e82bc6c38c2 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1570,16 +1570,15 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, ...(optimisticReportPreviewAction ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [optimisticReportPreviewAction.reportActionID]: optimisticReportPreviewAction, - }, - }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticReportPreviewAction.reportActionID]: optimisticReportPreviewAction, + }, + }, ] - : [] - ), + : []), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, @@ -1622,18 +1621,17 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, ...(optimisticReportPreviewAction ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [optimisticReportPreviewAction.reportActionID]: { - created: optimisticReportPreviewAction.created, - }, - }, - }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticReportPreviewAction.reportActionID]: { + created: optimisticReportPreviewAction.created, + }, + }, + }, ] - : [] - ), + : []), ]; return { From e5ccf3780203e0ce73f8779f9722639fb5610780 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 7 Sep 2023 01:41:19 +0800 Subject: [PATCH 3/4] Make constant variable --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 1e82bc6c38c2..e0aa4f72c1c9 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1538,7 +1538,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho true, ); - const optimisticReportPreviewAction = null; + let optimisticReportPreviewAction = null; const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction); From 04c77503638b6961b9e23a45b2e5b87492327f51 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Thu, 7 Sep 2023 01:46:44 +0800 Subject: [PATCH 4/4] Address PR feedback --- src/libs/actions/IOU.js | 46 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index e0aa4f72c1c9..bc7adf47bd8c 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1538,6 +1538,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho true, ); + // In some instances, the report preview action might not be available to the payer (only whispered to the requestor) + // hence we need to make the updates to the action safely. let optimisticReportPreviewAction = null; const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID); if (reportPreviewAction) { @@ -1568,17 +1570,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, }, }, - ...(optimisticReportPreviewAction - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [optimisticReportPreviewAction.reportActionID]: optimisticReportPreviewAction, - }, - }, - ] - : []), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, @@ -1619,21 +1610,28 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, }, }, - ...(optimisticReportPreviewAction - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, - value: { - [optimisticReportPreviewAction.reportActionID]: { - created: optimisticReportPreviewAction.created, - }, - }, - }, - ] - : []), ]; + // In case the report preview action is loaded locally, let's update it. + if (optimisticReportPreviewAction) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticReportPreviewAction.reportActionID]: optimisticReportPreviewAction, + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticReportPreviewAction.reportActionID]: { + created: optimisticReportPreviewAction.created, + }, + }, + }); + } + return { params: { iouReportID: iouReport.reportID,