Skip to content

[Merge Account] Remove the initial route from state after successful merge #60751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 13, 2025
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ const translations = {
lossOfUnsubmittedData: `Merging your accounts is irreversible and will result in the loss of any unsubmitted expenses for `,
enterMagicCode: `To continue, please enter the magic code sent to `,
errors: {
incorrect2fa: 'Incorrect two-factor authentication code. Please try again.',
incorrectMagicCode: 'Incorrect or invalid magic code. Please try again or request a new code.',
fallback: 'Something went wrong. Please try again later.',
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ const translations = {
lossOfUnsubmittedData: `Fusionar tus cuentas es irreversible y resultará en la pérdida de cualquier gasto no enviado de `,
enterMagicCode: `Para continuar, por favor introduce el código mágico enviado a `,
errors: {
incorrect2fa: 'Código de autenticación de dos factores incorrecto. Por favor, inténtalo de nuevo.',
incorrectMagicCode: 'Código mágico incorrecto o no válido. Inténtalo de nuevo o solicita otro código.',
fallback: 'Ha ocurrido un error. Por favor, inténtalo mas tarde.',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {ParamListBase} from '@react-navigation/routers';
import React from 'react';
import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator';
import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation';
import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types';
import type {
AddPersonalBankAccountNavigatorParamList,
AddUnreportedExpensesParamList,
Expand Down Expand Up @@ -47,6 +48,12 @@ import useModalStackScreenOptions from './useModalStackScreenOptions';

type Screens = Partial<Record<Screen, () => React.ComponentType>>;

const OPTIONS_PER_SCREEN: Partial<Record<Screen, PlatformStackNavigationOptions>> = {
[SCREENS.SETTINGS.MERGE_ACCOUNTS.MERGE_RESULT]: {
animationTypeForReplace: 'push',
},
};

/**
* Create a modal stack navigator with an array of sub-screens.
*
Expand All @@ -66,6 +73,7 @@ function createModalStackNavigator<ParamList extends ParamListBase>(screens: Scr
key={name}
name={name}
getComponent={(screens as Required<Screens>)[name as Screen]}
options={OPTIONS_PER_SCREEN[name as Screen]}
/>
))}
</ModalStackNavigator.Navigator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const getAuthenticationErrorKey = (err: string): TranslationPaths | null => {
}

if (err.includes('Invalid validateCode')) {
return 'mergeAccountsPage.accountValidate.errors.incorrect2fa';
return 'mergeAccountsPage.accountValidate.errors.incorrectMagicCode';
}

return 'mergeAccountsPage.accountValidate.errors.fallback';
Expand Down Expand Up @@ -137,7 +137,7 @@ function AccountValidatePage() {
<HeaderWithBackButton
title={translate('mergeAccountsPage.mergeAccount')}
onBackButtonPress={() => {
Navigation.goBack(ROUTES.SETTINGS_MERGE_ACCOUNTS.getRoute(email));
Navigation.goBack(ROUTES.SETTINGS_MERGE_ACCOUNTS.getRoute());
}}
shouldDisplayHelpButton={false}
/>
Expand Down
21 changes: 18 additions & 3 deletions src/pages/settings/Security/MergeAccounts/MergeResultPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import HybridAppModule from '@expensify/react-native-hybrid-app';
import {useRoute} from '@react-navigation/native';
import React, {useContext, useMemo} from 'react';
import React, {useContext, useEffect, useMemo} from 'react';
import {InteractionManager} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import ConfirmationPage from '@components/ConfirmationPage';
Expand All @@ -23,7 +24,7 @@ import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';

function MergeResultPage() {
const styles = useThemeStyles();
Expand Down Expand Up @@ -228,6 +229,20 @@ function MergeResultPage() {
};
}, [setRootStatusBarEnabled, login, translate, userEmailOrPhone, styles]);

useEffect(() => {
/**
* If the result is success, we need to remove the initial screen from the navigation state
* so that the back button closes the modal instead of going back to the initial screen.
*/
if (result !== CONST.MERGE_ACCOUNT_RESULTS.SUCCESS) {
return;
}

InteractionManager.runAfterInteractions(() => {
Navigation.removeScreenFromNavigationState(SCREENS.SETTINGS.MERGE_ACCOUNTS.ACCOUNT_DETAILS);
});
}, [result]);

const {
heading,
headingStyle,
Expand All @@ -253,7 +268,7 @@ function MergeResultPage() {
title={translate('mergeAccountsPage.mergeAccount')}
shouldShowBackButton={result !== CONST.MERGE_ACCOUNT_RESULTS.SUCCESS}
onBackButtonPress={() => {
Navigation.goBack(ROUTES.SETTINGS_MERGE_ACCOUNTS.getRoute(login));
Navigation.goBack(ROUTES.SETTINGS_MERGE_ACCOUNTS.getRoute());
}}
shouldDisplayHelpButton={false}
/>
Expand Down