diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 9aa6fda5b695..635fbbe4f1aa 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -568,10 +568,12 @@ const DYNAMIC_ROUTES = { entryScreens: [SCREENS.WORKSPACE.DYNAMIC_CATEGORY_SETTINGS, SCREENS.SETTINGS_CATEGORIES.DYNAMIC_SETTINGS_CATEGORY_SETTINGS], }, NOTIFICATION_PREFERENCES: { - path: 'notification-preferences', + // `reportID` is intentionally carried as a distinct path param (`notificationReportID`) rather than + // `reportID`, so it never collides with a `reportID` inherited from the surrounding report chain's + // query string. This keeps the inherited `?reportID=` intact for back navigation. + path: 'notification-preferences/:notificationReportID', entryScreens: [SCREENS.REPORT_SETTINGS.DYNAMIC_ROOT, SCREENS.DYNAMIC_PROFILE], - getRoute: (reportID: string) => getUrlWithParams('notification-preferences', {reportID}), - queryParams: ['reportID'], + getRoute: (notificationReportID: string) => `notification-preferences/${notificationReportID}` as const, }, POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT: { path: 'sage-intacct/export', diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 2e0c4491e403..fccfc7c6725c 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1873,7 +1873,7 @@ type ReportSettingsNavigatorParamList = { reportID: string; }; [SCREENS.REPORT_SETTINGS.DYNAMIC_NOTIFICATION_PREFERENCES]: { - reportID: string; + notificationReportID: string; }; [SCREENS.REPORT_SETTINGS.DYNAMIC_SETTINGS_WRITE_CAPABILITY]: { reportID: string; diff --git a/src/pages/inbox/report/withReportOrNotFound.tsx b/src/pages/inbox/report/withReportOrNotFound.tsx index eeff6f41c0a2..3f9d1dcb7006 100644 --- a/src/pages/inbox/report/withReportOrNotFound.tsx +++ b/src/pages/inbox/report/withReportOrNotFound.tsx @@ -79,16 +79,21 @@ type WithReportOrNotFoundProps = WithReportOrNotFoundOnyxProps & { export default function (shouldRequireReportID = true): (WrappedComponent: ComponentType) => ComponentType { return function (WrappedComponent: ComponentType) { function WithReportOrNotFound(props: TProps) { + const params = props.route.params; + // Most screens carry the report ID under `reportID`. The notification-preferences screen instead + // owns its target report as a distinct path param (`notificationReportID`) so it never collides + // with a `reportID` inherited from the surrounding report chain in the URL. + const reportID = 'notificationReportID' in params ? params.notificationReportID : params.reportID; const [betas] = useOnyx(ONYXKEYS.BETAS); - const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${props.route.params.reportID}`); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); - const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${props.route.params.reportID}`); - const [reportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${props.route.params.reportID}`); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`); + const [reportLoadingState] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${reportID}`); const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const isFocused = useIsFocused(); const contentShown = React.useRef(false); - const isReportIdInRoute = !!props.route.params.reportID?.length; + const isReportIdInRoute = !!reportID?.length; const isReportLoaded = !isEmptyObject(report) && !!report?.reportID; const isReportArchived = useReportIsArchived(report?.reportID); // The `isLoadingInitialReportActions` value will become `false` only after the first OpenReport API call is finished (either succeeded or failed) @@ -102,9 +107,9 @@ export default function (shouldRequireReportID = true): Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.NOTIFICATION_PREFERENCES.path))} + onPress={() => { + if (!reportID) { + return; + } + Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.NOTIFICATION_PREFERENCES.getRoute(reportID))); + }} /> )} {shouldShowWriteCapability &&