Skip to content

Commit

Permalink
Merge pull request #33076 from rezkiy37/feature/33019-clear-next-steps
Browse files Browse the repository at this point in the history
Clear the next steps every time user takes some IOU action
  • Loading branch information
mountiny authored Dec 15, 2023
2 parents 6fc070b + 5b6700c commit e2eca1b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -2936,13 +2962,28 @@ 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});
}

/**
* @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);

Expand Down Expand Up @@ -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',
{
Expand Down

0 comments on commit e2eca1b

Please sign in to comment.