diff --git a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts index 547ecb1de5b2..9767210b3479 100644 --- a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts +++ b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import Visibility from '@libs/Visibility'; +import * as Modal from '@userActions/Modal'; import ROUTES from '@src/ROUTES'; import backgroundRefresh from './backgroundRefresh'; import PushNotification from './index'; @@ -26,22 +27,25 @@ export default function subscribeToReportCommentPushNotifications() { Navigation.isNavigationReady() .then(Navigation.waitForProtectedRoutes) .then(() => { - try { - // If a chat is visible other than the one we are trying to navigate to, then we need to navigate back - if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) { - Navigation.goBack(ROUTES.HOME); - } + // The attachment modal remains open when navigating to the report so we need to close it + Modal.close(() => { + try { + // If a chat is visible other than the one we are trying to navigate to, then we need to navigate back + if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) { + Navigation.goBack(ROUTES.HOME); + } - Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID, reportActionID}); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(String(reportID))); - } catch (error) { - let errorMessage = String(error); - if (error instanceof Error) { - errorMessage = error.message; - } + Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID, reportActionID}); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(String(reportID))); + } catch (error) { + let errorMessage = String(error); + if (error instanceof Error) { + errorMessage = error.message; + } - Log.alert('[PushNotification] onSelected() - failed', {reportID, reportActionID, error: errorMessage}); - } + Log.alert('[PushNotification] onSelected() - failed', {reportID, reportActionID, error: errorMessage}); + } + }); }); }); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index a3cd8f52a411..310ce49912d6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -40,6 +40,7 @@ import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/Rep import type ReportAction from '@src/types/onyx/ReportAction'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import * as Modal from './Modal'; import * as Session from './Session'; import * as Welcome from './Welcome'; @@ -1870,7 +1871,7 @@ function showReportActionNotification(reportID: string, reportAction: ReportActi return; } - const onClick = () => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID)); + const onClick = () => Modal.close(() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID))); if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) { LocalNotification.showModifiedExpenseNotification(report, reportAction, onClick);