Show discard confirmation modal when going back from a page with unsaved changes#54176
Conversation
|
@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] |
|
|
|
I think the idea to add the discard confirmation logic in FormProvider is a good idea, but I think we should use a prop to control whether to enable it because I'm not confident it will work smooth on all cases (for example, we set isSavedRef to true when press the submit button, but there is a submit button that navigate forward to another page instead of closing it). Let me know if I should update it. |
| navigation.goBack(); | ||
| setTimeout(() => { | ||
| isExecutingRef.current = false; | ||
| }, CONST.ANIMATED_TRANSITION); |
There was a problem hiding this comment.
isExecutingRef prevent the user to click the overlay multiple times when going back (I can't repro the multiple click issue even after removing the ref). But since we are preventing the going back when there is unsaved change, the next press won't do anything. So, we need to reset isExecutingRef back.
| const updateMerchantRef = (value: string) => { | ||
| merchantRef.current = value; | ||
| }; | ||
|
|
There was a problem hiding this comment.
I used ref here (same for desc) so it won't trigger a re-render everytime the value is updated since we only use this for getHasUnsavedChanges.
| title: '¿Descartar cambios?', | ||
| body: '¿Estás seguro de que quieres descartar los cambios que hiciste?', | ||
| confirmText: 'Descartar cambios', | ||
| }, |
There was a problem hiding this comment.
Asked for the translation verification here: https://expensify.slack.com/archives/C01GTK53T8Q/p1734322609246139
There was a problem hiding this comment.
It approved, Let's add the Slack link in author checklist Link to Slack message:
Reviewer Checklist
Screenshots/VideosAndroid: Nativea.mp4Android: mWeb Chromeaw.mp4iOS: Nativei.mp4iOS: mWeb Safariiw.mp4MacOS: Chrome / Safariw.mp4MacOS: Desktopd.mp4 |
|
Looks good overall, we just need to fix the conflict and follow ESlint new rule |
|
Done |
|
@bernhardoj can we support |
Is the modal doesn't show when using hardware back button? I want to test it but getting error again But I also think we shouldn't use
Done |
Yeah, I agree. It will be difficult to implement. |
|
@bernhardoj another conflict need to resolved. |
|
Fixed. |
|
@stitesExpensify All yours! |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/stitesExpensify in version: 9.0.82-0 🚀
|
1 similar comment
|
🚀 Deployed to staging by https://github.com/stitesExpensify in version: 9.0.82-0 🚀
|
|
🚀 Deployed to production by https://github.com/thienlnam in version: 9.0.82-12 🚀
|
| onConfirm={() => { | ||
| setIsVisible(false); | ||
| if (blockedNavigationAction.current) { | ||
| navigation.dispatch(blockedNavigationAction.current); |
There was a problem hiding this comment.
navigation obtained with useNavigation scopes only to its parent stack. We should use the full top level navigation object here (with ref). More details here #57512 .
| ); | ||
|
|
||
| return ( | ||
| <ConfirmModal |
There was a problem hiding this comment.
We weren't using shouldHandleNavigationBack here which was causing incorrect navigation back (#58449).

Explanation of Change
Fixed Issues
$ #53679
PROPOSAL: #53679 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
NOTE for web/desktop: you can test going back by pressing the overlay too
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))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
Android: Native
android.17.17.49.mp4
Android: mWeb Chrome
android.mweb.17.17.49.mp4
iOS: Native
ios.17.17.49.mp4
iOS: mWeb Safari
ios.mweb.17.17.49.mp4
MacOS: Chrome / Safari
web.merchant.mp4
web-desc.mp4
MacOS: Desktop
desktop.17.17.49.mp4