2017-08-10 16:25:50 +00:00
|
|
|
import React from 'react';
|
2017-09-01 19:42:50 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-11-10 21:18:35 +00:00
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { RouteProp } from '@react-navigation/native';
|
|
|
|
import { FlatList, ScrollView, StyleSheet, Switch, Text, View, SwitchProps } from 'react-native';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2018-04-03 16:24:59 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
import * as List from '../containers/List';
|
2019-12-04 16:39:53 +00:00
|
|
|
import TextInput from '../presentation/TextInput';
|
2018-04-24 19:34:03 +00:00
|
|
|
import Loading from '../containers/Loading';
|
2018-09-25 19:28:42 +00:00
|
|
|
import { createChannelRequest as createChannelRequestAction } from '../actions/createChannel';
|
|
|
|
import { removeUser as removeUserAction } from '../actions/selectedUsers';
|
2017-09-01 20:00:31 +00:00
|
|
|
import KeyboardView from '../presentation/KeyboardView';
|
2018-04-24 19:34:03 +00:00
|
|
|
import scrollPersistTaps from '../utils/scrollPersistTaps';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../i18n';
|
2018-08-31 18:13:30 +00:00
|
|
|
import UserItem from '../presentation/UserItem';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { SWITCH_TRACK_COLOR, themes } from '../constants/colors';
|
|
|
|
import { withTheme } from '../theme';
|
2020-02-03 18:28:18 +00:00
|
|
|
import { Review } from '../utils/review';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../selectors/login';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../utils/log';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
2021-10-05 13:59:40 +00:00
|
|
|
import RocketChat from '../lib/rocketchat';
|
2021-09-13 20:41:05 +00:00
|
|
|
import sharedStyles from './Styles';
|
2018-08-31 18:13:30 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2018-09-11 16:32:52 +00:00
|
|
|
flex: 1
|
2018-08-31 18:13:30 +00:00
|
|
|
},
|
|
|
|
list: {
|
2019-12-04 16:39:53 +00:00
|
|
|
width: '100%'
|
2018-08-31 18:13:30 +00:00
|
|
|
},
|
|
|
|
input: {
|
|
|
|
height: 54,
|
|
|
|
paddingHorizontal: 18,
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 17,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textRegular
|
2018-08-31 18:13:30 +00:00
|
|
|
},
|
2020-03-26 13:14:51 +00:00
|
|
|
switchContainer: {
|
2018-08-31 18:13:30 +00:00
|
|
|
height: 54,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingHorizontal: 18
|
|
|
|
},
|
|
|
|
label: {
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 17,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textMedium
|
2018-08-31 18:13:30 +00:00
|
|
|
},
|
|
|
|
invitedHeader: {
|
|
|
|
marginTop: 18,
|
|
|
|
marginHorizontal: 15,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
invitedTitle: {
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 18,
|
|
|
|
...sharedStyles.textSemibold,
|
2018-08-31 18:13:30 +00:00
|
|
|
lineHeight: 41
|
|
|
|
},
|
|
|
|
invitedCount: {
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 14,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textRegular
|
2018-08-31 18:13:30 +00:00
|
|
|
}
|
|
|
|
});
|
2017-08-10 16:25:50 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
interface IOtherUser {
|
|
|
|
_id: string;
|
|
|
|
name: string;
|
|
|
|
fname: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ICreateFunction extends Omit<ICreateChannelViewState, 'channelName' | 'permissions'> {
|
|
|
|
name: string;
|
|
|
|
users: string[];
|
|
|
|
teamId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ICreateChannelViewState {
|
|
|
|
channelName: string;
|
|
|
|
type: boolean;
|
|
|
|
readOnly: boolean;
|
|
|
|
encrypted: boolean;
|
|
|
|
broadcast: boolean;
|
|
|
|
isTeam: boolean;
|
|
|
|
permissions: boolean[];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ICreateChannelViewProps {
|
|
|
|
navigation: StackNavigationProp<any, 'CreateChannelView'>;
|
|
|
|
route: RouteProp<{ CreateChannelView: { isTeam: boolean; teamId: string } }, 'CreateChannelView'>;
|
|
|
|
baseUrl: string;
|
|
|
|
create: (data: ICreateFunction) => void;
|
|
|
|
removeUser: (user: IOtherUser) => void;
|
|
|
|
error: object;
|
|
|
|
failure: boolean;
|
|
|
|
isFetching: boolean;
|
|
|
|
encryptionEnabled: boolean;
|
|
|
|
users: IOtherUser[];
|
|
|
|
user: {
|
|
|
|
id: string;
|
|
|
|
token: string;
|
|
|
|
roles: string[];
|
2017-09-25 13:15:28 +00:00
|
|
|
};
|
2021-11-10 21:18:35 +00:00
|
|
|
theme: string;
|
|
|
|
teamId: string;
|
|
|
|
createPublicChannelPermission: string[];
|
|
|
|
createPrivateChannelPermission: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ISwitch extends SwitchProps {
|
|
|
|
id: string;
|
|
|
|
label: string;
|
|
|
|
}
|
2017-08-10 16:25:50 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
class CreateChannelView extends React.Component<ICreateChannelViewProps, ICreateChannelViewState> {
|
|
|
|
private teamId: string;
|
|
|
|
|
|
|
|
constructor(props: ICreateChannelViewProps) {
|
2021-05-12 19:01:29 +00:00
|
|
|
super(props);
|
|
|
|
const { route } = this.props;
|
|
|
|
const isTeam = route?.params?.isTeam || false;
|
[NEW] Add/Create/Remove channel on a team (#3090)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* One way to refactor :P
* Next level refactor :)
* Fix create group dm
* Refactor renderItem
* Minor bug fixes
* Fix stories
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-05-19 21:14:42 +00:00
|
|
|
this.teamId = route?.params?.teamId;
|
2021-05-12 19:01:29 +00:00
|
|
|
this.state = {
|
|
|
|
channelName: '',
|
|
|
|
type: true,
|
|
|
|
readOnly: false,
|
|
|
|
encrypted: false,
|
|
|
|
broadcast: false,
|
2021-10-05 13:59:40 +00:00
|
|
|
isTeam,
|
|
|
|
permissions: []
|
2021-05-12 19:01:29 +00:00
|
|
|
};
|
|
|
|
this.setHeader();
|
2017-09-25 13:15:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 13:59:40 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.handleHasPermission();
|
|
|
|
}
|
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
shouldComponentUpdate(nextProps: ICreateChannelViewProps, nextState: ICreateChannelViewState) {
|
2021-10-05 13:59:40 +00:00
|
|
|
const { channelName, type, readOnly, broadcast, encrypted, permissions } = this.state;
|
|
|
|
const { users, isFetching, encryptionEnabled, theme, createPublicChannelPermission, createPrivateChannelPermission } =
|
|
|
|
this.props;
|
2019-12-04 16:39:53 +00:00
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextState.channelName !== channelName) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.type !== type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.readOnly !== readOnly) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-09-11 14:31:38 +00:00
|
|
|
if (nextState.encrypted !== encrypted) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextState.broadcast !== broadcast) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-10-05 13:59:40 +00:00
|
|
|
if (nextState.permissions !== permissions) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.isFetching !== isFetching) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-20 17:34:01 +00:00
|
|
|
if (nextProps.encryptionEnabled !== encryptionEnabled) {
|
2020-09-11 14:31:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-05 13:59:40 +00:00
|
|
|
if (!dequal(nextProps.createPublicChannelPermission, createPublicChannelPermission)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!dequal(nextProps.createPrivateChannelPermission, createPrivateChannelPermission)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.users, users)) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
componentDidUpdate(prevProps: ICreateChannelViewProps) {
|
2021-10-05 13:59:40 +00:00
|
|
|
const { createPublicChannelPermission, createPrivateChannelPermission } = this.props;
|
|
|
|
if (
|
|
|
|
!dequal(createPublicChannelPermission, prevProps.createPublicChannelPermission) ||
|
|
|
|
!dequal(createPrivateChannelPermission, prevProps.createPrivateChannelPermission)
|
|
|
|
) {
|
|
|
|
this.handleHasPermission();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 19:01:29 +00:00
|
|
|
setHeader = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
const { isTeam } = this.state;
|
|
|
|
|
|
|
|
navigation.setOptions({
|
|
|
|
title: isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel')
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-12 19:01:29 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
toggleRightButton = (channelName: string) => {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { navigation } = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.setOptions({
|
2021-09-13 20:41:05 +00:00
|
|
|
headerRight: () =>
|
|
|
|
channelName.trim().length > 0 && (
|
|
|
|
<HeaderButton.Container>
|
|
|
|
<HeaderButton.Item title={I18n.t('Create')} onPress={this.submit} testID='create-channel-submit' />
|
|
|
|
</HeaderButton.Container>
|
|
|
|
)
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
onChangeText = (channelName: string) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.toggleRightButton(channelName);
|
2018-08-31 18:13:30 +00:00
|
|
|
this.setState({ channelName });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-31 18:13:30 +00:00
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
submit = () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { channelName, type, readOnly, broadcast, encrypted, isTeam } = this.state;
|
|
|
|
const { users: usersProps, isFetching, create } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
if (!channelName.trim() || isFetching) {
|
2018-09-25 19:28:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-09-25 13:15:28 +00:00
|
|
|
|
|
|
|
// transform users object into array of usernames
|
2018-09-25 19:28:42 +00:00
|
|
|
const users = usersProps.map(user => user.name);
|
2017-09-25 13:15:28 +00:00
|
|
|
|
2021-05-12 19:01:29 +00:00
|
|
|
// create channel or team
|
2018-09-25 19:28:42 +00:00
|
|
|
create({
|
2021-09-13 20:41:05 +00:00
|
|
|
name: channelName,
|
|
|
|
users,
|
|
|
|
type,
|
|
|
|
readOnly,
|
|
|
|
broadcast,
|
|
|
|
encrypted,
|
|
|
|
isTeam,
|
|
|
|
teamId: this.teamId
|
2018-05-24 20:17:45 +00:00
|
|
|
});
|
2020-02-03 18:28:18 +00:00
|
|
|
|
|
|
|
Review.pushPositiveEvent();
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-08-10 16:25:50 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
removeUser = (user: IOtherUser) => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.CR_REMOVE_USER);
|
2020-03-03 21:25:23 +00:00
|
|
|
const { removeUser } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
removeUser(user);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
renderSwitch = ({ id, value, label, onValueChange, disabled = false }: ISwitch) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
2020-03-26 13:14:51 +00:00
|
|
|
<View style={[styles.switchContainer, { backgroundColor: themes[theme].backgroundColor }]}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.label, { color: themes[theme].titleText }]}>{I18n.t(label)}</Text>
|
|
|
|
<Switch
|
|
|
|
value={value}
|
|
|
|
onValueChange={onValueChange}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`create-channel-${id}`}
|
2019-12-04 16:39:53 +00:00
|
|
|
trackColor={SWITCH_TRACK_COLOR}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-05-24 20:17:45 +00:00
|
|
|
|
2021-10-05 13:59:40 +00:00
|
|
|
handleHasPermission = async () => {
|
|
|
|
const { createPublicChannelPermission, createPrivateChannelPermission } = this.props;
|
|
|
|
const permissions = [createPublicChannelPermission, createPrivateChannelPermission];
|
|
|
|
const permissionsToCreate = await RocketChat.hasPermission(permissions);
|
|
|
|
this.setState({ permissions: permissionsToCreate });
|
|
|
|
};
|
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
renderType() {
|
2021-10-05 13:59:40 +00:00
|
|
|
const { type, isTeam, permissions } = this.state;
|
|
|
|
const isDisabled = permissions.filter(r => r === true).length <= 1;
|
2021-05-12 19:01:29 +00:00
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
return this.renderSwitch({
|
|
|
|
id: 'type',
|
2021-10-05 13:59:40 +00:00
|
|
|
value: permissions[1] ? type : false,
|
|
|
|
disabled: isDisabled,
|
2021-05-12 19:01:29 +00:00
|
|
|
label: isTeam ? 'Private_Team' : 'Private_Channel',
|
2021-11-10 21:18:35 +00:00
|
|
|
onValueChange: (value: boolean) => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.CR_TOGGLE_TYPE);
|
2020-09-11 14:31:38 +00:00
|
|
|
// If we set the channel as public, encrypted status should be false
|
|
|
|
this.setState(({ encrypted }) => ({ type: value, encrypted: value && encrypted }));
|
2020-07-30 13:26:17 +00:00
|
|
|
}
|
2018-05-24 20:17:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderReadOnly() {
|
2021-05-12 19:01:29 +00:00
|
|
|
const { readOnly, broadcast, isTeam } = this.state;
|
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
return this.renderSwitch({
|
|
|
|
id: 'readonly',
|
|
|
|
value: readOnly,
|
2021-05-12 19:01:29 +00:00
|
|
|
label: isTeam ? 'Read_Only_Team' : 'Read_Only_Channel',
|
2021-09-13 20:41:05 +00:00
|
|
|
onValueChange: value => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.CR_TOGGLE_READ_ONLY);
|
2020-07-30 13:26:17 +00:00
|
|
|
this.setState({ readOnly: value });
|
|
|
|
},
|
2018-05-24 20:17:45 +00:00
|
|
|
disabled: broadcast
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
renderEncrypted() {
|
|
|
|
const { type, encrypted } = this.state;
|
2021-01-20 17:34:01 +00:00
|
|
|
const { encryptionEnabled } = this.props;
|
2020-09-11 14:31:38 +00:00
|
|
|
|
2021-01-20 17:34:01 +00:00
|
|
|
if (!encryptionEnabled) {
|
2020-09-11 14:31:38 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.renderSwitch({
|
|
|
|
id: 'encrypted',
|
|
|
|
value: encrypted,
|
|
|
|
label: 'Encrypted',
|
2021-09-13 20:41:05 +00:00
|
|
|
onValueChange: value => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.CR_TOGGLE_ENCRYPTED);
|
2020-09-11 14:31:38 +00:00
|
|
|
this.setState({ encrypted: value });
|
|
|
|
},
|
|
|
|
disabled: !type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
renderBroadcast() {
|
2021-05-12 19:01:29 +00:00
|
|
|
const { broadcast, readOnly, isTeam } = this.state;
|
|
|
|
|
2018-05-24 20:17:45 +00:00
|
|
|
return this.renderSwitch({
|
|
|
|
id: 'broadcast',
|
|
|
|
value: broadcast,
|
2021-05-12 19:01:29 +00:00
|
|
|
label: isTeam ? 'Broadcast_Team' : 'Broadcast_Channel',
|
2021-09-13 20:41:05 +00:00
|
|
|
onValueChange: value => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.CR_TOGGLE_BROADCAST);
|
2018-05-24 20:17:45 +00:00
|
|
|
this.setState({
|
|
|
|
broadcast: value,
|
|
|
|
readOnly: value ? true : readOnly
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
renderItem = ({ item }: { item: IOtherUser }) => {
|
|
|
|
const { theme } = this.props;
|
2018-08-31 18:13:30 +00:00
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
return (
|
|
|
|
<UserItem
|
|
|
|
name={item.fname}
|
|
|
|
username={item.name}
|
|
|
|
onPress={() => this.removeUser(item)}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`create-channel-view-item-${item.name}`}
|
2020-03-03 21:25:23 +00:00
|
|
|
icon='check'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-09-25 19:28:42 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
renderInvitedList = () => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { users, theme } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
data={users}
|
|
|
|
extraData={users}
|
|
|
|
keyExtractor={item => item._id}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[
|
|
|
|
styles.list,
|
|
|
|
sharedStyles.separatorVertical,
|
|
|
|
{
|
|
|
|
backgroundColor: themes[theme].focusedBackground,
|
|
|
|
borderColor: themes[theme].separatorColor
|
|
|
|
}
|
|
|
|
]}
|
2018-09-25 19:28:42 +00:00
|
|
|
renderItem={this.renderItem}
|
2021-02-26 16:27:04 +00:00
|
|
|
ItemSeparatorComponent={List.Separator}
|
2018-09-25 19:28:42 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
/>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-31 18:13:30 +00:00
|
|
|
|
2017-08-10 16:25:50 +00:00
|
|
|
render() {
|
2021-05-12 19:01:29 +00:00
|
|
|
const { channelName, isTeam } = this.state;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { users, isFetching, theme } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
const userCount = users.length;
|
|
|
|
|
2017-08-10 16:25:50 +00:00
|
|
|
return (
|
2017-11-07 16:28:02 +00:00
|
|
|
<KeyboardView
|
2019-12-04 16:39:53 +00:00
|
|
|
style={{ backgroundColor: themes[theme].auxiliaryBackground }}
|
2018-08-31 18:13:30 +00:00
|
|
|
contentContainerStyle={[sharedStyles.container, styles.container]}
|
2021-09-13 20:41:05 +00:00
|
|
|
keyboardVerticalOffset={128}>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
[TEST] E2E Tests for Teams (#3178)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Added SelectListView and logic for leaving team
* Added addTeamMember and removeTeamMember
* Minor tweak
* Added deleteTeam function
* Minor tweak
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Remove unnecesary prop
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* Minor refactor to ListItem, add SelectListView to ModalStack, update handleLeaveTeam
* Minor tweaks
* Update SelectListView
* Update handleLeaveTeam, remove unnecessary method, add story
* Minor tweak
* Minor visual tweaks
* Update SelectListView.js
* Update index.js
* Update RoomMembersView
* Updated SelectListView, RoomActionsView, leaveTeam method and string translations
* Update SelectListVIew
* Minor tweak
* Update SelectListView
* Minor tweak
* Minor tweaks
* Fix for List.Item subtitles being pushed down by title's flex
* Minor tweaks
* Update RoomActionsView
* Use showConfirmationAlert and showErrorAlert
* Remove addTeamMember, update removeTeamMember
* Update Alert
* Minor tweaks
* Minor tweaks
* Minor tweak
* Update showActionSheet on RoomMembersView
* Remove team main from query and move code around
* Fetch roles
* Update RoomMembersView and SelectListView
* Update rocketchat.js
* Updated leaveTeam and handleRemoveFromTeam
* Fix validation
* Remove unnecessary function
* Update RoomActionsView
* Update en.json
* updated deleteTeam function and permissions
* Added showConfirmationAlert
* Added string translations for teams
* Fix permission
* Added moveChannelToTeam and convertToTeam functionality
* Fix SelectListView RadioButton
* Fix moveToTeam
* Added searchBar to SelectListVIew
* Update RoomView , SelectListVIew and string translation for error
* E2E for Teams
* Fix tests and cleanup
* Minor refactor
* Wrong label
* Move/convert
* Fix convert
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-06-04 16:16:05 +00:00
|
|
|
<SafeAreaView testID='create-channel-view'>
|
2018-08-31 18:13:30 +00:00
|
|
|
<ScrollView {...scrollPersistTaps}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[sharedStyles.separatorVertical, { borderColor: themes[theme].separatorColor }]}>
|
2018-08-31 18:13:30 +00:00
|
|
|
<TextInput
|
2019-08-07 19:20:16 +00:00
|
|
|
autoFocus
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.input, { backgroundColor: themes[theme].backgroundColor }]}
|
2018-09-25 19:28:42 +00:00
|
|
|
value={channelName}
|
2018-08-31 18:13:30 +00:00
|
|
|
onChangeText={this.onChangeText}
|
2021-05-12 19:01:29 +00:00
|
|
|
placeholder={isTeam ? I18n.t('Team_Name') : I18n.t('Channel_Name')}
|
2018-08-31 18:13:30 +00:00
|
|
|
returnKeyType='done'
|
[TEST] E2E Tests for Teams (#3178)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Added SelectListView and logic for leaving team
* Added addTeamMember and removeTeamMember
* Minor tweak
* Added deleteTeam function
* Minor tweak
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Remove unnecesary prop
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* Minor refactor to ListItem, add SelectListView to ModalStack, update handleLeaveTeam
* Minor tweaks
* Update SelectListView
* Update handleLeaveTeam, remove unnecessary method, add story
* Minor tweak
* Minor visual tweaks
* Update SelectListView.js
* Update index.js
* Update RoomMembersView
* Updated SelectListView, RoomActionsView, leaveTeam method and string translations
* Update SelectListVIew
* Minor tweak
* Update SelectListView
* Minor tweak
* Minor tweaks
* Fix for List.Item subtitles being pushed down by title's flex
* Minor tweaks
* Update RoomActionsView
* Use showConfirmationAlert and showErrorAlert
* Remove addTeamMember, update removeTeamMember
* Update Alert
* Minor tweaks
* Minor tweaks
* Minor tweak
* Update showActionSheet on RoomMembersView
* Remove team main from query and move code around
* Fetch roles
* Update RoomMembersView and SelectListView
* Update rocketchat.js
* Updated leaveTeam and handleRemoveFromTeam
* Fix validation
* Remove unnecessary function
* Update RoomActionsView
* Update en.json
* updated deleteTeam function and permissions
* Added showConfirmationAlert
* Added string translations for teams
* Fix permission
* Added moveChannelToTeam and convertToTeam functionality
* Fix SelectListView RadioButton
* Fix moveToTeam
* Added searchBar to SelectListVIew
* Update RoomView , SelectListVIew and string translation for error
* E2E for Teams
* Fix tests and cleanup
* Minor refactor
* Wrong label
* Move/convert
* Fix convert
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-06-04 16:16:05 +00:00
|
|
|
testID='create-channel-name'
|
2018-08-31 18:13:30 +00:00
|
|
|
autoCorrect={false}
|
|
|
|
autoCapitalize='none'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-08-31 18:13:30 +00:00
|
|
|
underlineColorAndroid='transparent'
|
2018-05-24 20:17:45 +00:00
|
|
|
/>
|
2021-02-26 16:27:04 +00:00
|
|
|
<List.Separator />
|
2018-08-31 18:13:30 +00:00
|
|
|
{this.renderType()}
|
2021-02-26 16:27:04 +00:00
|
|
|
<List.Separator />
|
2018-08-31 18:13:30 +00:00
|
|
|
{this.renderReadOnly()}
|
2021-02-26 16:27:04 +00:00
|
|
|
<List.Separator />
|
2020-09-11 14:31:38 +00:00
|
|
|
{this.renderEncrypted()}
|
2021-02-26 16:27:04 +00:00
|
|
|
<List.Separator />
|
2018-08-31 18:13:30 +00:00
|
|
|
{this.renderBroadcast()}
|
|
|
|
</View>
|
|
|
|
<View style={styles.invitedHeader}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.invitedTitle, { color: themes[theme].titleText }]}>{I18n.t('Invite')}</Text>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.invitedCount, { color: themes[theme].auxiliaryText }]}>
|
|
|
|
{userCount === 1 ? I18n.t('1_user') : I18n.t('N_users', { n: userCount })}
|
|
|
|
</Text>
|
2018-05-24 20:17:45 +00:00
|
|
|
</View>
|
2018-08-31 18:13:30 +00:00
|
|
|
{this.renderInvitedList()}
|
2018-10-23 21:39:48 +00:00
|
|
|
<Loading visible={isFetching} />
|
2018-08-31 18:13:30 +00:00
|
|
|
</ScrollView>
|
|
|
|
</SafeAreaView>
|
2017-09-01 19:42:50 +00:00
|
|
|
</KeyboardView>
|
2017-08-10 16:25:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
const mapStateToProps = (state: any) => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl: state.server.server,
|
2019-08-07 13:51:34 +00:00
|
|
|
isFetching: state.createChannel.isFetching,
|
2021-01-20 17:34:01 +00:00
|
|
|
encryptionEnabled: state.encryption.enabled,
|
2019-08-07 13:51:34 +00:00
|
|
|
users: state.selectedUsers.users,
|
2021-10-05 13:59:40 +00:00
|
|
|
user: getUserSelector(state),
|
|
|
|
createPublicChannelPermission: state.permissions['create-c'],
|
|
|
|
createPrivateChannelPermission: state.permissions['create-p']
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2021-11-10 21:18:35 +00:00
|
|
|
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|
|
|
create: (data: ICreateFunction) => dispatch(createChannelRequestAction(data)),
|
|
|
|
removeUser: (user: IOtherUser) => dispatch(removeUserAction(user))
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(CreateChannelView));
|