Skip to content

Commit

Permalink
Merge pull request #29813 from Expensify/tgolen-routes-backto
Browse files Browse the repository at this point in the history
DRY up the code for the backTo param in routes
  • Loading branch information
bondydaa authored Oct 20, 2023
2 parents f727c90 + 8a3543d commit de74f35
Showing 1 changed file with 13 additions and 15 deletions.
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 @@ -104,13 +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) => {
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

0 comments on commit de74f35

Please sign in to comment.