Skip to content

Commit 59e26e4

Browse files
authored
Merge pull request #36216 from bernhardoj/fix/34755-concierge-navigation
Fix other chat is shown briefly when navigating to concierge page
2 parents c1e73ec + 50a8bb1 commit 59e26e4

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

src/libs/actions/Report.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ type ActionSubscriber = {
8686
callback: SubscriberCallback;
8787
};
8888

89+
let conciergeChatReportID: string | undefined;
8990
let currentUserAccountID = -1;
9091
Onyx.connect({
9192
key: ONYXKEYS.SESSION,
9293
callback: (value) => {
9394
// When signed out, val is undefined
9495
if (!value?.accountID) {
96+
conciergeChatReportID = undefined;
9597
return;
9698
}
9799

@@ -168,7 +170,6 @@ Onyx.connect({
168170
});
169171

170172
const allReports: OnyxCollection<Report> = {};
171-
let conciergeChatReportID: string | undefined;
172173
const typingWatchTimers: Record<string, NodeJS.Timeout> = {};
173174

174175
let reportIDDeeplinkedFromOldDot: string | undefined;
@@ -1716,24 +1717,29 @@ function updateWriteCapabilityAndNavigate(report: Report, newValue: WriteCapabil
17161717

17171718
/**
17181719
* Navigates to the 1:1 report with Concierge
1719-
*
1720-
* @param ignoreConciergeReportID - Flag to ignore conciergeChatReportID during navigation. The default behavior is to not ignore.
17211720
*/
1722-
function navigateToConciergeChat(ignoreConciergeReportID = false, shouldDismissModal = false) {
1721+
function navigateToConciergeChat(shouldDismissModal = false, shouldPopCurrentScreen = false, checkIfCurrentPageActive = () => true) {
17231722
// If conciergeChatReportID contains a concierge report ID, we navigate to the concierge chat using the stored report ID.
17241723
// Otherwise, we would find the concierge chat and navigate to it.
1725-
// Now, when user performs sign-out and a sign-in again, conciergeChatReportID may contain a stale value.
1726-
// In order to prevent navigation to a stale value, we use ignoreConciergeReportID to forcefully find and navigate to concierge chat.
1727-
if (!conciergeChatReportID || ignoreConciergeReportID) {
1724+
if (!conciergeChatReportID) {
17281725
// In order to avoid creating concierge repeatedly,
17291726
// we need to ensure that the server data has been successfully pulled
17301727
Welcome.serverDataIsReadyPromise().then(() => {
17311728
// If we don't have a chat with Concierge then create it
1729+
if (!checkIfCurrentPageActive()) {
1730+
return;
1731+
}
1732+
if (shouldPopCurrentScreen && !shouldDismissModal) {
1733+
Navigation.goBack();
1734+
}
17321735
navigateToAndOpenReport([CONST.EMAIL.CONCIERGE], shouldDismissModal);
17331736
});
17341737
} else if (shouldDismissModal) {
17351738
Navigation.dismissModal(conciergeChatReportID);
17361739
} else {
1740+
if (shouldPopCurrentScreen) {
1741+
Navigation.goBack();
1742+
}
17371743
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(conciergeChatReportID));
17381744
}
17391745
}
@@ -2213,10 +2219,7 @@ function openReportFromDeepLink(url: string, isAuthenticated: boolean) {
22132219
Session.waitForUserSignIn().then(() => {
22142220
Navigation.waitForProtectedRoutes().then(() => {
22152221
const route = ReportUtils.getRouteFromLink(url);
2216-
if (route === ROUTES.CONCIERGE) {
2217-
navigateToConciergeChat(true);
2218-
return;
2219-
}
2222+
22202223
if (route && Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route)) {
22212224
Session.signOutAndRedirectToSignIn(true);
22222225
return;

src/libs/actions/Session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ const canAccessRouteByAnonymousUser = (route: string) => {
890890
if (route.startsWith('/')) {
891891
routeRemovedReportId = routeRemovedReportId.slice(1);
892892
}
893-
const routesCanAccessByAnonymousUser = [ROUTES.SIGN_IN_MODAL, ROUTES.REPORT_WITH_ID_DETAILS.route, ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.route];
893+
const routesCanAccessByAnonymousUser = [ROUTES.SIGN_IN_MODAL, ROUTES.REPORT_WITH_ID_DETAILS.route, ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.route, ROUTES.CONCIERGE];
894894

895895
if ((routesCanAccessByAnonymousUser as string[]).includes(routeRemovedReportId)) {
896896
return true;

src/pages/ConciergePage.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import {useFocusEffect} from '@react-navigation/native';
22
import type {StackScreenProps} from '@react-navigation/stack';
3-
import React from 'react';
3+
import React, {useEffect, useRef} from 'react';
4+
import {View} from 'react-native';
45
import type {OnyxEntry} from 'react-native-onyx';
56
import {withOnyx} from 'react-native-onyx';
6-
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
7+
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
8+
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView';
9+
import ScreenWrapper from '@components/ScreenWrapper';
10+
import useThemeStyles from '@hooks/useThemeStyles';
711
import Navigation from '@libs/Navigation/Navigation';
812
import type {AuthScreensParamList} from '@libs/Navigation/types';
13+
import * as App from '@userActions/App';
914
import * as Report from '@userActions/Report';
1015
import ONYXKEYS from '@src/ONYXKEYS';
1116
import type SCREENS from '@src/SCREENS';
@@ -24,19 +29,39 @@ type ConciergePageProps = ConciergePageOnyxProps & StackScreenProps<AuthScreensP
2429
* - Else re-route to the login page
2530
*/
2631
function ConciergePage({session}: ConciergePageProps) {
32+
const styles = useThemeStyles();
33+
const isUnmounted = useRef(false);
34+
2735
useFocusEffect(() => {
2836
if (session && 'authToken' in session) {
37+
App.confirmReadyToOpenApp();
2938
// Pop the concierge loading page before opening the concierge report.
3039
Navigation.isNavigationReady().then(() => {
31-
Navigation.goBack();
32-
Report.navigateToConciergeChat();
40+
if (isUnmounted.current) {
41+
return;
42+
}
43+
Report.navigateToConciergeChat(undefined, true, () => !isUnmounted.current);
3344
});
3445
} else {
3546
Navigation.navigate();
3647
}
3748
});
3849

39-
return <FullScreenLoadingIndicator />;
50+
useEffect(
51+
() => () => {
52+
isUnmounted.current = true;
53+
},
54+
[],
55+
);
56+
57+
return (
58+
<ScreenWrapper testID={ConciergePage.displayName}>
59+
<View style={[styles.borderBottom]}>
60+
<ReportHeaderSkeletonView onBackButtonPress={Navigation.goBack} />
61+
</View>
62+
<ReportActionsSkeletonView />
63+
</ScreenWrapper>
64+
);
4065
}
4166

4267
ConciergePage.displayName = 'ConciergePage';

0 commit comments

Comments
 (0)