Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mountiny committed Sep 6, 2023
1 parent e5ccf37 commit 04c7750
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 04c7750

Please sign in to comment.