From 0c2dd4b1054989f982dd54f7a15c92b71adaa4fd Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 17 Oct 2023 11:15:18 -0600 Subject: [PATCH 1/2] DRY up the code for the backTo param in routes --- src/ROUTES.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index a677b7192fac..80d39b41c3e2 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -5,6 +5,16 @@ import CONST from './CONST'; * This is a file containing constants for all of the routes we want to be able to go to */ +/** + * This is a file containing constants for all of the routes we want to be able to go to + * Returns an encoded URI component for the backTo param which can be added to the end of URLs + * @param backTo + * @returns + */ +function getBackToParam(backTo = ''): string { + return backTo ? `?backTo=${encodeURIComponent(backTo)}` : ''; +} + export default { HOME: '', /** 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 */ @@ -20,10 +30,7 @@ export default { }, PROFILE: { route: 'a/:accountID', - getRoute: (accountID: string | number, backTo = '') => { - const backToParam = backTo ? `?backTo=${encodeURIComponent(backTo)}` : ''; - return `a/${accountID}${backToParam}`; - }, + getRoute: (accountID: string | number, backTo = '') => `a/${accountID}${getBackToParam(backTo)}`, }, TRANSITION_BETWEEN_APPS: 'transition', @@ -49,10 +56,7 @@ export default { BANK_ACCOUNT_PERSONAL: 'bank-account/personal', BANK_ACCOUNT_WITH_STEP_TO_OPEN: { route: 'bank-account/:stepToOpen?', - getRoute: (stepToOpen = '', policyID = '', backTo = ''): string => { - const backToParam = backTo ? `&backTo=${encodeURIComponent(backTo)}` : ''; - return `bank-account/${stepToOpen}?policyID=${policyID}${backToParam}`; - }, + getRoute: (stepToOpen = '', policyID = '', backTo = ''): string => `bank-account/${stepToOpen}?policyID=${policyID}${getBackToParam(backTo)}`, }, SETTINGS: 'settings', @@ -100,13 +104,7 @@ export default { SETTINGS_PERSONAL_DETAILS_ADDRESS: 'settings/profile/personal-details/address', SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY: { route: 'settings/profile/personal-details/address/country', - getRoute: (country: string, backTo?: string) => { - let route = `settings/profile/personal-details/address/country?country=${country}`; - if (backTo) { - route += `&backTo=${encodeURIComponent(backTo)}`; - } - return route; - }, + getRoute: (country: string, backTo?: string) => `settings/profile/personal-details/address/country?country=${country}${getBackToParam(backTo)}`, }, SETTINGS_CONTACT_METHODS: 'settings/profile/contact-methods', SETTINGS_CONTACT_METHOD_DETAILS: { From 8a3543d4895571cbadafa9924f899b3755723da5 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 18 Oct 2023 09:22:05 -0600 Subject: [PATCH 2/2] Use consistent type hinting --- src/ROUTES.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 80d39b41c3e2..e7efc422d37b 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -11,7 +11,7 @@ import CONST from './CONST'; * @param backTo * @returns */ -function getBackToParam(backTo = ''): string { +function getBackToParam(backTo?: string): string { return backTo ? `?backTo=${encodeURIComponent(backTo)}` : ''; } @@ -30,7 +30,7 @@ export default { }, PROFILE: { route: 'a/:accountID', - getRoute: (accountID: string | number, backTo = '') => `a/${accountID}${getBackToParam(backTo)}`, + getRoute: (accountID: string | number, backTo?: string) => `a/${accountID}${getBackToParam(backTo)}`, }, TRANSITION_BETWEEN_APPS: 'transition', @@ -56,7 +56,7 @@ export default { BANK_ACCOUNT_PERSONAL: 'bank-account/personal', BANK_ACCOUNT_WITH_STEP_TO_OPEN: { route: 'bank-account/:stepToOpen?', - getRoute: (stepToOpen = '', policyID = '', backTo = ''): string => `bank-account/${stepToOpen}?policyID=${policyID}${getBackToParam(backTo)}`, + getRoute: (stepToOpen = '', policyID = '', backTo?: string): string => `bank-account/${stepToOpen}?policyID=${policyID}${getBackToParam(backTo)}`, }, SETTINGS: 'settings',