Skip to content
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] Optimistically update receipt state to OPEN when the request is edited #25385

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ const CONST = {
AMOUNT_MAX_LENGTH: 10,
RECEIPT_STATE: {
SCANREADY: 'SCANREADY',
OPEN: 'OPEN',
SCANNING: 'SCANNING',
SCANCOMPLETE: 'SCANCOMPLETE',
SCANFAILED: 'SCANFAILED',
Expand Down
13 changes: 13 additions & 0 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function hasReceipt(transaction) {
function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) {
// Only changing the first level fields so no need for deep clone now
const updatedTransaction = _.clone(transaction);
let shouldStopSmartscan = false;

// The comment property does not have its modifiedComment counterpart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we leave a comment explaining the smartscan is not stopped when Comment is changed?

@Gonals Also shouldnt the smartscan stop also when merchant is edited? this is not implemented in the App yet but its in the Auth so I can add it there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it should, but we still didn't have merchants when I coded this. We do need to add it to auth (and eventually here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I just added it here too. No harm in doing so.
I've also created an issue to handle it in Auth too and will fix that tomorrow: https://github.com/Expensify/Expensify/issues/309894

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (_.has(transactionChanges, 'comment')) {
Expand All @@ -103,12 +104,24 @@ function getUpdatedTransaction(transaction, transactionChanges, isFromExpenseRep
}
if (_.has(transactionChanges, 'created')) {
updatedTransaction.modifiedCreated = transactionChanges.created;
shouldStopSmartscan = true;
}
if (_.has(transactionChanges, 'amount')) {
updatedTransaction.modifiedAmount = isFromExpenseReport ? -transactionChanges.amount : transactionChanges.amount;
shouldStopSmartscan = true;
}
if (_.has(transactionChanges, 'currency')) {
updatedTransaction.modifiedCurrency = transactionChanges.currency;
shouldStopSmartscan = true;
}

if (_.has(transactionChanges, 'merchant')) {
updatedTransaction.modifiedMerchant = transactionChanges.merchant;
shouldStopSmartscan = true;
}

if (shouldStopSmartscan && _.has(transaction, 'receipt') && !_.isEmpty(transaction.receipt) && lodashGet(transaction, 'receipt.state') !== CONST.IOU.RECEIPT_STATE.OPEN) {
updatedTransaction.receipt.state = CONST.IOU.RECEIPT_STATE.OPEN;
Gonals marked this conversation as resolved.
Show resolved Hide resolved
}
updatedTransaction.pendingFields = {
...(_.has(transactionChanges, 'comment') && {comment: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
Expand Down