Skip to content

Commit

Permalink
Merge pull request Expensify#25748 from software-mansion-labs/ts-migr…
Browse files Browse the repository at this point in the history
…ation/ROUTES

[No QA][TS migration] Migrate 'ROUTES.js' constant to TypeScript
  • Loading branch information
johnmlee101 authored Sep 11, 2023
2 parents ae30c3c + 01c3521 commit f5b7d5c
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions src/ROUTES.js → src/ROUTES.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import lodashGet from 'lodash/get';
import {ValueOf} from 'type-fest';
import * as Url from './libs/Url';
import CONST from './CONST';

/**
* This is a file containing constants for all of the routes we want to be able to go to
*/

type ParseReportRouteParams = {
reportID: string;
isSubReportPageRoute: boolean;
};

const REPORT = 'r';
const IOU_REQUEST = 'request/new';
const IOU_BILL = 'split/new';
Expand All @@ -20,7 +26,7 @@ export default {
BANK_ACCOUNT_NEW: 'bank-account/new',
BANK_ACCOUNT_WITH_STEP_TO_OPEN: 'bank-account/:stepToOpen?',
BANK_ACCOUNT_PERSONAL: 'bank-account/personal',
getBankAccountRoute: (stepToOpen = '', policyID = '', backTo = '') => {
getBankAccountRoute: (stepToOpen = '', policyID = '', backTo = ''): string => {
const backToParam = backTo ? `&backTo=${encodeURIComponent(backTo)}` : '';
return `bank-account/${stepToOpen}?policyID=${policyID}${backToParam}`;
},
Expand All @@ -47,7 +53,7 @@ export default {
SETTINGS_ADD_DEBIT_CARD: 'settings/wallet/add-debit-card',
SETTINGS_ADD_BANK_ACCOUNT: 'settings/wallet/add-bank-account',
SETTINGS_ENABLE_PAYMENTS: 'settings/wallet/enable-payments',
getSettingsAddLoginRoute: (type) => `settings/addlogin/${type}`,
getSettingsAddLoginRoute: (type: string) => `settings/addlogin/${type}`,
SETTINGS_WALLET_TRANSFER_BALANCE: 'settings/wallet/transfer-balance',
SETTINGS_WALLET_CHOOSE_TRANSFER_ACCOUNT: 'settings/wallet/choose-transfer-account',
SETTINGS_PERSONAL_DETAILS,
Expand All @@ -56,7 +62,7 @@ export default {
SETTINGS_PERSONAL_DETAILS_ADDRESS: `${SETTINGS_PERSONAL_DETAILS}/address`,
SETTINGS_CONTACT_METHODS,
SETTINGS_CONTACT_METHOD_DETAILS: `${SETTINGS_CONTACT_METHODS}/:contactMethod/details`,
getEditContactMethodRoute: (contactMethod) => `${SETTINGS_CONTACT_METHODS}/${encodeURIComponent(contactMethod)}/details`,
getEditContactMethodRoute: (contactMethod: string) => `${SETTINGS_CONTACT_METHODS}/${encodeURIComponent(contactMethod)}/details`,
SETTINGS_NEW_CONTACT_METHOD: `${SETTINGS_CONTACT_METHODS}/new`,
SETTINGS_2FA: 'settings/security/two-factor-auth',
SETTINGS_STATUS,
Expand All @@ -67,14 +73,14 @@ export default {
REPORT,
REPORT_WITH_ID: 'r/:reportID/:reportActionID?',
EDIT_REQUEST: 'r/:threadReportID/edit/:field',
getEditRequestRoute: (threadReportID, field) => `r/${threadReportID}/edit/${field}`,
getEditRequestRoute: (threadReportID: string, field: ValueOf<typeof CONST.EDIT_REQUEST_FIELD>) => `r/${threadReportID}/edit/${field}`,
EDIT_CURRENCY_REQUEST: 'r/:threadReportID/edit/currency',
getEditRequestCurrencyRoute: (threadReportID, currency, backTo) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}`,
getReportRoute: (reportID) => `r/${reportID}`,
getEditRequestCurrencyRoute: (threadReportID: string, currency: string, backTo: string) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}`,
getReportRoute: (reportID: string) => `r/${reportID}`,
REPORT_WITH_ID_DETAILS_SHARE_CODE: 'r/:reportID/details/shareCode',
getReportShareCodeRoute: (reportID) => `r/${reportID}/details/shareCode`,
getReportShareCodeRoute: (reportID: string) => `r/${reportID}/details/shareCode`,
REPORT_ATTACHMENTS: 'r/:reportID/attachment',
getReportAttachmentRoute: (reportID, source) => `r/${reportID}/attachment?source=${encodeURI(source)}`,
getReportAttachmentRoute: (reportID: string, source: string) => `r/${reportID}/attachment?source=${encodeURI(source)}`,

/** This is a utility route used to go to the user's concierge chat, or the sign-in page if the user's not authenticated */
CONCIERGE: 'concierge',
Expand All @@ -100,64 +106,61 @@ export default {
IOU_SEND_ADD_BANK_ACCOUNT: `${IOU_SEND}/add-bank-account`,
IOU_SEND_ADD_DEBIT_CARD: `${IOU_SEND}/add-debit-card`,
IOU_SEND_ENABLE_PAYMENTS: `${IOU_SEND}/enable-payments`,
getMoneyRequestRoute: (iouType, reportID = '') => `${iouType}/new/${reportID}`,
getMoneyRequestAmountRoute: (iouType, reportID = '') => `${iouType}/new/amount/${reportID}`,
getMoneyRequestParticipantsRoute: (iouType, reportID = '') => `${iouType}/new/participants/${reportID}`,
getMoneyRequestConfirmationRoute: (iouType, reportID = '') => `${iouType}/new/confirmation/${reportID}`,
getMoneyRequestCreatedRoute: (iouType, reportID = '') => `${iouType}/new/date/${reportID}`,
getMoneyRequestCurrencyRoute: (iouType, reportID = '', currency, backTo) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}`,
getMoneyRequestDescriptionRoute: (iouType, reportID = '') => `${iouType}/new/description/${reportID}`,
getMoneyRequestCategoryRoute: (iouType, reportID = '') => `${iouType}/new/category/${reportID}`,
getMoneyRequestMerchantRoute: (iouType, reportID = '') => `${iouType}/new/merchant/${reportID}`,
getMoneyRequestDistanceTabRoute: (iouType, reportID = '') => `${iouType}/new/${reportID}/distance`,
getMoneyRequestWaypointRoute: (iouType, waypointIndex) => `${iouType}/new/waypoint/${waypointIndex}`,
getMoneyRequestRoute: (iouType: string, reportID = '') => `${iouType}/new/${reportID}`,
getMoneyRequestAmountRoute: (iouType: string, reportID = '') => `${iouType}/new/amount/${reportID}`,
getMoneyRequestParticipantsRoute: (iouType: string, reportID = '') => `${iouType}/new/participants/${reportID}`,
getMoneyRequestConfirmationRoute: (iouType: string, reportID = '') => `${iouType}/new/confirmation/${reportID}`,
getMoneyRequestCreatedRoute: (iouType: string, reportID = '') => `${iouType}/new/date/${reportID}`,
getMoneyRequestCurrencyRoute: (iouType: string, reportID: string, currency: string, backTo: string) => `${iouType}/new/currency/${reportID}?currency=${currency}&backTo=${backTo}`,
getMoneyRequestDescriptionRoute: (iouType: string, reportID = '') => `${iouType}/new/description/${reportID}`,
getMoneyRequestCategoryRoute: (iouType: string, reportID = '') => `${iouType}/new/category/${reportID}`,
SPLIT_BILL_DETAILS: `r/:reportID/split/:reportActionID`,
getSplitBillDetailsRoute: (reportID, reportActionID) => `r/${reportID}/split/${reportActionID}`,
getNewTaskRoute: (reportID) => `${NEW_TASK}/${reportID}`,
getSplitBillDetailsRoute: (reportID: string, reportActionID: string) => `r/${reportID}/split/${reportActionID}`,
getNewTaskRoute: (reportID: string) => `${NEW_TASK}/${reportID}`,
NEW_TASK_WITH_REPORT_ID: `${NEW_TASK}/:reportID?`,
TASK_TITLE: 'r/:reportID/title',
TASK_DESCRIPTION: 'r/:reportID/description',
TASK_ASSIGNEE: 'r/:reportID/assignee',
getTaskReportTitleRoute: (reportID) => `r/${reportID}/title`,
getTaskReportDescriptionRoute: (reportID) => `r/${reportID}/description`,
getTaskReportAssigneeRoute: (reportID) => `r/${reportID}/assignee`,
getTaskReportTitleRoute: (reportID: string) => `r/${reportID}/title`,
getTaskReportDescriptionRoute: (reportID: string) => `r/${reportID}/description`,
getTaskReportAssigneeRoute: (reportID: string) => `r/${reportID}/assignee`,
NEW_TASK_ASSIGNEE: `${NEW_TASK}/assignee`,
NEW_TASK_SHARE_DESTINATION: `${NEW_TASK}/share-destination`,
NEW_TASK_DETAILS: `${NEW_TASK}/details`,
NEW_TASK_TITLE: `${NEW_TASK}/title`,
NEW_TASK_DESCRIPTION: `${NEW_TASK}/description`,
FLAG_COMMENT: `flag/:reportID/:reportActionID`,
getFlagCommentRoute: (reportID, reportActionID) => `flag/${reportID}/${reportActionID}`,
getFlagCommentRoute: (reportID: string, reportActionID: string) => `flag/${reportID}/${reportActionID}`,
SEARCH: 'search',
SAVE_THE_WORLD: 'save-the-world',
I_KNOW_A_TEACHER: 'save-the-world/i-know-a-teacher',
INTRO_SCHOOL_PRINCIPAL: 'save-the-world/intro-school-principal',
I_AM_A_TEACHER: 'save-the-world/i-am-a-teacher',
DETAILS: 'details',
getDetailsRoute: (login) => `details?login=${encodeURIComponent(login)}`,
getDetailsRoute: (login: string) => `details?login=${encodeURIComponent(login)}`,
PROFILE: 'a/:accountID',
getProfileRoute: (accountID, backTo = '') => {
getProfileRoute: (accountID: string | number, backTo = '') => {
const backToParam = backTo ? `?backTo=${encodeURIComponent(backTo)}` : '';
return `a/${accountID}${backToParam}`;
},
REPORT_PARTICIPANTS: 'r/:reportID/participants',
getReportParticipantsRoute: (reportID) => `r/${reportID}/participants`,
getReportParticipantsRoute: (reportID: string) => `r/${reportID}/participants`,
REPORT_WITH_ID_DETAILS: 'r/:reportID/details',
getReportDetailsRoute: (reportID) => `r/${reportID}/details`,
getReportDetailsRoute: (reportID: string) => `r/${reportID}/details`,
REPORT_SETTINGS: 'r/:reportID/settings',
getReportSettingsRoute: (reportID) => `r/${reportID}/settings`,
getReportSettingsRoute: (reportID: string) => `r/${reportID}/settings`,
REPORT_SETTINGS_ROOM_NAME: 'r/:reportID/settings/room-name',
getReportSettingsRoomNameRoute: (reportID) => `r/${reportID}/settings/room-name`,
getReportSettingsRoomNameRoute: (reportID: string) => `r/${reportID}/settings/room-name`,
REPORT_SETTINGS_NOTIFICATION_PREFERENCES: 'r/:reportID/settings/notification-preferences',
getReportSettingsNotificationPreferencesRoute: (reportID) => `r/${reportID}/settings/notification-preferences`,
getReportSettingsNotificationPreferencesRoute: (reportID: string) => `r/${reportID}/settings/notification-preferences`,
REPORT_WELCOME_MESSAGE: 'r/:reportID/welcomeMessage',
getReportWelcomeMessageRoute: (reportID) => `r/${reportID}/welcomeMessage`,
getReportWelcomeMessageRoute: (reportID: string) => `r/${reportID}/welcomeMessage`,
REPORT_SETTINGS_WRITE_CAPABILITY: 'r/:reportID/settings/who-can-post',
getReportSettingsWriteCapabilityRoute: (reportID) => `r/${reportID}/settings/who-can-post`,
getReportSettingsWriteCapabilityRoute: (reportID: string) => `r/${reportID}/settings/who-can-post`,
TRANSITION_BETWEEN_APPS: 'transition',
VALIDATE_LOGIN: 'v/:accountID/:validateCode',
GET_ASSISTANCE: 'get-assistance/:taskID',
getGetAssistanceRoute: (taskID) => `get-assistance/${taskID}`,
getGetAssistanceRoute: (taskID: string) => `get-assistance/${taskID}`,
UNLINK_LOGIN: 'u/:accountID/:validateCode',

APPLE_SIGN_IN: 'sign-in-with-apple',
Expand All @@ -168,7 +171,7 @@ export default {
// when linking users from e.com in order to share a session in this app.
ENABLE_PAYMENTS: 'enable-payments',
WALLET_STATEMENT_WITH_DATE: 'statements/:yearMonth',
getWalletStatementWithDateRoute: (yearMonth) => `statements/${yearMonth}`,
getWalletStatementWithDateRoute: (yearMonth: string) => `statements/${yearMonth}`,
WORKSPACE_NEW: 'workspace/new',
WORKSPACE_INITIAL: 'workspace/:policyID',
WORKSPACE_INVITE: 'workspace/:policyID/invite',
Expand All @@ -182,27 +185,23 @@ export default {
WORKSPACE_TRAVEL: 'workspace/:policyID/travel',
WORKSPACE_MEMBERS: 'workspace/:policyID/members',
WORKSPACE_NEW_ROOM: 'workspace/new-room',
getWorkspaceInitialRoute: (policyID) => `workspace/${policyID}`,
getWorkspaceInviteRoute: (policyID) => `workspace/${policyID}/invite`,
getWorkspaceInviteMessageRoute: (policyID) => `workspace/${policyID}/invite-message`,
getWorkspaceSettingsRoute: (policyID) => `workspace/${policyID}/settings`,
getWorkspaceCardRoute: (policyID) => `workspace/${policyID}/card`,
getWorkspaceReimburseRoute: (policyID) => `workspace/${policyID}/reimburse`,
getWorkspaceRateAndUnitRoute: (policyID) => `workspace/${policyID}/rateandunit`,
getWorkspaceBillsRoute: (policyID) => `workspace/${policyID}/bills`,
getWorkspaceInvoicesRoute: (policyID) => `workspace/${policyID}/invoices`,
getWorkspaceTravelRoute: (policyID) => `workspace/${policyID}/travel`,
getWorkspaceMembersRoute: (policyID) => `workspace/${policyID}/members`,
getWorkspaceInitialRoute: (policyID: string) => `workspace/${policyID}`,
getWorkspaceInviteRoute: (policyID: string) => `workspace/${policyID}/invite`,
getWorkspaceInviteMessageRoute: (policyID: string) => `workspace/${policyID}/invite-message`,
getWorkspaceSettingsRoute: (policyID: string) => `workspace/${policyID}/settings`,
getWorkspaceCardRoute: (policyID: string) => `workspace/${policyID}/card`,
getWorkspaceReimburseRoute: (policyID: string) => `workspace/${policyID}/reimburse`,
getWorkspaceRateAndUnitRoute: (policyID: string) => `workspace/${policyID}/rateandunit`,
getWorkspaceBillsRoute: (policyID: string) => `workspace/${policyID}/bills`,
getWorkspaceInvoicesRoute: (policyID: string) => `workspace/${policyID}/invoices`,
getWorkspaceTravelRoute: (policyID: string) => `workspace/${policyID}/travel`,
getWorkspaceMembersRoute: (policyID: string) => `workspace/${policyID}/members`,

// These are some on-off routes that will be removed once they're no longer needed (see GH issues for details)
SAASTR: 'saastr',
SBE: 'sbe',

/**
* @param {String} route
* @returns {Object}
*/
parseReportRouteParams: (route) => {
parseReportRouteParams: (route: string): ParseReportRouteParams => {
let parsingRoute = route;
if (parsingRoute.at(0) === '/') {
// remove the first slash
Expand All @@ -215,9 +214,9 @@ export default {

const pathSegments = parsingRoute.split('/');
return {
reportID: lodashGet(pathSegments, 1),
reportID: pathSegments[1],
isSubReportPageRoute: pathSegments.length > 2,
};
},
SIGN_IN_MODAL: 'sign-in-modal',
};
} as const;

0 comments on commit f5b7d5c

Please sign in to comment.