-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NoQA] Feat: Add submit action #28947
Changes from all commits
da7d340
9ca8e1e
96fd57b
5d3df48
f0b9557
fa2c697
60013c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2106,6 +2106,80 @@ function approveMoneyRequest(expenseReport) { | |
API.write('ApproveMoneyRequest', {reportID: expenseReport.reportID, approvedReportActionID: optimisticApprovedReportAction.reportActionID}, {optimisticData, successData, failureData}); | ||
} | ||
|
||
/** | ||
* @param {Object} expenseReport | ||
*/ | ||
function submitReport(expenseReport) { | ||
waterim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport.total, expenseReport.currency, expenseReport.reportID); | ||
|
||
const optimisticReportActionsData = { | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, | ||
value: { | ||
[optimisticSubmittedReportAction.reportActionID]: { | ||
...optimisticSubmittedReportAction, | ||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||
}, | ||
}, | ||
}; | ||
const optimisticIOUReportData = { | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, | ||
value: { | ||
...expenseReport, | ||
lastMessageText: optimisticSubmittedReportAction.message[0].text, | ||
lastMessageHtml: optimisticSubmittedReportAction.message[0].html, | ||
state: CONST.REPORT.STATE.SUBMITTED, | ||
stateNum: CONST.REPORT.STATE_NUM.PROCESSING, | ||
statusNum: CONST.REPORT.STATUS.SUBMITTED, | ||
}, | ||
}; | ||
const optimisticData = [optimisticIOUReportData, optimisticReportActionsData]; | ||
|
||
const successData = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, | ||
value: { | ||
[optimisticSubmittedReportAction.reportActionID]: { | ||
pendingAction: null, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const failureData = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, | ||
value: { | ||
[expenseReport.reportActionID]: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @waterim @Beamanator @burczu @mountiny, should the reportId for failureData should have been the optimistic id There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes correct this should have been |
||
errors: ErrorUtils.getMicroSecondOnyxError('iou.error.other'), | ||
}, | ||
}, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, | ||
value: { | ||
state: CONST.REPORT.STATE.OPEN, | ||
stateNum: CONST.REPORT.STATE_NUM.OPEN, | ||
}, | ||
}, | ||
]; | ||
|
||
API.write( | ||
'SubmitReport', | ||
{ | ||
reportID: expenseReport.reportID, | ||
managerEmail: expenseReport.managerEmail, | ||
managerAccountID: expenseReport.managerID, | ||
Beamanator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
reportActionID: optimisticSubmittedReportAction.reportActionID, | ||
}, | ||
{optimisticData, successData, failureData}, | ||
); | ||
} | ||
|
||
/** | ||
* @param {String} paymentType | ||
* @param {Object} chatReport | ||
|
@@ -2327,10 +2401,6 @@ function getIOUReportID(iou, route) { | |
return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', ''); | ||
} | ||
|
||
function submitReport() { | ||
// Will be implemented in https://github.com/Expensify/App/issues/28763 | ||
} | ||
|
||
export { | ||
createDistanceRequest, | ||
editMoneyRequest, | ||
|
@@ -2340,6 +2410,7 @@ export { | |
requestMoney, | ||
sendMoneyElsewhere, | ||
approveMoneyRequest, | ||
submitReport, | ||
payMoneyRequest, | ||
sendMoneyWithWallet, | ||
startMoneyRequest, | ||
|
@@ -2362,5 +2433,4 @@ export { | |
updateDistanceRequest, | ||
replaceReceipt, | ||
getIOUReportID, | ||
submitReport, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line introduced bug here: #38579
where the optimistic data from the client differs from what is returned by the backend.