Add discard changes handling to spend rule merchant pages#88973
Add discard changes handling to spend rule merchant pages#88973
Conversation
SpendRuleMerchantEditPage now shows a discard changes confirmation modal when navigating back with unsaved input changes. SpendRuleMerchantsPage now silently rolls back merchant data to its original state when navigating back without pressing Save. Co-authored-by: Carlos Martins <luacmartins@users.noreply.github.com>
… React Compiler compliance Add refs to useEffect dependency array instead of disabling the rule. Refs are stable across renders so behavior is unchanged. Co-authored-by: Carlos Martins <luacmartins@users.noreply.github.com>
|
Fixed the failing React Compiler Compliance check: removed the |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
I’ll start taking a look at this one in an hour |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAd-Hoc az_recorder_20260502_155902.1.mp4CleanShot.2026-04-30.at.19.53.45.5.mp4Android: mWeb ChromeCleanShot.2026-04-30.at.19.49.21.4.mp4iOS: HybridAppCleanShot.2026-04-30.at.19.35.11.2.mp4iOS: mWeb SafariCleanShot.2026-04-30.at.19.37.52.3.mp4MacOS: Chrome / SafariCleanShot.2026-04-30.at.19.21.12.1.mp4 |
|
@MelvinBot The change set looks good, mark it as ready for review. |
|
🤖 I can't mark this PR as ready for review because The PR assignee ( |
@MelvinBot Test step: Precondition: Have an account with a workspace that has Expensify Cards and Rules enabled.
@luacmartins The current PR is ready for behavior verification on an ad hoc build |
|
🤖 Thanks for the test steps,
|
|
Running an adhoc |
|
🚧 @luacmartins has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
trjExpensify
left a comment
There was a problem hiding this comment.
Spend rules project bug fix.
|
Sorry for the delay. @suneox ready for review. |
I’ve completed the checklist, and the current behavior LGTM |
|
All yours @JS00001 |
|
Implemented the
Typecheck passes. Ready for review. |
…mpiler rule Co-authored-by: Carlos Martins <luacmartins@users.noreply.github.com>
|
Fixed the failing ESLint check: removed an |
suneox
left a comment
There was a problem hiding this comment.
The updated alternative solution, using draft form values instead of resetting the original value still works as expected.
CleanShot.2026-05-05.at.17.02.10.1.mp4
|
Ok, I updated the code to:
|
JS00001
left a comment
There was a problem hiding this comment.
I am confused by this approach, it seems really complicated. The issue is that we want to not persist the changes to the draft spend rule if 'save' is not clicked', so can we use local state & mirror it to the draft spend rule when save is clicked?
|
|
||
| const goBack = useCallback(() => navigation.goBack(), [navigation]); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
is this a 'wait for the changes to be saved, then go back'?
There was a problem hiding this comment.
Why is this needed? Why is this not part of the onSave handler?
That's the issue, yea. Generally, our flows persist values so that it survives a page refresh, so I don't think keeping it in state would help. |
|
|
||
| const goBack = useCallback(() => navigation.goBack(), [navigation]); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Why is this needed? Why is this not part of the onSave handler?
We need the navigation to happen on the render after |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 @JS00001 has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/JS00001 in version: 9.3.68-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes are required for this PR. Reason: This PR is a UX bug fix that adds a "Discard changes?" confirmation dialog and proper rollback of unsaved merchant data on the Spend Rule merchant edit pages. It doesn't introduce new features, change terminology, alter navigation paths, or modify any user-facing settings. There are no existing help site articles covering Spend Rules (the docs cover "Workspace Merchant Rules" and "Workspace Rules", which are separate features), so there is nothing to update. |
|
🚀 Deployed to production by https://github.com/francoisl in version: 9.3.68-3 🚀
|
Explanation of Change
When editing a spend rule merchant, navigating back without pressing Save still persisted the merchant data to the Onyx form state. This happened because
SpendRuleMerchantEditPagecommitted changes to Onyx on submit, butSpendRuleMerchantsPagedidn't distinguish between "saved" and "unsaved" states on back navigation.Changes:
SpendRuleMerchantEditPage: AddeduseDiscardChangesConfirmationhook that shows a "Discard changes?" confirmation modal when navigating back (in-app or browser) with unsaved input changes. Tracks adidSaveRefto skip the prompt after a successful save.SpendRuleMerchantsPage: Added a cleanup effect that silently rolls backmerchantNamesandmerchantMatchTypesto their original values (captured on mount) when the page unmounts without the user pressing Save. The Save button now sets adidSaveRefflag to skip the rollback.Fixed Issues
$ #87442
PROPOSAL: #87442 (comment)
Tests
Precondition: Have an account with a workspace that has Expensify Cards and Rules enabled.
Offline tests
N/A
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Screen.Recording.2026-05-01.at.9.01.05.AM.mov
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari