Skip to content

Commit ab41b82

Browse files
authored
Merge pull request Expensify#86934 from huult/83834-migrate-workspace-tags-settings-per-diem
2 parents 9f8d61d + 6ddb8b5 commit ab41b82

9 files changed

Lines changed: 43 additions & 54 deletions

File tree

src/ROUTES.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ const DYNAMIC_ROUTES = {
320320
path: 'keyboard-shortcuts',
321321
entryScreens: ['*'],
322322
},
323+
SETTINGS_TAG_APPROVER: {
324+
path: 'tag-approver',
325+
entryScreens: [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_SETTINGS],
326+
},
327+
SETTINGS_TAG_LIST_VIEW: {
328+
path: 'tag-list/:orderWeight',
329+
entryScreens: [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_ROOT],
330+
getRoute: (orderWeight: number) => `tag-list/${orderWeight}`,
331+
},
323332
DETAILS_CONSTANT_PICKER: {
324333
path: 'constant-picker',
325334
entryScreens: [SCREENS.DEBUG.REPORT, SCREENS.DEBUG.REPORT_ACTION, SCREENS.DEBUG.TRANSACTION, SCREENS.DEBUG.TRANSACTION_VIOLATION],
@@ -1479,18 +1488,6 @@ const ROUTES = {
14791488
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
14801489
getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}` as const, backTo),
14811490
},
1482-
SETTINGS_TAG_APPROVER: {
1483-
route: 'settings/:policyID/tag/:orderWeight/:tagName/approver',
1484-
getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') =>
1485-
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
1486-
getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}/approver` as const, backTo),
1487-
},
1488-
SETTINGS_TAG_LIST_VIEW: {
1489-
route: 'settings/:policyID/tag-list/:orderWeight',
1490-
1491-
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
1492-
getRoute: (policyID: string, orderWeight: number, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tag-list/${orderWeight}` as const, backTo),
1493-
},
14941491
SETTINGS_TAG_GL_CODE: {
14951492
route: 'settings/:policyID/tag/:orderWeight/:tagName/gl-code',
14961493
getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') =>

src/SCREENS.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ const SCREENS = {
458458
SETTINGS_TAG_CREATE: 'Settings_Tag_Create',
459459
SETTINGS_TAG_EDIT: 'Settings_Tag_Edit',
460460
SETTINGS_TAG_SETTINGS: 'Settings_Tag_Settings',
461-
SETTINGS_TAG_APPROVER: 'Settings_Tag_Approver',
462-
SETTINGS_TAG_LIST_VIEW: 'Settings_Tag_List_View',
461+
DYNAMIC_SETTINGS_TAG_APPROVER: 'Dynamic_Settings_Tag_Approver',
462+
DYNAMIC_SETTINGS_TAG_LIST_VIEW: 'Dynamic_Settings_Tag_List_View',
463463
SETTINGS_TAG_GL_CODE: 'Settings_Tag_GL_Code',
464464
SETTINGS_TAGS_IMPORT: 'Settings_Tags_Import',
465465
SETTINGS_TAGS_IMPORTED: 'Settings_Tags_Imported',

src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ const TagsModalStackNavigator = createModalStackNavigator({
330330
[SCREENS.WORKSPACE.TAGS_IMPORT_OPTIONS]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/ImportTagsOptionsPage').default,
331331
[SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORTED]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/ImportedTagsPage').default,
332332
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_SETTINGS]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/TagSettingsPage').default,
333-
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/WorkspaceViewTagsPage').default,
333+
[SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_LIST_VIEW]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/WorkspaceViewTagsPage').default,
334334
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_CREATE]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/WorkspaceCreateTagPage').default,
335335
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_EDIT]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/EditTagPage').default,
336-
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/TagApproverPage').default,
336+
[SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_APPROVER]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/TagApproverPage').default,
337337
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_GL_CODE]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/TagGLCodePage').default,
338338
});
339339

src/libs/Navigation/linkingConfig/config.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,18 +1524,8 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
15241524
orderWeight: Number,
15251525
},
15261526
},
1527-
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER]: {
1528-
path: ROUTES.SETTINGS_TAG_APPROVER.route,
1529-
parse: {
1530-
orderWeight: Number,
1531-
},
1532-
},
1533-
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW]: {
1534-
path: ROUTES.SETTINGS_TAG_LIST_VIEW.route,
1535-
parse: {
1536-
orderWeight: Number,
1537-
},
1538-
},
1527+
[SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_APPROVER]: DYNAMIC_ROUTES.SETTINGS_TAG_APPROVER.path,
1528+
[SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_LIST_VIEW]: DYNAMIC_ROUTES.SETTINGS_TAG_LIST_VIEW.path,
15391529
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_GL_CODE]: {
15401530
path: ROUTES.SETTINGS_TAG_GL_CODE.route,
15411531
parse: {

src/libs/Navigation/types.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,9 @@ type SettingsNavigatorParamList = {
551551
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
552552
backTo?: Routes;
553553
};
554-
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW]: {
554+
[SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_LIST_VIEW]: {
555555
policyID: string;
556-
orderWeight: number;
557-
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
558-
backTo?: Routes;
556+
orderWeight: number | string;
559557
};
560558
[SCREENS.WORKSPACE.TAGS_EDIT]: {
561559
policyID: string;
@@ -590,12 +588,10 @@ type SettingsNavigatorParamList = {
590588
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
591589
backTo?: Routes;
592590
};
593-
[SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER]: {
591+
[SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_APPROVER]: {
594592
policyID: string;
595593
orderWeight: number;
596594
tagName: string;
597-
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
598-
backTo?: Routes;
599595
};
600596
[SCREENS.WORKSPACE.TAG_GL_CODE]: {
601597
policyID: string;

src/pages/workspace/tags/TagApproverPage.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import HeaderWithBackButton from '@components/HeaderWithBackButton';
33
import ScreenWrapper from '@components/ScreenWrapper';
44
import WorkspaceMembersSelectionList from '@components/WorkspaceMembersSelectionList';
5+
import useDynamicBackPath from '@hooks/useDynamicBackPath';
56
import useLocalize from '@hooks/useLocalize';
67
import usePolicy from '@hooks/usePolicy';
78
import useThemeStyles from '@hooks/useThemeStyles';
@@ -12,27 +13,26 @@ import {getTagApproverRule} from '@libs/PolicyUtils';
1213
import type {SettingsNavigatorParamList} from '@navigation/types';
1314
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
1415
import CONST from '@src/CONST';
15-
import ROUTES from '@src/ROUTES';
16+
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
1617
import SCREENS from '@src/SCREENS';
1718

1819
type TagApproverPageProps =
1920
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAG_APPROVER>
20-
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER>;
21+
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_APPROVER>;
2122

2223
function TagApproverPage({route}: TagApproverPageProps) {
23-
const {policyID, tagName, orderWeight, backTo} = route.params;
24+
const {policyID, tagName, orderWeight} = route.params;
2425

2526
const styles = useThemeStyles();
2627
const {translate} = useLocalize();
2728
const policy = usePolicy(policyID);
2829

2930
const tagApprover = getTagApproverRule(policy, tagName)?.approver;
30-
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER;
31+
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_APPROVER;
32+
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.SETTINGS_TAG_APPROVER.path);
3133

3234
const goBack = () => {
33-
Navigation.goBack(
34-
isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName),
35-
);
35+
Navigation.goBack(isQuickSettingsFlow ? backPath : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName));
3636
};
3737

3838
return (

src/pages/workspace/tags/TagSettingsPage.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import useLocalize from '@hooks/useLocalize';
1616
import usePolicyData from '@hooks/usePolicyData';
1717
import useThemeStyles from '@hooks/useThemeStyles';
1818
import {getLatestErrorMessageField} from '@libs/ErrorUtils';
19+
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
1920
import Navigation from '@libs/Navigation/Navigation';
2021
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
2122
import {isDisablingOrDeletingLastEnabledTag} from '@libs/OptionsListUtils';
@@ -35,7 +36,7 @@ import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
3536
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
3637
import {clearPolicyTagErrors, deletePolicyTags, setWorkspaceTagEnabled} from '@userActions/Policy/Tag';
3738
import CONST from '@src/CONST';
38-
import ROUTES from '@src/ROUTES';
39+
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
3940
import SCREENS from '@src/SCREENS';
4041

4142
type TagSettingsPageProps =
@@ -118,9 +119,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) {
118119

119120
const navigateToEditTagApprover = () => {
120121
Navigation.navigate(
121-
isQuickSettingsFlow
122-
? ROUTES.SETTINGS_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)
123-
: ROUTES.WORKSPACE_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name),
122+
isQuickSettingsFlow ? createDynamicRoute(DYNAMIC_ROUTES.SETTINGS_TAG_APPROVER.path) : ROUTES.WORKSPACE_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name),
124123
);
125124
};
126125

src/pages/workspace/tags/WorkspaceTagsPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
} from '@libs/actions/Policy/Tag';
5252
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
5353
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
54+
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
5455
import Navigation from '@libs/Navigation/Navigation';
5556
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
5657
import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types';
@@ -76,7 +77,7 @@ import variables from '@styles/variables';
7677
import {close} from '@userActions/Modal';
7778
import CONST from '@src/CONST';
7879
import ONYXKEYS from '@src/ONYXKEYS';
79-
import ROUTES from '@src/ROUTES';
80+
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
8081
import SCREENS from '@src/SCREENS';
8182
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
8283
import type DeepValueOf from '@src/types/utils/DeepValueOf';
@@ -485,7 +486,9 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
485486
}
486487
if (tag.orderWeight !== undefined) {
487488
Navigation.navigate(
488-
isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo) : ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight),
489+
isQuickSettingsFlow
490+
? createDynamicRoute(DYNAMIC_ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(tag.orderWeight))
491+
: ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight),
489492
);
490493
} else {
491494
Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, 0, tag.value, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, 0, tag.value));

src/pages/workspace/tags/WorkspaceViewTagsPage.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import CustomListHeader from '@components/SelectionListWithModal/CustomListHeade
1616
import ListItemRightCaretWithLabel from '@components/SelectionListWithModal/ListItemRightCaretWithLabel';
1717
import Switch from '@components/Switch';
1818
import useConfirmModal from '@hooks/useConfirmModal';
19+
import useDynamicBackPath from '@hooks/useDynamicBackPath';
1920
import useFilteredSelection from '@hooks/useFilteredSelection';
2021
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
2122
import useLocalize from '@hooks/useLocalize';
@@ -48,18 +49,20 @@ import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
4849
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
4950
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
5051
import CONST from '@src/CONST';
51-
import ROUTES from '@src/ROUTES';
52+
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
5253
import SCREENS from '@src/SCREENS';
5354
import type {PolicyTag} from '@src/types/onyx';
5455
import type DeepValueOf from '@src/types/utils/DeepValueOf';
5556
import type {TagListItem} from './types';
5657

5758
type WorkspaceViewTagsProps =
5859
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAG_LIST_VIEW>
59-
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW>;
60+
| PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_LIST_VIEW>;
6061

6162
function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
62-
const {policyID, backTo, orderWeight} = route.params;
63+
const {policyID, orderWeight: orderWeightParam} = route.params;
64+
const backTo = 'backTo' in route.params ? route.params.backTo : undefined;
65+
const orderWeight = Number(orderWeightParam);
6366

6467
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout for the small screen selection mode
6568
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
@@ -77,7 +80,8 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
7780
const hasDependentTags = useMemo(() => hasDependentTagsPolicyUtils(policy, policyTags), [policy, policyTags]);
7881
const isMultiLevelTags = isMultiLevelTagsPolicyUtils(policyTags);
7982
const currentPolicyTag = policyTags?.[currentTagListName];
80-
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW;
83+
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_TAGS.DYNAMIC_SETTINGS_TAG_LIST_VIEW;
84+
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.SETTINGS_TAG_LIST_VIEW.path);
8185
const fetchTags = useCallback(() => {
8286
openPolicyTagsPage(policyID);
8387
}, [policyID]);
@@ -108,7 +112,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
108112
onClearSelection: () => {
109113
setSelectedTags([]);
110114
},
111-
onNavigationCallBack: () => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : undefined),
115+
onNavigationCallBack: () => Navigation.goBack(isQuickSettingsFlow ? backPath : undefined),
112116
});
113117

114118
const updateWorkspaceTagEnabled = useCallback(
@@ -364,7 +368,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
364368
turnOffMobileSelectionMode();
365369
return;
366370
}
367-
Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : undefined);
371+
Navigation.goBack(isQuickSettingsFlow ? backPath : undefined);
368372
}}
369373
>
370374
{!shouldUseNarrowLayout && getHeaderButtons()}

0 commit comments

Comments
 (0)