Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRY up the code for the backTo param in routes #29813

Merged
merged 2 commits into from
Oct 20, 2023
Merged
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
28 changes: 13 additions & 15 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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): 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 */
Expand All @@ -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?: string) => `a/${accountID}${getBackToParam(backTo)}`,
},

TRANSITION_BETWEEN_APPS: 'transition',
Expand All @@ -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): string => `bank-account/${stepToOpen}?policyID=${policyID}${getBackToParam(backTo)}`,
},

SETTINGS: 'settings',
Expand Down Expand Up @@ -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: {
Expand Down
Loading