Skip to content

fix: close popover after duplicating expense#84024

Merged
tgolen merged 8 commits intoExpensify:mainfrom
yuvrajangadsingh:fix/83708-duplicate-popover-stays-open
Mar 16, 2026
Merged

fix: close popover after duplicating expense#84024
tgolen merged 8 commits intoExpensify:mainfrom
yuvrajangadsingh:fix/83708-duplicate-popover-stays-open

Conversation

@yuvrajangadsingh
Copy link
Contributor

@yuvrajangadsingh yuvrajangadsingh commented Mar 3, 2026

Explanation of Change

The shouldCloseModalOnSelect prop on the Duplicate action was inverted. In the normal case (no violations), the OR expression evaluated to false, keeping the popover open. PopoverMenu checks shouldCloseModalOnSelect === false (strict equality), so false = keep open.

Negated the condition in both MoneyRequestHeader and MoneyReportHeader so the popover closes by default and only stays open when a violation error modal needs to show.

Fixed Issues

$ #83708
PROPOSAL: #83708 (comment)

Tests

  1. Open any expense in a self-DM (no workspace account needed)
  2. Tap the three-dot menu at the top right
  3. Tap "Duplicate expense"
  4. Verify the popover closes immediately and the duplicated expense appears without the menu stuck on top
  5. Also verify that Merge and Delete still work correctly from the same menu
  • Verify that no errors appear in the JS console

Offline tests

N/A, this is a UI state fix. The shouldCloseModalOnSelect boolean is evaluated synchronously when the menu item is tapped, no network calls involved.

QA Steps

Same as tests above.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • [x]The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • [x]A similar style doesn't already exist
    • [x]The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • [x]The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • [x]The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • [x]I verified that all the inputs inside a form are aligned with each other.
    • [x]I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

MacOS: Chrome / Safari

Bug (production):

bug-demo-final.mp4

popover stays open after clicking "Duplicate expense" from the three-dot menu.

Fix: negated shouldCloseModalOnSelect so the popover closes on duplicate. same flow, menu dismisses immediately.

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@yuvrajangadsingh
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

CLABotify added a commit to Expensify/CLA that referenced this pull request Mar 4, 2026
@yuvrajangadsingh
Copy link
Contributor Author

self-review / code walkthrough

the bug is in how shouldCloseModalOnSelect is set for the Duplicate action.

in MoneyRequestHeader.tsx (line 521), we had:

shouldCloseModalOnSelect: hasCustomUnitOutOfPolicyViolation || isPerDiemRequestOnNonDefaultWorkspace,

in MoneyReportHeader.tsx (line 1462), same pattern:

shouldCloseModalOnSelect: isPerDiemRequestOnNonDefaultWorkspace || hasCustomUnitOutOfPolicyViolation || activePolicyExpenseChat?.iouReportID === moneyRequestReport?.reportID,

the problem: in the normal case (no violations), the OR evaluates to false. PopoverMenu.tsx (line 325) checks shouldCloseModalOnSelect === false with strict equality, so false means "don't close the popover."

the fix is wrapping each in !() so the normal case returns true (close popover) and violation cases return false (keep open for error modal).

the violation handlers (lines 493-510 in MoneyRequestHeader) call showConfirmModal() with early returns before duplicateTransaction() ever runs, so they genuinely need the popover to stay open. the negation makes both paths correct.

Delete action works fine because it doesn't set shouldCloseModalOnSelect at all, which defaults to closing.

@yuvrajangadsingh yuvrajangadsingh marked this pull request as ready for review March 4, 2026 18:06
@yuvrajangadsingh yuvrajangadsingh requested review from a team as code owners March 4, 2026 18:06
@melvin-bot melvin-bot bot requested review from ahmedGaber93 and trjExpensify and removed request for a team March 4, 2026 18:07
@melvin-bot
Copy link

melvin-bot bot commented Mar 4, 2026

@ahmedGaber93 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team March 4, 2026 18:07
@yuvrajangadsingh
Copy link
Contributor Author

yuvrajangadsingh commented Mar 4, 2026

bug reproduction (production, new.expensify.com):

bug-demo-final.mp4

three-dot menu stays open after clicking Duplicate expense. popover should dismiss on click.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc0242ed10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh
Copy link
Contributor Author

@tgolen ready for review. codex caught one thing and it's been addressed, clean on re-review now.

@yuvrajangadsingh
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/83708-duplicate-popover-stays-open branch from b5d1eeb to 9d042fc Compare March 4, 2026 21:23
tgolen
tgolen previously approved these changes Mar 4, 2026
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/83708-duplicate-popover-stays-open branch 2 times, most recently from a6a4d45 to c8cd88f Compare March 5, 2026 06:27
trjExpensify
trjExpensify previously approved these changes Mar 5, 2026
Copy link
Contributor

@trjExpensify trjExpensify left a comment

Choose a reason for hiding this comment

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

Makes sense to close the popover 👍

@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/83708-duplicate-popover-stays-open branch from c8cd88f to 90db6d8 Compare March 5, 2026 15:26
@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Mar 5, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
20260310210032317.mp4
20260310205857342.mp4
Android: mWeb Chrome
20260310211420777.mp4
20260310211538629.mp4
iOS: HybridApp
iOS: mWeb Safari
20260310211859640.mp4
MacOS: Chrome / Safari
20260310202856074.mp4
20260310203013222.mp4
20260310203211158.mp4

@ahmedGaber93
Copy link
Contributor

@tgolen Sorry for joining this late 🙏

I just want to confirm that this is being discussed in the correct context. CC @trjExpensify

Based on #65948 (OP item 4), we intentionally kept the menu open on success for displaying success animation, and on failure we close it and show an error alert.

  1. We'll indicate the expense has been duplicated by:
  • Changing the Multiple Receipts icon into a checkmark temporarily and then back to the Multiple Receipts icon.
  • Changing Duplicate on the button to be Duplicated and then back to Duplicate at the same time as the icon change.

Now in this PR we are reverting that behavior. If we close the menu immediately after clicking, the animation above will no longer be visible, so it probably makes sense to remove that implementation as well.

Also, there’s no longer a need to keep shouldCloseModalOnSelect. We don’t need it anymore, on success the menu will close, and on failure it will be replaced by an error alert modal, so it will close in both cases.

@tgolen
Copy link
Contributor

tgolen commented Mar 6, 2026

OK, that's good context to know. Thank you! I didn't know about that.

I personally feel like leaving the menu open, solely for the purpose of showing the animation, isn't a very good UX. I would suggest we remove the animation and close the menu.

Looking for @trjExpensify to confirm what we would like to do here.

@trjExpensify
Copy link
Contributor

I thought the original implementation of this had the popover close after the success animation? But yeah, I can see on staging that isn't happening:

2026-03-06_10-14-36.mp4

Can we do that? I do think you need some kind of confirmation that the action was successful otherwise it just feels like a dead click in the popover.

(CC: @Expensify/design @garrettmknight for vis)

@yuvrajangadsingh
Copy link
Contributor Author

@trjExpensify got it, so the flow you want is: click Duplicate → success animation plays (checkmark + "Duplicated" text) → popover auto-closes after the animation finishes.

right now my PR just closes the popover immediately on click, which skips the animation entirely. i'll update it to keep the popover open during the animation and then close it once the animation completes.

just want to confirm before i start: are we waiting on @garrettmknight / @Expensify/design to weigh in, or should i go ahead with the "animate then close" approach?

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Mar 11, 2026

@tgolen I also agree that the hard-coded delay isn't ideal. However, since the current animation relies on setTimeout in useThrottledButtonState, it seems that the only way to close the modal before the animation ends is to use another setTimeout with a shorter delay.

That said, this is only a minor improvement, so I'm also fine with closing this PR.

@parasharrajat
Copy link
Member

What we can do is that we allow a passing handler to the throttle hook. Then, when we reset the state of the button after a timeout, we first call the handler(which closes the modal in our case), then we reset the button state.

@ahmedGaber93
Copy link
Contributor

Ahh, this looks like a better approach. @yuvrajangadsingh can we try implementing this?

@yuvrajangadsingh
Copy link
Contributor Author

@ahmedGaber93 @parasharrajat done. pushed in 027552b.

removed the shouldDelay prop and the hardcoded setTimeout from PopoverMenu entirely. useThrottledButtonState now accepts an optional onReset callback that fires when the button state resets after the animation timeout. both headers pass a memoized callback that closes the dropdown menu via the ref.

no extra props, no extra timers. the popover closes exactly when the animation finishes, driven by the same 1800ms timeout that already existed in the hook.

tgolen
tgolen previously approved these changes Mar 12, 2026
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for those improvements.

Keep popover open during the success animation (checkmark + "Duplicated"
text), then auto-close after 1.5s. Matches the pattern used in Inbox
context menu actions like "Copy link".

Reverts shouldCloseModalOnSelect to original logic: close immediately
for error cases, stay open for success animation then delayed close.
add shouldDelay to PopoverMenuItem type. when true, the popover
closes after 800ms delay (same as ReportActionContextMenu pattern)
instead of calling closeModal() which could close the wrong modal.
… shouldDelay

removes the hardcoded setTimeout delay from PopoverMenu and the
shouldDelay prop from DropdownOption. instead, useThrottledButtonState
now accepts an optional onReset callback that fires when the button
state resets after the animation, closing the popover at the right time
without any extra timers or props.
@yuvrajangadsingh yuvrajangadsingh force-pushed the fix/83708-duplicate-popover-stays-open branch from 3e039d3 to 8dcd76c Compare March 16, 2026 12:45
@ahmedGaber93
Copy link
Contributor

Tested it, works like a charm 👍

20260316192952771.mp4

@melvin-bot
Copy link

melvin-bot bot commented Mar 16, 2026

We did not find an internal engineer to review this PR, trying to assign a random engineer to #83708 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@melvin-bot melvin-bot bot requested a review from inimaga March 16, 2026 17:47
@ahmedGaber93
Copy link
Contributor

@tgolen All yours!

@tgolen tgolen merged commit 7a3681a into Expensify:main Mar 16, 2026
30 checks passed
@github-actions
Copy link
Contributor

🚧 @tgolen has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.39-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.39-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants