Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 36 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,38 @@ const PUBLIC_SCREENS_ROUTES = {
// Exported for identifying a url as a verify-account route, associated with a page extending the VerifyAccountPageBase component
const VERIFY_ACCOUNT = 'verify-account';

type DynamicRouteConfig = {
path: string;
entryScreens: Screen[];
};

type DynamicRoutes = Record<string, DynamicRouteConfig>;

/**
* Dynamic routes configuration for contextual navigation paths.
*
* These routes can be appended to base paths and accessed from multiple screens
* based on permission rules. They create reusable UI flows while preserving
* the underlying navigation state.
*
* Structure:
* - `path`: URL suffix appended to base routes
* - `entryScreens`: Screens allowed to access this dynamic route
*
* Example: '/workspace/123' + 'verify-account' = '/workspace/123/verify-account'
*
* Use for: verification flows, confirmations, multi-entry workflows
* Avoid for: regular navigation, single-entry workflows
*
* WIP - DO NOT USE FOR NEW ROUTES
*/
const DYNAMIC_ROUTES = {
VERIFY_ACCOUNT: {
path: 'verify-account',
entryScreens: [],
},
} as const satisfies DynamicRoutes;

const MULTIFACTOR_AUTHENTICATION_PROTECTED_ROUTES = {
FACTOR: 'multifactor-authentication/factor',
PROMPT: 'multifactor-authentication/prompt',
Expand Down Expand Up @@ -3862,7 +3894,7 @@ const SHARED_ROUTE_PARAMS: Partial<Record<Screen, string[]>> = {
[SCREENS.WORKSPACE.INITIAL]: ['backTo'],
} as const;

export {PUBLIC_SCREENS_ROUTES, SHARED_ROUTE_PARAMS, VERIFY_ACCOUNT, MULTIFACTOR_AUTHENTICATION_PROTECTED_ROUTES};
export {PUBLIC_SCREENS_ROUTES, SHARED_ROUTE_PARAMS, VERIFY_ACCOUNT, MULTIFACTOR_AUTHENTICATION_PROTECTED_ROUTES, DYNAMIC_ROUTES};
export default ROUTES;

type ReportAttachmentsRoute = typeof ROUTES.REPORT_ATTACHMENTS.route;
Expand Down Expand Up @@ -3901,6 +3933,8 @@ type Route = {
[K in keyof typeof ROUTES]: ExtractRouteName<(typeof ROUTES)[K]>;
}[keyof typeof ROUTES];

type DynamicRouteSuffix = (typeof DYNAMIC_ROUTES)[keyof typeof DYNAMIC_ROUTES]['path'];

type RoutesValidationError = 'Error: One or more routes defined within `ROUTES` have not correctly used `as const` in their `getRoute` function return value.';

/**
Expand All @@ -3912,4 +3946,4 @@ type RoutesValidationError = 'Error: One or more routes defined within `ROUTES`
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type RouteIsPlainString = AssertTypesNotEqual<string, Route, RoutesValidationError>;

export type {Route};
export type {Route, DynamicRouteSuffix};
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const SCREENS = {
TROUBLESHOOT: 'Settings_Troubleshoot',
CONSOLE: 'Settings_Console',
SHARE_LOG: 'Share_Log',
DYNAMIC_VERIFY_ACCOUNT: 'Dynamic_Verify_Account',

PROFILE: {
ROOT: 'Settings_Profile',
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import createNormalizedConfigs from '@libs/Navigation/helpers/createNormalizedCo
import type {RootNavigatorParamList} from '@navigation/types';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import ROUTES from '@src/ROUTES';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import type {Screen} from '@src/SCREENS';
import SCREENS from '@src/SCREENS';

Expand Down Expand Up @@ -399,6 +399,7 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
exact: true,
},
[SCREENS.SETTINGS.SHARE_LOG]: ROUTES.SETTINGS_SHARE_LOG.route,
[SCREENS.SETTINGS.DYNAMIC_VERIFY_ACCOUNT]: DYNAMIC_ROUTES.VERIFY_ACCOUNT.path,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: We should consider adding an ESLint rule that checks if both the field and the value include DYNAMIC_

[SCREENS.SETTINGS.PROFILE.CONTACT_METHODS]: {
path: ROUTES.SETTINGS_CONTACT_METHODS.route,
exact: true,
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type SettingsNavigatorParamList = {
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
backTo: Routes;
};
[SCREENS.SETTINGS.DYNAMIC_VERIFY_ACCOUNT]: undefined;
[SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS]: undefined;
[SCREENS.SETTINGS.WALLET.DOMAIN_CARD]: {
/** cardID of selected card */
Expand Down
Loading