Skip to content

Commit

Permalink
Merge pull request Expensify#30968 from tienifr/fix/30446
Browse files Browse the repository at this point in the history
Fix: Attachment modal is not closed when click notification
  • Loading branch information
Joel Bettner authored Jan 23, 2024
2 parents f267baf + 4a7606f commit cfea515
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
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(() => {
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

0 comments on commit cfea515

Please sign in to comment.