-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Followup #23961: update IOU report total in optimistic data on edit money request #25498
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
Changes from all commits
f0ff0a7
72784d4
b7dc724
7c9706e
c7a2d06
4cbd6d5
db3cf8a
ea2926f
4399aa1
3e98419
e89644c
529180d
2590bdc
58346d1
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 |
|---|---|---|
|
|
@@ -989,12 +989,50 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC | |
| const transactionThread = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`]; | ||
| const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; | ||
| const iouReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThread.parentReportID}`]; | ||
| const chatReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`]; | ||
| const isFromExpenseReport = ReportUtils.isExpenseReport(iouReport); | ||
|
|
||
| // STEP 2: Build new modified expense report action. | ||
| const updatedReportAction = ReportUtils.buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport); | ||
| const updatedTransaction = TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport); | ||
|
|
||
| // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct | ||
| // Should only update if the transaction matches the currency of the report, else we wait for the update | ||
| // from the server with the currency conversion | ||
| let updatedMoneyRequestReport = {...iouReport}; | ||
| const updatedChatReport = {...chatReport}; | ||
| if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { | ||
|
Contributor
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. @BeeMargarida @rezkiy37 run into an issue because the
Contributor
Author
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. Yes, I'll make a PR with that fix
Contributor
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. Thank you!
Contributor
Author
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. The regression fix PR: #27451 (comment) |
||
| const diff = TransactionUtils.getAmount(transaction, true) - TransactionUtils.getAmount(updatedTransaction, true); | ||
| if (ReportUtils.isExpenseReport(iouReport)) { | ||
| updatedMoneyRequestReport.total += diff; | ||
| } else { | ||
| updatedMoneyRequestReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, updatedReportAction.actorAccountID, diff, TransactionUtils.getCurrency(transaction), false); | ||
| } | ||
|
|
||
| updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedTransaction.currency); | ||
|
|
||
| // Update the last message of the IOU report | ||
| const lastMessage = ReportUtils.getIOUReportActionMessage( | ||
| iouReport.reportID, | ||
| CONST.IOU.REPORT_ACTION_TYPE.CREATE, | ||
|
BeeMargarida marked this conversation as resolved.
|
||
| updatedMoneyRequestReport.total, | ||
| '', | ||
| updatedTransaction.currency, | ||
| '', | ||
| false, | ||
| ); | ||
| updatedMoneyRequestReport.lastMessageText = lastMessage[0].text; | ||
| updatedMoneyRequestReport.lastMessageHtml = lastMessage[0].html; | ||
|
|
||
| // Update the last message of the chat report | ||
| const messageText = Localize.translateLocal('iou.payerOwesAmount', { | ||
| payer: updatedMoneyRequestReport.managerEmail, | ||
|
Contributor
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. How hard would it be to update this to use
Contributor
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. We're trying to get rid of all uses of
Contributor
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. I guess not that hard just time consuming as we need to make prs across stack from back to front end and back, do you have an issue specifically for these flows?
Contributor
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. This may be the most related one: https://github.com/Expensify/Expensify/issues/294647 |
||
| amount: CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, updatedMoneyRequestReport.currency), | ||
| }); | ||
| updatedChatReport.lastMessageText = messageText; | ||
| updatedChatReport.lastMessageHtml = messageText; | ||
| } | ||
|
|
||
| // STEP 4: Compose the optimistic data | ||
| const optimisticData = [ | ||
| { | ||
|
|
@@ -1009,6 +1047,16 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC | |
| key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, | ||
| value: updatedTransaction, | ||
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, | ||
| value: updatedMoneyRequestReport, | ||
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`, | ||
| value: updatedChatReport, | ||
| }, | ||
|
Contributor
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. We should have set |
||
| ]; | ||
|
|
||
| const successData = [ | ||
|
|
@@ -1032,6 +1080,11 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC | |
| }, | ||
| }, | ||
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, | ||
| value: {pendingAction: null}, | ||
| }, | ||
| ]; | ||
|
|
||
| const failureData = [ | ||
|
|
@@ -1049,9 +1102,14 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC | |
| }, | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.report}`, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, | ||
| value: iouReport, | ||
| }, | ||
|
mountiny marked this conversation as resolved.
|
||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`, | ||
| value: chatReport, | ||
| }, | ||
| ]; | ||
|
|
||
| // STEP 6: Call the API endpoint | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.