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 navigation to concierge after leaving the group #42020

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import * as Environment from '@libs/Environment/Environment';
import * as ErrorUtils from '@libs/ErrorUtils';
import Log from '@libs/Log';
import * as LoginUtils from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import type {NetworkStatus} from '@libs/NetworkConnection';
import LocalNotification from '@libs/Notification/LocalNotification';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
Expand Down Expand Up @@ -2530,10 +2530,11 @@ function navigateToMostRecentReport(currentReport: OnyxEntry<Report>) {
const isChatThread = ReportUtils.isChatThread(currentReport);
if (lastAccessedReportID) {
const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID ?? '');
// We are using index 1 here because on index 0, we'll always have the bottomTabNavigator.
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
const isFirstRoute = navigationRef?.current?.getState()?.index === 1;
// If it is not a chat thread we should call Navigation.goBack to pop the current route first before navigating to last accessed report.
if (!isChatThread) {
// Fallback to the lastAccessedReportID route, if this is first route in the navigator
Navigation.goBack(lastAccessedReportRoute);
if (!isChatThread && !isFirstRoute) {
Navigation.goBack();
}
Navigation.navigate(lastAccessedReportRoute, CONST.NAVIGATION.TYPE.FORCED_UP);
} else {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ function ReportScreen({
const didReportClose = wasReportRemoved && prevReport.statusNum === CONST.REPORT.STATUS_NUM.OPEN && report.statusNum === CONST.REPORT.STATUS_NUM.CLOSED;
const isTopLevelPolicyRoomWithNoStatus = !report.statusNum && !prevReport.parentReportID && prevReport.chatType === CONST.REPORT.CHAT_TYPE.POLICY_ROOM;
const isClosedTopLevelPolicyRoom = wasReportRemoved && prevReport.statusNum === CONST.REPORT.STATUS_NUM.OPEN && isTopLevelPolicyRoomWithNoStatus;

// Navigate to the Concierge chat if the room was removed from another device (e.g. user leaving a room or removed from a room)
if (
// non-optimistic case
Expand All @@ -526,6 +525,10 @@ function ReportScreen({
isRemovalExpectedForReportType ||
isClosedTopLevelPolicyRoom
) {
// If the report isn't focused, navigation to Concierge Chat should be avoided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please edit this slightly to explain WHY we shouldn't navigate depending on the focus state

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need here to prevent ReportScreen.tsx from handling "leaving room optimisticData" during the transition time to prevent undesired redirect to concierge when user leaves a room from the same device.

I think we can say it like this:

// We shouldn't redirect to Concierge Chat when report screen is not focused, like during the transition time,
// As this can cause undesired redirection to Concierge Chat when user leaves a room from the same device.

if (!isFocused) {
return;
}
Navigation.dismissModal();
if (Navigation.getTopmostReportId() === prevOnyxReportID) {
Navigation.setShouldPopAllStateOnUP();
Expand All @@ -540,6 +543,7 @@ function ReportScreen({
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
return;
}

Report.navigateToConciergeChat();
return;
}
Expand Down Expand Up @@ -567,6 +571,7 @@ function ReportScreen({
prevReport.chatType,
prevReport,
reportIDFromRoute,
isFocused,
]);

useEffect(() => {
Expand Down
Loading