Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Attachment modal is not closed when click notification #30968

Merged
merged 13 commits into from
Jan 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(() => {
arosiclair marked this conversation as resolved.
Show resolved Hide resolved
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});
}
});
});
});
}
3 changes: 2 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
Loading