diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 8ebcd8d6a5ba3..73ca58306df00 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -99,6 +99,10 @@ const DYNAMIC_ROUTES = { path: 'owner-selector', entryScreens: [], }, + REPORT_SETTINGS_WRITE_CAPABILITY: { + path: 'who-can-post', + entryScreens: [SCREENS.REPORT_SETTINGS.ROOT], + }, REPORT_SETTINGS_VISIBILITY: { path: 'visibility', entryScreens: [SCREENS.REPORT_SETTINGS.ROOT], @@ -806,12 +810,6 @@ const ROUTES = { // eslint-disable-next-line no-restricted-syntax -- Legacy route generation getRoute: (reportID: string, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/settings/notification-preferences` as const, backTo), }, - REPORT_SETTINGS_WRITE_CAPABILITY: { - route: 'r/:reportID/settings/who-can-post', - - // eslint-disable-next-line no-restricted-syntax -- Legacy route generation - getRoute: (reportID: string, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/settings/who-can-post` as const, backTo), - }, REPORT_CHANGE_APPROVER: { route: 'r/:reportID/change-approver', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 961e910964233..caab8f7a72c42 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -445,7 +445,8 @@ const SCREENS = { ROOT: 'Report_Settings_Root', NAME: 'Report_Settings_Name', NOTIFICATION_PREFERENCES: 'Report_Settings_Notification_Preferences', - WRITE_CAPABILITY: 'Report_Settings_Write_Capability', + DYNAMIC_SETTINGS_WRITE_CAPABILITY: 'Dynamic_Report_Settings_Write_Capability', + VISIBILITY: 'Report_Settings_Visibility', DYNAMIC_SETTINGS_VISIBILITY: 'Dynamic_Report_Settings_Visibility', REPORT_LAYOUT: 'Report_Settings_Report_Layout', COLUMNS: 'Report_Settings_Columns', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index a96f23e120f9f..a04102eeb2987 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -270,7 +270,7 @@ const ReportSettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/settings/Report/ReportSettingsPage').default, [SCREENS.REPORT_SETTINGS.NAME]: () => require('../../../../pages/settings/Report/NamePage').default, [SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: () => require('../../../../pages/settings/Report/NotificationPreferencePage').default, - [SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: () => require('../../../../pages/settings/Report/WriteCapabilityPage').default, + [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: () => require('../../../../pages/settings/Report/DynamicWriteCapabilityPage').default, [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY]: () => require('../../../../pages/settings/Report/DynamicVisibilityPage').default, [SCREENS.REPORT_SETTINGS.REPORT_LAYOUT]: () => require('../../../../pages/settings/Report/ReportLayoutPage').default, [SCREENS.REPORT_SETTINGS.COLUMNS]: () => require('../../../../pages/settings/Report/ReportDetailsColumnsPage').default, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 571698d0a94eb..65ac3deb94787 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -1402,9 +1402,7 @@ const config: LinkingOptions['config'] = { [SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES]: { path: ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.route, }, - [SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: { - path: ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.route, - }, + [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: DYNAMIC_ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.path, [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY]: DYNAMIC_ROUTES.REPORT_SETTINGS_VISIBILITY.path, [SCREENS.REPORT_SETTINGS.REPORT_LAYOUT]: { path: ROUTES.REPORT_SETTINGS_REPORT_LAYOUT.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 82f78383a616d..f2edd8ed65ec5 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1685,10 +1685,8 @@ type ReportSettingsNavigatorParamList = { // 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 backTo?: Routes; }; - [SCREENS.REPORT_SETTINGS.WRITE_CAPABILITY]: { + [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: { reportID: string; - // 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 - backTo?: Routes; }; [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_VISIBILITY]: { reportID: string; diff --git a/src/pages/inbox/report/withReportOrNotFound.tsx b/src/pages/inbox/report/withReportOrNotFound.tsx index 8a2e9aecb8be0..932d7207116bd 100644 --- a/src/pages/inbox/report/withReportOrNotFound.tsx +++ b/src/pages/inbox/report/withReportOrNotFound.tsx @@ -53,6 +53,7 @@ type ScreenProps = | PlatformStackScreenProps | PlatformStackScreenProps | PlatformStackScreenProps + | PlatformStackScreenProps | PlatformStackScreenProps | PlatformStackScreenProps | PlatformStackScreenProps diff --git a/src/pages/settings/Report/WriteCapabilityPage.tsx b/src/pages/settings/Report/DynamicWriteCapabilityPage.tsx similarity index 73% rename from src/pages/settings/Report/WriteCapabilityPage.tsx rename to src/pages/settings/Report/DynamicWriteCapabilityPage.tsx index 78658925b9755..07331f73a6b05 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.tsx +++ b/src/pages/settings/Report/DynamicWriteCapabilityPage.tsx @@ -1,4 +1,3 @@ -import {useRoute} from '@react-navigation/native'; import React, {useCallback} from 'react'; import type {ValueOf} from 'type-fest'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; @@ -6,23 +5,21 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/ListItem/RadioListItem'; +import useDynamicBackPath from '@hooks/useDynamicBackPath'; import useLocalize from '@hooks/useLocalize'; import useReportIsArchived from '@hooks/useReportIsArchived'; import {updateWriteCapability as updateWriteCapabilityUtil} from '@libs/actions/Report'; import Navigation from '@libs/Navigation/Navigation'; -import type {PlatformStackRouteProp, PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import {canEditWriteCapability} from '@libs/ReportUtils'; -import type {ReportSettingsNavigatorParamList} from '@navigation/types'; import withReportOrNotFound from '@pages/inbox/report/withReportOrNotFound'; import type {WithReportOrNotFoundProps} from '@pages/inbox/report/withReportOrNotFound'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; -import type SCREENS from '@src/SCREENS'; +import {DYNAMIC_ROUTES} from '@src/ROUTES'; -type WriteCapabilityPageProps = WithReportOrNotFoundProps & PlatformStackScreenProps; +type DynamicWriteCapabilityPageProps = WithReportOrNotFoundProps; -function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { - const route = useRoute>(); +function DynamicWriteCapabilityPage({report, policy}: DynamicWriteCapabilityPageProps) { + const backPath = useDynamicBackPath(DYNAMIC_ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.path); const {translate} = useLocalize(); const writeCapabilityOptions = Object.values(CONST.REPORT.WRITE_CAPABILITIES).map((value) => ({ value, @@ -34,9 +31,9 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { const isReportArchived = useReportIsArchived(report.reportID); const isAbleToEdit = canEditWriteCapability(report, policy, isReportArchived); - const goBack = useCallback(() => { - Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID, route.params.backTo)); - }, [report.reportID, route.params.backTo]); + const goBack = () => { + Navigation.goBack(backPath); + }; const updateWriteCapability = useCallback( (newValue: ValueOf) => { @@ -69,4 +66,4 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) { ); } -export default withReportOrNotFound()(WriteCapabilityPage); +export default withReportOrNotFound()(DynamicWriteCapabilityPage); diff --git a/src/pages/settings/Report/ReportSettingsPage.tsx b/src/pages/settings/Report/ReportSettingsPage.tsx index a1afbbb319ead..ec23f00ad565b 100644 --- a/src/pages/settings/Report/ReportSettingsPage.tsx +++ b/src/pages/settings/Report/ReportSettingsPage.tsx @@ -79,7 +79,7 @@ function ReportSettingsPage({report, policy, route}: ReportSettingsPageProps) { shouldShowRightIcon title={writeCapabilityText} description={translate('writeCapabilityPage.label')} - onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID, backTo))} + onPress={() => Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.path))} /> ) : (