-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ConciergePage.tsx
75 lines (67 loc) · 2.74 KB
/
ConciergePage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {useFocusEffect} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} 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) {
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();
}
});
useEffect(() => {
isUnmounted.current = false;
return () => {
isUnmounted.current = true;
};
}, []);
return (
<ScreenWrapper testID={ConciergePage.displayName}>
<View style={[styles.borderBottom, styles.appContentHeader, !shouldUseNarrowLayout && styles.headerBarDesktopHeight]}>
<ReportHeaderSkeletonView onBackButtonPress={Navigation.goBack} />
</View>
<ReportActionsSkeletonView />
</ScreenWrapper>
);
}
ConciergePage.displayName = 'ConciergePage';
export default withOnyx<ConciergePageProps, ConciergePageOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
})(ConciergePage);