import React, { useEffect } from 'react'; import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack'; import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; import { useSelector } from 'react-redux'; import { CompositeNavigationProp } from '@react-navigation/core'; import * as List from '../containers/List'; import StatusBar from '../containers/StatusBar'; import * as HeaderButton from '../containers/HeaderButton'; import SafeAreaView from '../containers/SafeAreaView'; import I18n from '../i18n'; import { ChatsStackParamList, DrawerParamList, NewMessageStackParamList } from '../stacks/types'; import { IApplicationState } from '../definitions'; type TRoute = RouteProp; type TNavigation = CompositeNavigationProp< StackNavigationProp, CompositeNavigationProp, StackNavigationProp> >; const setHeader = ({ navigation, isMasterDetail }: { navigation: StackNavigationProp; isMasterDetail: boolean; }) => { const options: StackNavigationOptions = { headerTitle: I18n.t('Add_Channel_to_Team') }; if (isMasterDetail) { options.headerLeft = () => ; } navigation.setOptions(options); }; const AddChannelTeamView = () => { const navigation = useNavigation(); const isMasterDetail = useSelector((state: IApplicationState) => state.app.isMasterDetail); const { params: { teamId } } = useRoute(); useEffect(() => { setHeader({ navigation, isMasterDetail }); }, [isMasterDetail, navigation]); return ( isMasterDetail ? navigation.navigate('SelectedUsersViewCreateChannel', { nextAction: () => navigation.navigate('CreateChannelView', { teamId }) }) : navigation.navigate('SelectedUsersView', { nextAction: () => navigation.navigate('ChatsStackNavigator', { screen: 'CreateChannelView', params: { teamId } }) }) } testID='add-channel-team-view-create-channel' left={() => } right={() => } /> navigation.navigate('AddExistingChannelView', { teamId })} testID='add-channel-team-view-add-existing' left={() => } right={() => } /> ); }; export default AddChannelTeamView;