Add missing navigateBack in merchant step after save#84216
Add missing navigateBack in merchant step after save#84216
Conversation
The updateMerchant function saves data but never navigates back to the confirmation page, leaving users stuck on the merchant page. This adds navigateBack() to all three code paths, matching the pattern used by other working step pages (Date, Tag, Category). Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
The synchronous navigateBack() calls were blocked by DiscardChangesConfirmation's usePreventRemove because setHasUnsavedChanges(false) hadn't rendered yet. Use a useEffect that fires after the state update renders, matching the pattern that PR #78291 inadvertently removed. Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
|
@MelvinBot The fix addresses the right problem — A few concerns:
Suggested simpler approach — just call if (isEditingSplitBill) {
setDraftSplitTransaction(transactionID, splitDraftTransaction, {merchant: newMerchant});
- setIsSaved(true);
+ navigateBack();
return;
}
if (newMerchant === merchant || (newMerchant === '' && merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT)) {
- setIsSaved(true);
+ navigateBack();
return;
}
setMoneyRequestMerchant(transactionID, newMerchant || CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, !isEditing);
// ... editing logic ...
- setIsSaved(true);
+ navigateBack();This removes the need for the |
|
Thanks for the detailed review! The suggestion to call Why direct This component uses
By deferring Why the
On the This is a valid observation in theory, but not a practical issue: |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@MelvinBot does this bug exist in other pages, such as:
|
|
Good question — I investigated all the listed pages. Here's the breakdown:
Summary: |
|
@MelvinBot are there any other pages that we are not aware of? |
Apply the same deferred navigateBack pattern used in IOURequestStepMerchant
to IOURequestStepDescription. The description step had the same bug where
the user was stranded on the page after saving because navigateBack() was
never called. Uses isSaved state + useEffect to defer navigation until after
the render where hasUnsavedChanges becomes false, preventing
DiscardChangesConfirmation from blocking navigation.
Co-authored-by: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"} <{"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"}@users.noreply.github.com>
|
I've searched all pages that use
No other files in the codebase use the The fix for |
|
I searched all IOU request step pages that use
Why DistanceOdometer was never affected: It navigates directly with There's also In summary: This PR already covers both affected pages (Merchant and Description). No other pages are missing navigation after save. |
Explanation of Change
PR #78291 migrated
IOURequestStepMerchantfromuseBeforeRemovetousePreventRemoveinDiscardChangesConfirmation. During this migration, the olduseEffect-based navigation pattern (which usedisSavedstate +shouldNavigateAfterSaveRefto navigate back after saving) was removed but never replaced with direct navigation calls.This PR restores navigation after saving merchant by:
isSavedstate variableuseEffectthat callsnavigateBack()whenisSavedbecomestrueisSaved(true)in all three code paths ofupdateMerchant(split bill, no-change, and normal save)The
useEffectapproach is necessary (rather than callingnavigateBack()directly) becausesetHasUnsavedChanges(false)is a React state update that doesn't take effect until the next render. IfnavigateBack()were called synchronously,DiscardChangesConfirmation'susePreventRemovewould still seehasUnsavedChanges=trueand block the navigation with a "Discard changes?" dialog. By deferring navigation to auseEffect, both state updates (hasUnsavedChanges=falseandisSaved=true) are batched and rendered together, sousePreventRemoveis already disabled whennavigateBack()fires.Fixed Issues
$ #84160
PROPOSAL: #84160 (comment)
Tests
Offline tests
QA Steps
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
Web: Chrome
Tested via automated browser testing. After entering a merchant value and pressing Save, the user is immediately navigated back to the confirmation page with the merchant value correctly displayed. No "Discard changes?" dialog appears.