From fee2243e16598e18c1c73109a0b2db7cabedf373 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Sat, 21 Oct 2023 20:38:30 -0600 Subject: [PATCH 1/3] fix getBackToParam --- src/ROUTES.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index a2308cb56ef1..d66970afec6d 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -12,7 +12,7 @@ import CONST from './CONST'; * @returns */ function getBackToParam(backTo?: string): string { - return backTo ? `?backTo=${encodeURIComponent(backTo)}` : ''; + return backTo ? `backTo=${encodeURIComponent(backTo)}` : ''; } export default { @@ -30,7 +30,7 @@ export default { }, PROFILE: { route: 'a/:accountID', - getRoute: (accountID: string | number, backTo?: string) => `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): string => `bank-account/${stepToOpen}?policyID=${policyID}${getBackToParam(backTo)}`, + getRoute: (stepToOpen = '', policyID = '', backTo?: string): string => `bank-account/${stepToOpen}?policyID=${policyID}&${getBackToParam(backTo)}`, }, SETTINGS: 'settings', @@ -108,7 +108,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) => `settings/profile/personal-details/address/country?country=${country}${getBackToParam(backTo)}`, + 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 ef81f5c652dec5811ff9c4f1ef40108ac62472e2 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Sat, 21 Oct 2023 20:47:37 -0600 Subject: [PATCH 2/3] create getUrlWithBackToParam --- src/ROUTES.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index d66970afec6d..2667609236c3 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -7,12 +7,13 @@ import CONST from './CONST'; /** * 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 + * Returns the URL with an encoded URI component for the backTo param which can be added to the end of URLs * @param backTo * @returns */ -function getBackToParam(backTo?: string): string { - return backTo ? `backTo=${encodeURIComponent(backTo)}` : ''; +function getUrlWithBackToParam(url: string, backTo?: string): string { + const backToParam = backTo ? `${url.includes("?") ? "&" : "?"}backTo=${encodeURIComponent(backTo)}` : ''; + return url + backToParam; } export default { @@ -30,7 +31,7 @@ export default { }, PROFILE: { route: 'a/:accountID', - getRoute: (accountID: string | number, backTo?: string) => `a/${accountID}?${getBackToParam(backTo)}`, + getRoute: (accountID: string | number, backTo?: string) => getUrlWithBackToParam(`a/${accountID}`, backTo), }, TRANSITION_BETWEEN_APPS: 'transition', @@ -56,7 +57,7 @@ export default { BANK_ACCOUNT_PERSONAL: 'bank-account/personal', BANK_ACCOUNT_WITH_STEP_TO_OPEN: { route: 'bank-account/:stepToOpen?', - getRoute: (stepToOpen = '', policyID = '', backTo?: string): string => `bank-account/${stepToOpen}?policyID=${policyID}&${getBackToParam(backTo)}`, + getRoute: (stepToOpen = '', policyID = '', backTo?: string): string => getUrlWithBackToParam(`bank-account/${stepToOpen}?policyID=${policyID}`, backTo), }, SETTINGS: 'settings', @@ -108,7 +109,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) => `settings/profile/personal-details/address/country?country=${country}&${getBackToParam(backTo)}`, + getRoute: (country: string, backTo?: string) => getUrlWithBackToParam(`settings/profile/personal-details/address/country?country=${country}`, backTo), }, SETTINGS_CONTACT_METHODS: 'settings/profile/contact-methods', SETTINGS_CONTACT_METHOD_DETAILS: { From a498bc97a57ce5df305f2a021f2345975c9dbac2 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Sat, 21 Oct 2023 20:58:20 -0600 Subject: [PATCH 3/3] fix style --- src/ROUTES.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 2667609236c3..bcc4685368cb 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -12,7 +12,7 @@ import CONST from './CONST'; * @returns */ function getUrlWithBackToParam(url: string, backTo?: string): string { - const backToParam = backTo ? `${url.includes("?") ? "&" : "?"}backTo=${encodeURIComponent(backTo)}` : ''; + const backToParam = backTo ? `${url.includes('?') ? '&' : '?'}backTo=${encodeURIComponent(backTo)}` : ''; return url + backToParam; }