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

[$500] Request - Request money amount disappears if tap Next&Back and then switching between tabs #32739

Closed
6 tasks done
lanitochka17 opened this issue Dec 8, 2023 · 17 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Dec 8, 2023

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: 1.4.10-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Login to ND Expensify
  2. Tap FAB button
  3. Tap Request money
  4. Select Manual tab
  5. Select a currency and enter any amount
  6. Tap Next
  7. Tap Back
  8. Switch between tabs Scan or Distance and return to Manual tab

Expected Result:

The amount previously entered is remembered and displayed on the BNP

Actual Result:

If user proceeds until attendee selector and then returns back, switching between tabs make the amount disappear

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6306099_1702060371938.1000024236.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~017941ed9191037a56
  • Upwork Job ID: 1733194841222483968
  • Last Price Increase: 2023-12-08
  • Automatic offers:
    • c3024 | Reviewer | 28037175
    • FitseTLT | Contributor | 28037178
@lanitochka17 lanitochka17 added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 2023

Triggered auto assignment to @kadiealexander (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

Copy link

melvin-bot bot commented Dec 8, 2023

Job added to Upwork: https://www.upwork.com/jobs/~017941ed9191037a56

@melvin-bot melvin-bot bot changed the title Request - Request money amount disappears if tap Next&Back and then switching between tabs [$500] Request - Request money amount disappears if tap Next&Back and then switching between tabs Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 8, 2023
Copy link

melvin-bot bot commented Dec 8, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @c3024 (External)

@FitseTLT
Copy link
Contributor

FitseTLT commented Dec 8, 2023

Proposal

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

Request money amount disappears if tap Next&Back and then switching between tabs

What is the root cause of that problem?

currentAmount state is being reset to iou.amount here as we navigate to the receipt selector page because iou.amount is reset (to 0) always when we change between tabs

initializeAmount(amount);
// we want to update the state only when the amount is changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [amount]);

But the reason this is not happening before the user's first click of Next is that when a user inputs an amount it will only set the currentAmount state in MoneyRequestAmountForm not iou.amount and iou.amount is 0 so navigating between tabs will not reset the currentAmount state as there will be no change in iou.amount on navigating between tabs the iou.amount is reset to 0 but iou.amount was not changed it was already 0.

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

We shouldn't reset currentAmount state on iou.amount change if iou.amount is 0 as that means we are having a reset on the iou.amount and we need to preserve currentAmount state for MoneyRequestAmountForm (same as it is preserving between switch of tabs before the first user clicks of Next )

initializeAmount(amount);
// we want to update the state only when the amount is changed

if(amount !== 0){
initializeAmount(amount);
}

What alternative solutions did you explore? (Optional)

If we don't have any special reason we can leave updating currentAmount state to iou.amount value at all. Because currentAmount is a state of the user's amount input as long as the MoneyRequestAmountForm is rendered and preserving that state will be better user experience as the user will always have his draft amount value present always.

@yh-0218
Copy link
Contributor

yh-0218 commented Dec 8, 2023

Proposal

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

Request money amount disappears if tap Next&Back and then switching between tabs

What is the root cause of that problem?

When we enter first tap(manual), we reset iou.

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

We need to give amount when reset

resetMoneyRequestInfo();

What alternative solutions did you explore? (Optional)

Screen.Recording.2023-12-08.at.9.13.36.PM.mov

@BhuvaneshPatil
Copy link
Contributor

Proposal

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

Request amount is changing whenever we go to next step and come back again

What is the root cause of that problem?

We are resetting the transaction details here -

App/src/libs/actions/IOU.js

Lines 113 to 121 in 138e6a2

Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${newTransactionID}`, {
amount: 0,
comment,
created,
currency: lodashGet(currentUserPersonalDetails, 'localCurrencyCode', CONST.CURRENCY.USD),
iouRequestType,
reportID,
transactionID: newTransactionID,
});

Whenever we change the tab this method is being called. There are two instances -

IOU.startMoneyRequest_temporaryForRefactor(reportID, transactionRequestType.current);

IOU.startMoneyRequest_temporaryForRefactor(reportID, newIouType);

This causes the amount to set zero.
But the question arises that why it is not resetting to zero when we change the tab without going next and coming back.

Screen.Recording.2023-12-09.at.1.11.27.AM.mov

The reason behind that is the MoneyRequestAmountForm component isn't unmounted, and thus state is preserved.

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

We shall pass amount to startMoneyRequest_temporaryForRefactor(), the default value will be zero.
Whenever we call this method we pass the current amount in transaction.

...
IOU.startMoneyRequest_temporaryForRefactor(reportID, transactionRequestType.current, TransactionUtils.getAmount(transaction));
...

and we use the amount we received as parameter to set the amount.

    Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${newTransactionID}`, {
        amount: currentAmount,
        comment,
        created,
        currency: lodashGet(currentUserPersonalDetails, 'localCurrencyCode', CONST.CURRENCY.USD),
        iouRequestType,
        reportID,
        transactionID: newTransactionID,
    });
Screen.Recording.2023-12-09.at.1.17.52.AM.mov

What alternative solutions did you explore? (Optional)

@AmjedNazzal
Copy link
Contributor

Proposal

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

Request - Request money amount disappears if tap Next&Back and then switching between tabs

What is the root cause of that problem?

To understand the cause of this, let's take a look at this section of the code from MoneyRequestAmountForm:

const initializeAmount = useCallback((newAmount) => {
const frontendAmount = newAmount ? CurrencyUtils.convertToFrontendAmount(newAmount).toString() : '';
setCurrentAmount(frontendAmount);
setSelection({
start: frontendAmount.length,
end: frontendAmount.length,
});
}, []);
useEffect(() => {
if (!currency || !_.isNumber(amount)) {
return;
}
initializeAmount(amount);
// we want to update the state only when the amount is changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [amount]);

So what the above code is doing is simple, if there is newAmount, which is retrieved from the onyx store, it will set the currentAmount to that amount, else it will reset it to 0.

Now the problem is that when we proceed to the next step, the value of the amount variable will change since we are updating the amount in the onyx store, also as we navigate to other tabs after that, we are resetting that onyx store amount to initialise the other tabs, what happens because of that is that the useEffect will kick in as the amount has changed, resulting in currentAmount being reset the same as if we were to unmount and remount the component.

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

Since the currentAmount will be reset to 0 anyway when we unmount and remount the component, I don't see the point in calling setCurrentAmount just to pass it nothing, so we can add a check to not do that unless frontendAmount does hold a value

const initializeAmount = useCallback((newAmount) => {
    const frontendAmount = newAmount ? CurrencyUtils.convertToFrontendAmount(newAmount).toString() : '';
    if(frontendAmount){
        setCurrentAmount(frontendAmount);
        setSelection({
            start: frontendAmount.length,
            end: frontendAmount.length,
        });
    }

Result

Screen.Recording.2023-12-08.at.11.01.26.PM.mov

@melvin-bot melvin-bot bot added the Overdue label Dec 11, 2023
@c3024
Copy link
Contributor

c3024 commented Dec 11, 2023

Proposal by @FitseTLT identifies the root cause correctly and the solution suggested works well.

🎀 👀 🎀 C+ Reviewed

Copy link

melvin-bot bot commented Dec 11, 2023

Triggered auto assignment to @stitesExpensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 11, 2023
Copy link

melvin-bot bot commented Dec 11, 2023

📣 @c3024 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Dec 11, 2023

📣 @FitseTLT 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Dec 13, 2023
@0xmiros
Copy link
Contributor

0xmiros commented Dec 13, 2023

As per new expected behavior, I think we can close this.

@c3024
Copy link
Contributor

c3024 commented Dec 14, 2023

Yes, the expected behavior changed since this proposal was approved. Now, the suggested changes are not required. The issue may be closed.

@kadiealexander @stitesExpensify

Since, the issue proceeded to the point of making a PR, some compensation might be due.

@FitseTLT
Copy link
Contributor

@stitesExpensify U can close this issue; from my side I am OK ❤️ with no compensation 👍

@stitesExpensify
Copy link
Contributor

Great, thanks @FitseTLT !

@c3024
Copy link
Contributor

c3024 commented Dec 19, 2023

Please close the PR @FitseTLT .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests

9 participants