Skip to content

Commit

Permalink
Merge pull request #51794 from ugogiordano/fix_44465
Browse files Browse the repository at this point in the history
Fixing duplicate Concierge chat
  • Loading branch information
aldo-expensify authored Nov 21, 2024
2 parents 74db684 + b6f73fe commit 6fa5b51
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions src/pages/ConciergePage.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
import {useFocusEffect} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect, useRef} from 'react';
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView';
import ScreenWrapper from '@components/ScreenWrapper';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as App from '@userActions/App';
import * as Report from '@userActions/Report';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {Session} from '@src/types/onyx';

type ConciergePageOnyxProps = {
/** Session info for the currently logged in user. */
session: OnyxEntry<Session>;
};

type ConciergePageProps = ConciergePageOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.CONCIERGE>;

/*
* This is a "utility page", that does this:
* - If the user is authenticated, find their concierge chat and re-route to it
* - Else re-route to the login page
*/
function ConciergePage({session}: ConciergePageProps) {
function ConciergePage() {
const styles = useThemeStyles();
const isUnmounted = useRef(false);
const {shouldUseNarrowLayout} = useResponsiveLayout();

useFocusEffect(() => {
if (session && 'authToken' in session) {
App.confirmReadyToOpenApp();
// Pop the concierge loading page before opening the concierge report.
Navigation.isNavigationReady().then(() => {
if (isUnmounted.current) {
return;
}
Report.navigateToConciergeChat(true, () => !isUnmounted.current);
});
} else {
Navigation.navigate();
}
});
const [session] = useOnyx(ONYXKEYS.SESSION);
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true});

useFocusEffect(
useCallback(() => {
if (session && 'authToken' in session) {
App.confirmReadyToOpenApp();
Navigation.isNavigationReady().then(() => {
if (isUnmounted.current || isLoadingReportData === undefined || !!isLoadingReportData) {
return;
}
Report.navigateToConciergeChat(true, () => !isUnmounted.current);
});
} else {
Navigation.navigate();
}
}, [session, isLoadingReportData]),
);

useEffect(() => {
isUnmounted.current = false;
Expand All @@ -68,8 +59,4 @@ function ConciergePage({session}: ConciergePageProps) {

ConciergePage.displayName = 'ConciergePage';

export default withOnyx<ConciergePageProps, ConciergePageOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
})(ConciergePage);
export default ConciergePage;

0 comments on commit 6fa5b51

Please sign in to comment.