Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.48k stars 2.84k forks source link

Track expense - Edited amount is not reflected correctly in amount editor on confirmation page #51030

Open IuliiaHerets opened 3 days ago

IuliiaHerets commented 3 days ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.50-0 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): applausetester+kh081006@applause.expensifail.com Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to self DM.
  3. Track a $10 expense.
  4. Go to transaction thread.
  5. Change the amount to $20 (important).
  6. Go back to main chat and click Submit it to someone from the whisper.
  7. Select a user.
  8. Click Amount on the confirmation page.
  9. Change the amount to $30 and save it.
  10. Click Amount.

Expected Result:

The amount will remain the same, which is $30.

Actual Result:

The amount is $20, while it shows $30 on the confirmation page.

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/29c581a1-214a-462b-a91a-3cbfe5530c2f

View all open jobs on GitHub

melvin-bot[bot] commented 3 days ago

Triggered auto assignment to @puneetlath (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

IuliiaHerets commented 3 days ago

@puneetlath FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

FitseTLT commented 3 days ago

Edited by proposal-police: This proposal was edited at 2024-10-17 16:32:06 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

Track expense - Edited amount is not reflected correctly in amount editor on confirmation page

What is the root cause of that problem?

We are taking the modifiedAmount from the trackExpense when we create draft transaction on submit it to someone https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/libs/ReportUtils.ts#L8037-L8046 So in IOUStepAmountPage we only update only amount (not modifiedAmount) of the transaction if the action is not editing https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/pages/iou/request/step/IOURequestStepAmount.tsx#L170 So in confirmation page we will see this new amount we updated but when reopen the amount page it will show us modifiedAmount which has not been updated https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/libs/TransactionUtils/index.ts#L337-L340 it prioritize modifiedAmount if over amount if it exists

What changes do you think we should make in order to solve the problem?

We should mimic the setup we have for create expense (because submit it to someone is basically creating an expense from an existing some sort of expense template) so when we create a draft transaction increateDraftTransactionAndNavigateToParticipantSelector whether it is for submit, categorize or share we should reset modifiedAmount to undefined so that IOURequestStepAmount will have one source of truth amount same as what we have for creation of a new request. We need to reset modifiedAmount on the draft transaction here


        currency,
        modifiedAmount: undefined,

What alternative solutions did you explore? (Optional)

daledah commented 3 days ago

Edited by proposal-police: This proposal was edited at 2024-10-17 15:50:45 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

The amount is $20, while it shows $30 on the confirmation page.

What is the root cause of that problem?

If the original amount is 100 When editing the track expense to 200, we will update modifiedAmount: -200, amount: -100

We're showing the amount on confirmation page

https://github.com/Expensify/App/blob/47b681160a137a7b693307e6258555751171eebc/src/pages/iou/request/step/IOURequestStepConfirmation.tsx#L640

But on amount page, we use modifiedAmount

https://github.com/Expensify/App/blob/47b681160a137a7b693307e6258555751171eebc/src/pages/iou/request/step/IOURequestStepAmount.tsx#L87

https://github.com/Expensify/App/blob/47b681160a137a7b693307e6258555751171eebc/src/libs/TransactionUtils/index.ts#L358-L360

What changes do you think we should make in order to solve the problem?

We should update modifiedAmount if it's the draft transaction in

https://github.com/Expensify/App/blob/47b681160a137a7b693307e6258555751171eebc/src/libs/actions/IOU.ts#L404-L406

function setMoneyRequestAmount(transactionID: string, amount: number, currency: string, shouldShowOriginalAmount = false) {
    Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount, currency, shouldShowOriginalAmount, modifiedAmount: amount});
}

What alternative solutions did you explore? (Optional)

NA

FitseTLT commented 3 days ago

Only added detail on the RCA