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

[TS migration] Migrate 'Concierge' page to TypeScript #32997

30 changes: 11 additions & 19 deletions src/pages/ConciergePage.js → src/pages/ConciergePage.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
import {useFocusEffect} from '@react-navigation/native';
import PropTypes from 'prop-types';
import type {StackScreenProps} from '@react-navigation/stack';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import {OnyxEntry, withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as Report from '@userActions/Report';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import {Session} from '@src/types/onyx';

const propTypes = {
type ConciergePageOnyxProps = {
/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user authToken */
authToken: PropTypes.string,
}),
session: OnyxEntry<Session>;
};

const defaultProps = {
session: {
authToken: null,
},
};
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(props) {
function ConciergePage({session}: ConciergePageProps) {
useFocusEffect(() => {
if (_.has(props.session, 'authToken')) {
if (session?.authToken) {
// Pop the concierge loading page before opening the concierge report.
Navigation.isNavigationReady().then(() => {
Navigation.goBack(ROUTES.HOME);
Expand All @@ -43,12 +38,9 @@ function ConciergePage(props) {

return <FullScreenLoadingIndicator />;
}

ConciergePage.propTypes = propTypes;
ConciergePage.defaultProps = defaultProps;
ConciergePage.displayName = 'ConciergePage';

export default withOnyx({
export default withOnyx<ConciergePageProps, ConciergePageOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
Expand Down