diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 7513989d08c4..1e69bd236f0f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -119,6 +119,15 @@ Onyx.connect({ }, }); +let nextSteps = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.NEXT_STEP, + waitForCollectionCallback: true, + callback: (val) => { + nextSteps = val || {}; + }, +}); + /** * Initialize money request info * @param {String} reportID to attach the transaction to @@ -2751,6 +2760,8 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho optimisticReportPreviewAction = ReportUtils.updateReportPreview(iouReport, reportPreviewAction, true); } + const currentNextStep = lodashGet(nextSteps, `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`, null); + const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2817,6 +2828,19 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho }, ]; + if (!_.isNull(currentNextStep)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`, + value: null, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport.reportID}`, + value: currentNextStep, + }); + } + // In case the report preview action is loaded locally, let's update it. if (optimisticReportPreviewAction) { optimisticData.push({ @@ -2887,6 +2911,8 @@ function sendMoneyWithWallet(report, amount, currency, comment, managerID, recip } function approveMoneyRequest(expenseReport) { + const currentNextStep = lodashGet(nextSteps, `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, null); + const optimisticApprovedReportAction = ReportUtils.buildOptimisticApprovedReportAction(expenseReport.total, expenseReport.currency, expenseReport.reportID); const optimisticReportActionsData = { @@ -2936,6 +2962,19 @@ function approveMoneyRequest(expenseReport) { }, ]; + if (!_.isNull(currentNextStep)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, + value: null, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, + value: currentNextStep, + }); + } + API.write('ApproveMoneyRequest', {reportID: expenseReport.reportID, approvedReportActionID: optimisticApprovedReportAction.reportActionID}, {optimisticData, successData, failureData}); } @@ -2943,6 +2982,8 @@ function approveMoneyRequest(expenseReport) { * @param {Object} expenseReport */ function submitReport(expenseReport) { + const currentNextStep = lodashGet(nextSteps, `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, null); + const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport.total, expenseReport.currency, expenseReport.reportID); const parentReport = ReportUtils.getReport(expenseReport.parentReportID); @@ -3028,6 +3069,19 @@ function submitReport(expenseReport) { : []), ]; + if (!_.isNull(currentNextStep)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, + value: null, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`, + value: currentNextStep, + }); + } + API.write( 'SubmitReport', {