Skip to content

Commit

Permalink
Fix getting topmost route in AddPersonalBankAccountPage, add todo com…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
WojtekBoman committed Oct 18, 2024
1 parent 0cdad81 commit 2f137ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4096,6 +4096,7 @@ function navigateBackAfterDeleteTransaction(backRoute: Route | undefined, isFrom
if (!backRoute) {
return;
}
// @TODO: Refactor this method
const topmostCentralPaneRoute = Navigation.getTopMostCentralPaneRouteFromRootState();
if (topmostCentralPaneRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) {
Navigation.dismissModal();
Expand Down
19 changes: 11 additions & 8 deletions src/pages/AddPersonalBankAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlaidOAuthReceivedRedirectURI from '@libs/getPlaidOAuthReceivedRedirectURI';
import Navigation from '@libs/Navigation/Navigation';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {NavigationPartialRoute} from '@libs/Navigation/types';
import {isFullScreenRoute} from '@libs/NavigationUtils';
import * as BankAccounts from '@userActions/BankAccounts';
import * as PaymentMethods from '@userActions/PaymentMethods';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/ReimbursementAccountForm';

function AddPersonalBankAccountPage() {
Expand All @@ -26,21 +28,22 @@ function AddPersonalBankAccountPage() {
const [personalBankAccount] = useOnyx(ONYXKEYS.PERSONAL_BANK_ACCOUNT);
const [plaidData] = useOnyx(ONYXKEYS.PLAID_DATA);
const shouldShowSuccess = personalBankAccount?.shouldShowSuccess ?? false;
const topMostCentralPane = Navigation.getTopMostCentralPaneRouteFromRootState();
const topmostFullScreenRoute = navigationRef.current?.getRootState().routes.findLast((route) => isFullScreenRoute(route as NavigationPartialRoute));

// @TODO: Verify if this methods works correctly
const goBack = useCallback(() => {
switch (topMostCentralPane?.name) {
case SCREENS.SETTINGS.WALLET.ROOT:
Navigation.goBack(ROUTES.SETTINGS_WALLET, true);
switch (topmostFullScreenRoute?.name) {
case NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR:
Navigation.goBack(ROUTES.SETTINGS_WALLET);
break;
case SCREENS.REPORT:
case NAVIGATORS.REPORTS_SPLIT_NAVIGATOR:
Navigation.closeRHPFlow();
break;
default:
Navigation.goBack();
break;
}
}, [topMostCentralPane]);
}, [topmostFullScreenRoute]);

const submitBankAccountForm = useCallback(() => {
const bankAccounts = plaidData?.bankAccounts ?? [];
Expand Down

0 comments on commit 2f137ca

Please sign in to comment.