Skip to content

Commit

Permalink
Merge pull request #32997 from callstack-internal/pac-guerreiro/refac…
Browse files Browse the repository at this point in the history
…tor/migrate-conciergepage-to-typescript

[TS migration] Migrate 'Concierge' page to TypeScript
  • Loading branch information
techievivek authored Jan 16, 2024
2 parents bfb7f22 + ee212ba commit 30defcc
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/pages/ConciergePage.js → src/pages/ConciergePage.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import {useFocusEffect} from '@react-navigation/native';
import PropTypes from 'prop-types';
import type {StackScreenProps} from '@react-navigation/stack';
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
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 type SCREENS from '@src/SCREENS';
import type {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' in session) {
// Pop the concierge loading page before opening the concierge report.
Navigation.isNavigationReady().then(() => {
Navigation.goBack(ROUTES.HOME);
Expand All @@ -44,11 +40,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

0 comments on commit 30defcc

Please sign in to comment.