Skip to content

[Due for payment 2025-04-14] [$250] Expense - Pay Elsewhere button returns to Pay with expensify if editing any field in report. #58688

Closed

Description

@jponikarchuk

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.1.15-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Yes, reproducible on both
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): ibellicotest+421@gmail.com
Issue reported by: Applause Internal Team
Device used: Motorola MotoG60 - Android 12 - Chrome / Windows 10 - Chrome
App Component: Money Requests

Action Performed:

  1. Open the staging.new.expensify.com website.
  2. Open any workspace chat (Add approvals and Delay submissions are disabled).
  3. Create an expense.
  4. Open the expense report and tap on the dropdown menu on the pay button.
  5. Select "Pay Elsewhere"
  6. Edit any field on the report. (For example: Merchant)
  7. When redirected to report again, check the pay button behaviour after this action.

Expected Result:

"Pay Elsewhere" option should remain the same after editing any of the fields in expense report.

Actual Result:

"Pay Elsewhere" option in expense report gets reseted to "Pay with Expensify" after editing any field of the report for the first time.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021902359061805797787
  • Upwork Job ID: 1902359061805797787
  • Last Price Increase: 2025-03-26
  • Automatic offers:
    • DylanDylann | Reviewer | 106678841
    • nkdengineer | Contributor | 106678843
Issue OwnerCurrent Issue Owner: @laurenreidexpensify

Activity

  1. added
    Bug
    Daily
    on Mar 19, 2025
  2. melvin-bot commented on Mar 19, 2025

    @melvin-bot

    Triggered auto assignment to @laurenreidexpensify (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.

  3. added
    External
    on Mar 19, 2025
  4. changed the title [-]Expense - Pay Elsewhere button returns to Pay with expensify if editing any field in report.[/-] [+][$250] Expense - Pay Elsewhere button returns to Pay with expensify if editing any field in report.[/+] on Mar 19, 2025
  5. melvin-bot commented on Mar 19, 2025

    @melvin-bot
  6. added
    Help Wanted
    on Mar 19, 2025
  7. melvin-bot commented on Mar 19, 2025

    @melvin-bot

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

  8. linhvovan29546 commented on Mar 19, 2025

    @linhvovan29546
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-03-19 15:10:00 UTC.

    Proposal

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

    Expense - Pay Elsewhere button returns to Pay with expensify if editing any field in report.

    What is the root cause of that problem?

    When editing any field in the report, paymentButtonOptions is re-rendered. During this process, we re-sort the options to ensure the lastPaymentMethod is always at the top. And, in ButtonWithDropdownMenu, the selectedItemIndex still keep the same previous, causing the selected button to reset.

    if (lastPaymentMethod) {
    return buttonOptions.sort((method) => (method.value === lastPaymentMethod ? -1 : 0));
    }

    const [selectedItemIndex, setSelectedItemIndex] = useState(defaultSelectedIndex);

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

    We can update selectedItemIndex immediately after sorting buttonOptions.

        useImperativeHandle(ref,
            () => ({
                setSelectedItemIndex: (index) => {
                    setSelectedItemIndex(index);
                },
            }),
        )
    • Pass a ref to ButtonWithDropdownMenu in SettlementButton.

    • Update selectedItemIndex after sorting buttonOptions.

    if (lastPaymentMethod && shouldSortLastPaymentMethod.current) {
                buttonWithDropdownMenuRef.current.setSelectedItemIndex(0)
                return buttonOptions.sort((method) => (method.value === lastPaymentMethod ? -1 : 0));
            }

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    We can write unit test to verify the button not change when re re-ender the paymentButtonOptions

    What alternative solutions did you explore? (Optional)

  9. linhvovan29546 commented on Mar 19, 2025

    @linhvovan29546
    Contributor
  10. nkdengineer commented on Mar 19, 2025

    @nkdengineer
    Contributor

    Proposal

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

    "Pay Elsewhere" option in expense report gets reseted to "Pay with Expensify" after editing any field of the report for the first time.

    What is the root cause of that problem?

    Test branch: https://github.com/nkdengineer/App/tree/fix/58688

    paymentButtonOptions is re-rendered when we edit a field of the transaction. The reason it's rendered is we add the whole report as dependency:

    1. confirmPayment function which is the onPress callback has some frequently changed dependencies chatReport and moneyRequestReport

    const confirmPayment = useCallback(
    (type?: PaymentMethodType | undefined, payAsBusiness?: boolean, methodID?: number, paymentMethod?: PaymentMethod) => {
    if (!type || !chatReport) {
    return;
    }
    setPaymentType(type);
    setRequestType(CONST.IOU.REPORT_ACTION_TYPE.PAY);
    if (isDelegateAccessRestricted) {
    setIsNoDelegateAccessMenuVisible(true);
    } else if (isAnyTransactionOnHold) {
    setIsHoldMenuVisible(true);
    } else if (isInvoiceReport(moneyRequestReport)) {
    startAnimation();
    payInvoice(type, chatReport, moneyRequestReport, payAsBusiness, methodID, paymentMethod);
    } else {
    startAnimation();
    payMoneyRequest(type, chatReport, moneyRequestReport, true);
    }
    },
    [chatReport, isAnyTransactionOnHold, isDelegateAccessRestricted, moneyRequestReport, startAnimation],
    );

    1. The useMemo of paymentButtonOptions also has some frequently changed dependencies iouReport, chatReport

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

    1. We should use ref for chatReport and moneyRequestReport. Also, we can add useMemo for isAnyTransactionOnHold and isDelegateAccessRestricted

    const confirmPayment = useCallback(
    (type?: PaymentMethodType | undefined, payAsBusiness?: boolean, methodID?: number, paymentMethod?: PaymentMethod) => {
    if (!type || !chatReport) {
    return;
    }
    setPaymentType(type);
    setRequestType(CONST.IOU.REPORT_ACTION_TYPE.PAY);
    if (isDelegateAccessRestricted) {
    setIsNoDelegateAccessMenuVisible(true);
    } else if (isAnyTransactionOnHold) {
    setIsHoldMenuVisible(true);
    } else if (isInvoiceReport(moneyRequestReport)) {
    startAnimation();
    payInvoice(type, chatReport, moneyRequestReport, payAsBusiness, methodID, paymentMethod);
    } else {
    startAnimation();
    payMoneyRequest(type, chatReport, moneyRequestReport, true);
    }
    },
    [chatReport, isAnyTransactionOnHold, isDelegateAccessRestricted, moneyRequestReport, startAnimation],
    );

    1. iouReport and chatReport are only used to check as a boolean so we can create a variable for this and add this as a dependency instead
    const isExpenseReport = isExpenseReportUtil(iouReport);
    const isIndividualInvoiceRoom = isIndividualInvoiceRoomUtil(chatReport);
    

    const isExpenseReport = isExpenseReportUtil(iouReport);

    if (isIndividualInvoiceRoomUtil(chatReport)) {

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    Just is a UI logic improvement, no need the test.

    What alternative solutions did you explore? (Optional)

    We can store lastPaymentMethod to a ref when the component is rendered and don't change it anymore

    const lastPaymentMethodRef = useRef(lastPaymentMethod);
    
    useEffect(() => {
        if (!isLoadingLastPaymentMethod) {
            return;
        }
        lastPaymentMethodRef.current = lastPaymentMethod;
    }, [isLoadingLastPaymentMethod]);
    
    if (lastPaymentMethodRef.current) {
        return buttonOptions.sort((method) => (method.value === lastPaymentMethod ? -1 : 0));
    }
    

    if (lastPaymentMethod) {
    return buttonOptions.sort((method) => (method.value === lastPaymentMethod ? -1 : 0));
    }

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  11. nkdengineer commented on Mar 21, 2025

    @nkdengineer
    Contributor

    Updated proposal: Add alternative solution.

  12. 22 remaining items

  13. melvin-bot commented on Apr 7, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.23-7 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-04-14. 🎊

    For reference, here are some details about the assignees on this issue:

  14. melvin-bot commented on Apr 7, 2025

    @melvin-bot

    @DylanDylann @laurenreidexpensify @DylanDylann The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  15. added
    Daily
    and removed
    Weekly
    on Apr 14, 2025
  16. laurenreidexpensify commented on Apr 14, 2025

    @laurenreidexpensify
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment:

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion:

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal Template
    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Precondition:

    Test:

    Do we agree 👍 or 👎

  17. laurenreidexpensify commented on Apr 14, 2025

    @laurenreidexpensify
    Contributor

    @DylanDylann pls complete check list thanks

  18. melvin-bot commented on Apr 18, 2025

    @melvin-bot

    @laurenreidexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

  19. DylanDylann commented on Apr 21, 2025

    @DylanDylann
    Contributor

    Sorry for my delay. I missed the notification

  20. DylanDylann commented on Apr 21, 2025

    @DylanDylann
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: I am not sure if this is a bug while implementing, it seems like a case wasn't considered

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: NA

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Test:

    1. Open any workspace chat (Add approvals and Delay submissions are disabled).
    2. Create an expense.
    3. Open the expense report and tap on the dropdown menu on the pay button.
    4. Select "Pay Elsewhere"
    5. Edit any field on the report. (For example: Merchant)
    6. When redirected to report again, check the pay button behaviour after this action.
    7. Verify that: "Pay Elsewhere" option should remain the same after editing any of the fields in expense report.

    Do we agree 👍 or 👎

  21. melvin-bot commented on Apr 22, 2025

    @melvin-bot

    @laurenreidexpensify 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  22. laurenreidexpensify commented on Apr 22, 2025

    @laurenreidexpensify
    Contributor

    Payment Summary:

  23. moved this from Bugs and Follow Up Issues to Done in #expensify-bugson Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions