Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
51e1ef7
add first dynamic route + page to the app
collectioneur Feb 4, 2026
3546a82
add warnings
collectioneur Feb 4, 2026
962c1d5
fix Log import path
collectioneur Feb 4, 2026
fc957d2
add another helper function splitPathAndQuery
collectioneur Feb 5, 2026
28b620d
add test for useDynamicBackPath
collectioneur Feb 5, 2026
6c10f7b
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur Feb 5, 2026
8fb4c10
Merge branch 'collectioneur/dynamic-routes-batch-4' into collectioneu…
collectioneur Feb 6, 2026
d884620
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur Feb 6, 2026
8ebe861
add test for getPathFromState
collectioneur Feb 6, 2026
46b560f
add tests for other dynamic routes functions
collectioneur Feb 6, 2026
177d5b5
Merge branch 'collectioneur/dynamic-routes-batch-4' into collectioneu…
collectioneur Feb 6, 2026
f8cbf81
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur Feb 6, 2026
9007535
Merge branch 'main' into collectioneur/dynamic-routes-batch-5
collectioneur Feb 10, 2026
70073f5
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
collectioneur Feb 10, 2026
656851e
fix bug when hook returns back path with trailing slash
collectioneur Feb 10, 2026
367ade2
Merge branch 'collectioneur/dynamic-routes-batch-4' into collectioneu…
collectioneur Feb 10, 2026
03e6ab9
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur Feb 10, 2026
c85f89a
remove unnecessary type assertion
collectioneur Feb 11, 2026
c9b7d1f
add splitPathAndQuery tests
collectioneur Feb 11, 2026
2f9f5ba
Merge branch main into collectioneur/dynamic-routes-batch-6
collectioneur Feb 11, 2026
e10a268
remove Route type
collectioneur Feb 11, 2026
155587e
add additional guards for getMatchingFullScreenRoute
collectioneur Feb 11, 2026
119ac48
remove eslint disable
collectioneur Feb 11, 2026
90dd078
Adjust useDynamicBackPath to use useRootNavigationState
WojtekBoman Feb 12, 2026
cb49b29
Handle case when state is undefined in useDynamicPath
WojtekBoman Feb 13, 2026
178655f
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
WojtekBoman Feb 13, 2026
926f01a
Add splitPathAndQuery
WojtekBoman Feb 17, 2026
3c175e2
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
WojtekBoman Feb 17, 2026
2e70a45
Add dynamic routes config
WojtekBoman Feb 17, 2026
2671fd8
Merge branch 'dynamic-routes/fixed-batch-4' into collectioneur/dynami…
collectioneur Feb 23, 2026
781700d
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur Feb 23, 2026
3e3aca6
fix imports and fix test useDynamicBackPath
collectioneur Feb 23, 2026
74dd154
Merge branch 'main' into collectioneur/dynamic-routes-batch-5
collectioneur Feb 23, 2026
e597284
fix prettier
collectioneur Feb 23, 2026
4de4eb9
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
collectioneur Feb 23, 2026
29d7815
fix prettier
collectioneur Feb 23, 2026
898e2d1
add getMatchingFullScreenRoute tests
collectioneur Feb 23, 2026
dbc641d
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
collectioneur Feb 23, 2026
cb16295
small dynamic routes adjustments
collectioneur Feb 24, 2026
f13fbc1
Merge branch 'main' into collectioneur/dynamic-routes-batch-5
collectioneur Feb 24, 2026
a068424
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type DynamicRoutes = Record<string, DynamicRouteConfig>;
const DYNAMIC_ROUTES = {
VERIFY_ACCOUNT: {
path: 'verify-account',
entryScreens: [],
entryScreens: [SCREENS.SETTINGS.WALLET.ROOT],
},
} as const satisfies DynamicRoutes;

Expand Down Expand Up @@ -359,7 +359,6 @@ const ROUTES = {
SETTINGS_ABOUT: 'settings/about',
SETTINGS_APP_DOWNLOAD_LINKS: 'settings/about/app-download-links',
SETTINGS_WALLET: 'settings/wallet',
SETTINGS_WALLET_VERIFY_ACCOUNT: `settings/wallet/${VERIFY_ACCOUNT}`,
SETTINGS_WALLET_DOMAIN_CARD: {
route: 'settings/wallet/card/:cardID?',
getRoute: (cardID: string) => `settings/wallet/card/${cardID}` as const,
Expand Down
1 change: 0 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ const SCREENS = {

Comment thread
collectioneur marked this conversation as resolved.
Resolved
WALLET: {
ROOT: 'Settings_Wallet',
VERIFY_ACCOUNT: 'Settings_Wallet_VerifyAccount',
DOMAIN_CARD: 'Settings_Wallet_DomainCard',
DOMAIN_CARD_CONFIRM_MAGIC_CODE: 'Settings_Wallet_DomainCard_ConfirmMagicCode',
CARD_MISSING_DETAILS: 'Settings_Wallet_Card_MissingDetails',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.SETTINGS.CLOSE]: () => require<ReactComponentModule>('../../../../pages/settings/Security/CloseAccountPage').default,
[SCREENS.SETTINGS.APP_DOWNLOAD_LINKS]: () => require<ReactComponentModule>('../../../../pages/settings/AppDownloadLinks').default,
[SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS]: () => require<ReactComponentModule>('../../../../pages/settings/Profile/PersonalDetails/PersonalAddressPage').default,
[SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/VerifyAccountPage').default,
[SCREENS.SETTINGS.WALLET.DOMAIN_CARD]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/ExpensifyCardPage/index').default,
[SCREENS.SETTINGS.WALLET.DOMAIN_CARD_CONFIRM_MAGIC_CODE]: () =>
require<ReactComponentModule>('../../../../pages/settings/Wallet/ExpensifyCardPage/ExpensifyCardVerifyAccountPage').default,
Expand Down
9 changes: 4 additions & 5 deletions src/libs/Navigation/helpers/getLastSuffixFromPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Log from '@libs/Log';
import splitPathAndQuery from './splitPathAndQuery';

/**
* Extracts the last segment from a URL path, removing query parameters and trailing slashes.
Expand All @@ -7,16 +8,14 @@ import Log from '@libs/Log';
* @returns The last segment of the path as a string
*/
function getLastSuffixFromPath(path: string | undefined): string {
const pathWithoutParams = path?.split('?').at(0);
const [normalizedPath] = splitPathAndQuery(path ?? '');

if (!pathWithoutParams) {
if (!normalizedPath) {
Log.warn('[getLastSuffixFromPath.ts] Failed to parse the path, path is empty');
return '';
}

const pathWithoutTrailingSlash = pathWithoutParams.endsWith('/') ? pathWithoutParams.slice(0, -1) : pathWithoutParams;

const lastSuffix = pathWithoutTrailingSlash.split('/').pop() ?? '';
const lastSuffix = normalizedPath.split('/').pop() ?? '';

return lastSuffix;
}
Expand Down
9 changes: 3 additions & 6 deletions src/libs/Navigation/helpers/getPathFromState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import type {NavigationState, PartialState} from '@react-navigation/routers';
import {linkingConfig} from '@libs/Navigation/linkingConfig';
import {normalizedConfigs} from '@libs/Navigation/linkingConfig/config';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type {DynamicRouteSuffix} from '@src/ROUTES';
import type {Screen} from '@src/SCREENS';

type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;

const dynamicRouteEntries = Object.values(DYNAMIC_ROUTES);
const dynamicRoutePaths = new Set(dynamicRouteEntries.map(({path}) => path));

/**
* Checks if a screen name is a dynamic route screen
Expand All @@ -19,12 +21,7 @@ function isDynamicRouteScreen(screenName: Screen): boolean {
return false;
}

for (const {path} of dynamicRouteEntries) {
if (screenPath === path) {
return true;
}
}
return false;
return dynamicRoutePaths.has(screenPath as DynamicRouteSuffix);
}

const getPathFromState = (state: State): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/helpers/splitPathAndQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* and the second element is the query string (if any).
*/
function splitPathAndQuery(fullPath: string | undefined): [string | undefined, string | undefined] {
const [path, query] = fullPath?.split('?') ?? [undefined, undefined];
const [path, query] = fullPath?.split('?', 2) ?? [undefined, undefined];
const normalizedPath = path?.endsWith('/') && path.length > 1 ? path.slice(0, -1) : path;
return [normalizedPath, query];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const SETTINGS_TO_RHP: Partial<Record<keyof SettingsSplitNavigatorParamList, str
SCREENS.SETTINGS.WALLET.PERSONAL_CARD_DETAILS,
SCREENS.SETTINGS.WALLET.PERSONAL_CARD_EDIT_NAME,
SCREENS.SETTINGS.WALLET.PERSONAL_CARD_EDIT_TRANSACTION_START_DATE,
SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT,
SCREENS.SETTINGS.WALLET.TRANSFER_BALANCE,
SCREENS.SETTINGS.WALLET.CHOOSE_TRANSFER_ACCOUNT,
SCREENS.SETTINGS.WALLET.IMPORT_TRANSACTIONS,
Expand Down
4 changes: 0 additions & 4 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
path: ROUTES.SETTINGS_WALLET_CARD_MISSING_DETAILS_CONFIRM_MAGIC_CODE.route,
exact: true,
},
[SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT]: {
path: ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT,
exact: true,
},
[SCREENS.SETTINGS.WALLET.REPORT_VIRTUAL_CARD_FRAUD]: {
path: ROUTES.SETTINGS_REPORT_FRAUD.route,
exact: true,
Expand Down
1 change: 0 additions & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ type SettingsNavigatorParamList = {
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: {
policyID: string;
};
[SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT]: undefined;
[SCREENS.SETTINGS.WALLET.TRANSFER_BALANCE]: undefined;
[SCREENS.SETTINGS.WALLET.CHOOSE_TRANSFER_ACCOUNT]: undefined;
[SCREENS.SETTINGS.WALLET.IMPORT_TRANSACTIONS]: undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Welcome/OnboardingFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import CONST from '@src/CONST';
import IntlStore from '@src/languages/IntlStore';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import {hasCompletedGuidedSetupFlowSelector} from '@src/selectors/Onboarding';
import type {Locale, Onboarding} from '@src/types/onyx';

Expand Down
10 changes: 7 additions & 3 deletions src/pages/settings/DynamicVerifyAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import VerifyAccountPageBase from './VerifyAccountPageBase';

function DynamicVerifyAccountPage() {
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path);
// currently, the default behavior of this component after completing verification is to navigate back
const forwardPath = backPath;

let forwardPath = backPath;
Comment thread
collectioneur marked this conversation as resolved.
Resolved
if (backPath === ROUTES.SETTINGS_WALLET) {
forwardPath = ROUTES.SETTINGS_ENABLE_PAYMENTS;
Comment thread
collectioneur marked this conversation as resolved.
Resolved
}

return (
<VerifyAccountPageBase
navigateBackTo={backPath}
Expand Down
14 changes: 0 additions & 14 deletions src/pages/settings/Wallet/VerifyAccountPage.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/pages/settings/Wallet/WalletPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {hasDisplayableAssignedCards, maskCardNumber} from '@libs/CardUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import createDynamicRoute from '@libs/Navigation/helpers/createDynamicRoute';
import Navigation from '@libs/Navigation/Navigation';
import {formatPaymentMethods, getPaymentMethodDescription} from '@libs/PaymentUtils';
import {getDescriptionForPolicyDomainCard, hasActiveAdminWorkspaces, hasEligibleActiveAdminFromWorkspaces} from '@libs/PolicyUtils';
Expand All @@ -47,7 +48,7 @@ import {clearWalletError, clearWalletTermsError, deletePaymentCard, getPaymentMe
import {navigateToBankAccountRoute} from '@userActions/ReimbursementAccount';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
import type {CardPressHandlerParams, PaymentMethodPressHandlerParams} from './types';
Expand Down Expand Up @@ -717,7 +718,7 @@ function WalletPage() {
}

if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT);
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path));
return;
}
Navigation.navigate(ROUTES.SETTINGS_ENABLE_PAYMENTS);
Expand Down
81 changes: 81 additions & 0 deletions tests/navigation/createDynamicRouteTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import createDynamicRoute from '@libs/Navigation/helpers/createDynamicRoute';
import Navigation from '@libs/Navigation/Navigation';
import type {DynamicRouteSuffix} from '@src/ROUTES';

jest.mock('@libs/Navigation/Navigation', () => ({
getActiveRoute: jest.fn(),
}));

jest.mock('@src/ROUTES', () => ({
DYNAMIC_ROUTES: {
VERIFY_ACCOUNT: {path: 'verify-account'},
CUSTOM_FLOW: {path: 'custom-flow'},
DETAILS: {path: 'details'},
INVITE: {path: 'invite'},
FILTERS: {path: 'filters'},
},
}));

describe('createDynamicRoute', () => {
const mockGetActiveRoute = Navigation.getActiveRoute as jest.Mock;

beforeEach(() => {
jest.clearAllMocks();
});

it('should append suffix to a simple path', () => {
const activeRoute = 'settings/profile';
const suffix = 'verify-account';
const expectedPath = 'settings/profile/verify-account';

mockGetActiveRoute.mockReturnValue(activeRoute);

const result = createDynamicRoute(suffix);

expect(result).toBe(expectedPath);
expect(mockGetActiveRoute).toHaveBeenCalled();
});

it('should append suffix and preserve query parameters at the end', () => {
const activeRoute = 'report/123?sortBy=date';
const suffix = 'details';
const expectedPath = 'report/123/details?sortBy=date';

mockGetActiveRoute.mockReturnValue(activeRoute);

const result = createDynamicRoute(suffix as unknown as DynamicRouteSuffix);

expect(result).toBe(expectedPath);
});

it('should throw an error if the suffix is invalid', () => {
const suffix = 'invalid-suffix';

expect(() => createDynamicRoute(suffix as unknown as DynamicRouteSuffix)).toThrow(`The route name ${suffix} is not supported in createDynamicRoute`);
expect(mockGetActiveRoute).not.toHaveBeenCalled();
});

it('should handle paths with trailing slashes if splitPathAndQuery normalizes them', () => {
const activeRoute = 'workspace/100/';
const suffix = 'invite';
const expectedPath = 'workspace/100/invite';

mockGetActiveRoute.mockReturnValue(activeRoute);

const result = createDynamicRoute(suffix as unknown as DynamicRouteSuffix);

expect(result).toBe(expectedPath);
});

it('should correctly construct path when multiple query parameters exist', () => {
const activeRoute = 'search?q=test&type=expense';
const suffix = 'filters';
const expectedPath = 'search/filters?q=test&type=expense';

mockGetActiveRoute.mockReturnValue(activeRoute);

const result = createDynamicRoute(suffix as unknown as DynamicRouteSuffix);

expect(result).toBe(expectedPath);
});
});
39 changes: 39 additions & 0 deletions tests/navigation/getLastSuffixFromPathTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import getLastSuffixFromPath from '@libs/Navigation/helpers/getLastSuffixFromPath';

jest.mock('@libs/Log', () => ({
warn: jest.fn(),
}));

describe('getLastSuffixFromPath', () => {
it('should extract correct suffix from standard path', () => {
const path = 'settings/profile/verify-account';
const expected = 'verify-account';
const result = getLastSuffixFromPath(path);

expect(result).toBe(expected);
});

it('should handle path that is just the suffix', () => {
const path = 'verify-account';
const expected = 'verify-account';
const result = getLastSuffixFromPath(path);

expect(result).toBe(expected);
});

it('should ignore query params', () => {
const path = 'settings/profile/verify-account?sortBy=date';
const expected = 'verify-account';
const result = getLastSuffixFromPath(path);

expect(result).toBe(expected);
});

it('should handle trailing slashes', () => {
const path = 'settings/profile/verify-account/';
const expected = 'verify-account';
const result = getLastSuffixFromPath(path);

expect(result).toBe(expected);
});
});
Loading
Loading