2021-06-15 20:13:42 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2021-11-25 14:25:11 +00:00
|
|
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
2022-05-30 22:01:25 +00:00
|
|
|
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
|
|
|
|
import { useSelector } from 'react-redux';
|
2021-12-24 13:12:49 +00:00
|
|
|
import { CompositeNavigationProp } from '@react-navigation/core';
|
2021-06-15 20:13:42 +00:00
|
|
|
|
|
|
|
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';
|
2021-12-24 13:12:49 +00:00
|
|
|
import { ChatsStackParamList, DrawerParamList, NewMessageStackParamList } from '../stacks/types';
|
2022-05-30 22:01:25 +00:00
|
|
|
import { IApplicationState } from '../definitions';
|
2021-11-25 14:25:11 +00:00
|
|
|
|
2022-05-30 22:01:25 +00:00
|
|
|
type TRoute = RouteProp<ChatsStackParamList, 'AddChannelTeamView'>;
|
|
|
|
|
|
|
|
type TNavigation = CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'AddChannelTeamView'>,
|
|
|
|
CompositeNavigationProp<StackNavigationProp<NewMessageStackParamList>, StackNavigationProp<DrawerParamList>>
|
|
|
|
>;
|
2021-11-25 14:25:11 +00:00
|
|
|
|
2021-12-24 13:12:49 +00:00
|
|
|
const setHeader = ({
|
|
|
|
navigation,
|
|
|
|
isMasterDetail
|
|
|
|
}: {
|
|
|
|
navigation: StackNavigationProp<ChatsStackParamList, 'AddChannelTeamView'>;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
}) => {
|
2021-11-25 14:25:11 +00:00
|
|
|
const options: StackNavigationOptions = {
|
2021-06-15 20:13:42 +00:00
|
|
|
headerTitle: I18n.t('Add_Channel_to_Team')
|
|
|
|
};
|
|
|
|
|
|
|
|
if (isMasterDetail) {
|
|
|
|
options.headerLeft = () => <HeaderButton.CloseModal navigation={navigation} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigation.setOptions(options);
|
|
|
|
};
|
|
|
|
|
2022-05-30 22:01:25 +00:00
|
|
|
const AddChannelTeamView = () => {
|
|
|
|
const navigation = useNavigation<TNavigation>();
|
|
|
|
const isMasterDetail = useSelector((state: IApplicationState) => state.app.isMasterDetail);
|
|
|
|
const { teamChannels, teamId } = useRoute<TRoute>().params;
|
2021-06-15 20:13:42 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-12-24 13:12:49 +00:00
|
|
|
setHeader({ navigation, isMasterDetail });
|
2022-05-30 22:01:25 +00:00
|
|
|
}, [isMasterDetail, navigation]);
|
2021-06-15 20:13:42 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeAreaView testID='add-channel-team-view'>
|
|
|
|
<StatusBar />
|
|
|
|
<List.Container>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Create_New'
|
2021-10-01 18:12:19 +00:00
|
|
|
onPress={() =>
|
|
|
|
isMasterDetail
|
|
|
|
? navigation.navigate('SelectedUsersViewCreateChannel', {
|
|
|
|
nextAction: () => navigation.navigate('CreateChannelView', { teamId })
|
|
|
|
})
|
|
|
|
: navigation.navigate('SelectedUsersView', {
|
|
|
|
nextAction: () =>
|
|
|
|
navigation.navigate('ChatsStackNavigator', { screen: 'CreateChannelView', params: { teamId } })
|
|
|
|
})
|
2021-06-15 20:13:42 +00:00
|
|
|
}
|
|
|
|
testID='add-channel-team-view-create-channel'
|
|
|
|
left={() => <List.Icon name='team' />}
|
|
|
|
right={() => <List.Icon name='chevron-right' />}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Add_Existing'
|
|
|
|
onPress={() => navigation.navigate('AddExistingChannelView', { teamId, teamChannels })}
|
|
|
|
testID='add-channel-team-view-add-existing'
|
|
|
|
left={() => <List.Icon name='channel-public' />}
|
|
|
|
right={() => <List.Icon name='chevron-right' />}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Container>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-30 22:01:25 +00:00
|
|
|
export default AddChannelTeamView;
|