Skip to content

Commit 3cc8013

Browse files
authored
Merge pull request Expensify#85109 from huult/83368-migrate-REPORT_SETTINGS_WRITE_CAPABILITY
2 parents b89df6b + 55535fb commit 3cc8013

8 files changed

Lines changed: 20 additions & 27 deletions

File tree

src/ROUTES.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const DYNAMIC_ROUTES = {
9999
path: 'owner-selector',
100100
entryScreens: [],
101101
},
102+
REPORT_SETTINGS_WRITE_CAPABILITY: {
103+
path: 'who-can-post',
104+
entryScreens: [SCREENS.REPORT_SETTINGS.ROOT],
105+
},
102106
REPORT_SETTINGS_VISIBILITY: {
103107
path: 'visibility',
104108
entryScreens: [SCREENS.REPORT_SETTINGS.ROOT],
@@ -814,12 +818,6 @@ const ROUTES = {
814818
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
815819
getRoute: (reportID: string, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/settings/notification-preferences` as const, backTo),
816820
},
817-
REPORT_SETTINGS_WRITE_CAPABILITY: {
818-
route: 'r/:reportID/settings/who-can-post',
819-
820-
// eslint-disable-next-line no-restricted-syntax -- Legacy route generation
821-
getRoute: (reportID: string, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/settings/who-can-post` as const, backTo),
822-
},
823821
REPORT_CHANGE_APPROVER: {
824822
route: 'r/:reportID/change-approver',
825823

src/SCREENS.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ const SCREENS = {
447447
ROOT: 'Report_Settings_Root',
448448
NAME: 'Report_Settings_Name',
449449
NOTIFICATION_PREFERENCES: 'Report_Settings_Notification_Preferences',
450-
WRITE_CAPABILITY: 'Report_Settings_Write_Capability',
450+
DYNAMIC_SETTINGS_WRITE_CAPABILITY: 'Dynamic_Report_Settings_Write_Capability',
451+
VISIBILITY: 'Report_Settings_Visibility',
451452
DYNAMIC_SETTINGS_VISIBILITY: 'Dynamic_Report_Settings_Visibility',
452453
REPORT_LAYOUT: 'Report_Settings_Report_Layout',
453454
COLUMNS: 'Report_Settings_Columns',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ const ReportSettingsModalStackNavigator = createModalStackNavigator<ReportSettin
270270
[SCREENS.REPORT_SETTINGS.ROOT]: () => require<ReactComponentModule>('../../../../pages/settings/Report/ReportSettingsPage').default,
271271
[SCREENS.REPORT_SETTINGS.NAME]: () => require<ReactComponentModule>('../../../../pages/settings/Report/NamePage').default,
272272
[SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: () => require<ReactComponentModule>('../../../../pages/settings/Report/NotificationPreferencePage').default,
273-
[SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: () => require<ReactComponentModule>('../../../../pages/settings/Report/WriteCapabilityPage').default,
273+
[SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: () => require<ReactComponentModule>('../../../../pages/settings/Report/DynamicWriteCapabilityPage').default,
274274
[SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY]: () => require<ReactComponentModule>('../../../../pages/settings/Report/DynamicVisibilityPage').default,
275275
[SCREENS.REPORT_SETTINGS.REPORT_LAYOUT]: () => require<ReactComponentModule>('../../../../pages/settings/Report/ReportLayoutPage').default,
276276
[SCREENS.REPORT_SETTINGS.COLUMNS]: () => require<ReactComponentModule>('../../../../pages/settings/Report/ReportDetailsColumnsPage').default,

src/libs/Navigation/linkingConfig/config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,9 +1410,7 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
14101410
[SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: {
14111411
path: ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.route,
14121412
},
1413-
[SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: {
1414-
path: ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.route,
1415-
},
1413+
[SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: DYNAMIC_ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.path,
14161414
[SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY]: DYNAMIC_ROUTES.REPORT_SETTINGS_VISIBILITY.path,
14171415
[SCREENS.REPORT_SETTINGS.REPORT_LAYOUT]: {
14181416
path: ROUTES.REPORT_SETTINGS_REPORT_LAYOUT.route,

src/libs/Navigation/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,10 +1693,8 @@ type ReportSettingsNavigatorParamList = {
16931693
// 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
16941694
backTo?: Routes;
16951695
};
1696-
[SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: {
1696+
[SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: {
16971697
reportID: string;
1698-
// 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
1699-
backTo?: Routes;
17001698
};
17011699
[SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY]: {
17021700
reportID: string;

src/pages/inbox/report/withReportOrNotFound.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type ScreenProps =
5353
| PlatformStackScreenProps<ReportDetailsNavigatorParamList, typeof SCREENS.REPORT_DETAILS.ROOT>
5454
| PlatformStackScreenProps<ReportDetailsNavigatorParamList, typeof SCREENS.REPORT_DETAILS.SHARE_CODE>
5555
| PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.ROOT>
56+
| PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY>
5657
| PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY>
5758
| PlatformStackScreenProps<RoomMembersNavigatorParamList, typeof SCREENS.ROOM_MEMBERS.DETAILS>
5859
| PlatformStackScreenProps<ReportChangeWorkspaceNavigatorParamList, typeof SCREENS.REPORT_CHANGE_WORKSPACE.ROOT>

src/pages/settings/Report/WriteCapabilityPage.tsx renamed to src/pages/settings/Report/DynamicWriteCapabilityPage.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
import {useRoute} from '@react-navigation/native';
21
import React, {useCallback} from 'react';
32
import type {ValueOf} from 'type-fest';
43
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
54
import HeaderWithBackButton from '@components/HeaderWithBackButton';
65
import ScreenWrapper from '@components/ScreenWrapper';
76
import SelectionList from '@components/SelectionList';
87
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
8+
import useDynamicBackPath from '@hooks/useDynamicBackPath';
99
import useLocalize from '@hooks/useLocalize';
1010
import useReportIsArchived from '@hooks/useReportIsArchived';
1111
import {updateWriteCapability as updateWriteCapabilityUtil} from '@libs/actions/Report';
1212
import Navigation from '@libs/Navigation/Navigation';
13-
import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
1413
import {canEditWriteCapability} from '@libs/ReportUtils';
15-
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
1614
import withReportOrNotFound from '@pages/inbox/report/withReportOrNotFound';
1715
import type {WithReportOrNotFoundProps} from '@pages/inbox/report/withReportOrNotFound';
1816
import CONST from '@src/CONST';
19-
import ROUTES from '@src/ROUTES';
20-
import type SCREENS from '@src/SCREENS';
17+
import {DYNAMIC_ROUTES} from '@src/ROUTES';
2118

22-
type WriteCapabilityPageProps = WithReportOrNotFoundProps & PlatformStackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY>;
19+
type DynamicWriteCapabilityPageProps = WithReportOrNotFoundProps;
2320

24-
function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) {
25-
const route = useRoute<PlatformStackRouteProp<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY>>();
21+
function DynamicWriteCapabilityPage({report, policy}: DynamicWriteCapabilityPageProps) {
22+
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.path);
2623
const {translate} = useLocalize();
2724
const writeCapabilityOptions = Object.values(CONST.REPORT.WRITE_CAPABILITIES).map((value) => ({
2825
value,
@@ -34,9 +31,9 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) {
3431
const isReportArchived = useReportIsArchived(report.reportID);
3532
const isAbleToEdit = canEditWriteCapability(report, policy, isReportArchived);
3633

37-
const goBack = useCallback(() => {
38-
Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID, route.params.backTo));
39-
}, [report.reportID, route.params.backTo]);
34+
const goBack = () => {
35+
Navigation.goBack(backPath);
36+
};
4037

4138
const updateWriteCapability = useCallback(
4239
(newValue: ValueOf<typeof CONST.REPORT.WRITE_CAPABILITIES>) => {
@@ -69,4 +66,4 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) {
6966
);
7067
}
7168

72-
export default withReportOrNotFound()(WriteCapabilityPage);
69+
export default withReportOrNotFound()(DynamicWriteCapabilityPage);

src/pages/settings/Report/ReportSettingsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function ReportSettingsPage({report, policy, route}: ReportSettingsPageProps) {
7979
shouldShowRightIcon
8080
title={writeCapabilityText}
8181
description={translate('writeCapabilityPage.label')}
82-
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID, backTo))}
82+
onPress={() => Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.path))}
8383
/>
8484
) : (
8585
<View style={[styles.ph5, styles.pv3]}>

0 commit comments

Comments
 (0)