diff --git a/app/actions/actionsTypes.js b/app/actions/actionsTypes.js index 1fd8679bc..146350087 100644 --- a/app/actions/actionsTypes.js +++ b/app/actions/actionsTypes.js @@ -38,6 +38,7 @@ export const INQUIRY = createRequestTypes('INQUIRY', [...defaultTypes, 'SET_ENAB export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS', 'SET_MASTER_DETAIL']); export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']); export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]); +export const CREATE_TEAM = createRequestTypes('CREATE_TEAM', [...defaultTypes]); export const CREATE_DISCUSSION = createRequestTypes('CREATE_DISCUSSION', [...defaultTypes]); export const SELECTED_USERS = createRequestTypes('SELECTED_USERS', ['ADD_USER', 'REMOVE_USER', 'RESET', 'SET_LOADING']); export const SERVER = createRequestTypes('SERVER', [ diff --git a/app/actions/createTeam.js b/app/actions/createTeam.js new file mode 100644 index 000000000..c91cce2d7 --- /dev/null +++ b/app/actions/createTeam.js @@ -0,0 +1,22 @@ +import * as types from './actionsTypes'; + +export function createTeamRequest(data) { + return { + type: types.CREATE_TEAM.REQUEST, + data + }; +} + +export function createTeamSuccess(data) { + return { + type: types.CREATE_TEAM.SUCCESS, + data + }; +} + +export function createTeamFailure(err) { + return { + type: types.CREATE_TEAM.FAILURE, + err + }; +} diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index a0229ec9a..635a7957b 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -711,5 +711,8 @@ "No_team_channels_found": "No channels found", "Team_not_found": "Team not found", "Create_Team": "Create Team", - "Team_Name": "Team Name" + "Team_Name": "Team Name", + "Private_Team": "Private Team", + "Read_Only_Team": "Read Only Team", + "Broadcast_Team": "Broadcast Team" } diff --git a/app/views/CreateChannelView.js b/app/views/CreateChannelView.js index 7690de270..5674f1d5e 100644 --- a/app/views/CreateChannelView.js +++ b/app/views/CreateChannelView.js @@ -10,6 +10,7 @@ import * as List from '../containers/List'; import TextInput from '../presentation/TextInput'; import Loading from '../containers/Loading'; import { createChannelRequest as createChannelRequestAction } from '../actions/createChannel'; +import { createTeamRequest as createTeamRequestAction } from '../actions/createTeam'; import { removeUser as removeUserAction } from '../actions/selectedUsers'; import sharedStyles from './Styles'; import KeyboardView from '../presentation/KeyboardView'; @@ -68,15 +69,16 @@ const styles = StyleSheet.create({ }); class CreateChannelView extends React.Component { - static navigationOptions = () => ({ - title: this.props?.route?.params?.isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel') + static navigationOptions = ({ route }) => ({ + title: route?.params?.isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel') }) static propTypes = { navigation: PropTypes.object, route: PropTypes.object, baseUrl: PropTypes.string, - create: PropTypes.func.isRequired, + createChannel: PropTypes.func.isRequired, + createTeam: PropTypes.func.isRequired, removeUser: PropTypes.func.isRequired, error: PropTypes.object, failure: PropTypes.bool, @@ -155,7 +157,10 @@ class CreateChannelView extends React.Component { const { channelName, type, readOnly, broadcast, encrypted } = this.state; - const { users: usersProps, isFetching, create } = this.props; + const { + users: usersProps, isFetching, createTeam, createChannel, route + } = this.props; + const { isTeam } = route?.params; if (!channelName.trim() || isFetching) { return; @@ -164,10 +169,17 @@ class CreateChannelView extends React.Component { // transform users object into array of usernames const users = usersProps.map(user => user.name); - // create channel - create({ - name: channelName, users, type, readOnly, broadcast, encrypted - }); + if (isTeam) { + // create team + createTeam({ + name: channelName, users, type, readOnly, broadcast, encrypted + }); + } else { + // create channel + createChannel({ + name: channelName, users, type, readOnly, broadcast, encrypted + }); + } Review.pushPositiveEvent(); } @@ -198,10 +210,13 @@ class CreateChannelView extends React.Component { renderType() { const { type } = this.state; + const { route } = this.props; + const { isTeam } = route?.params; + return this.renderSwitch({ id: 'type', value: type, - label: 'Private_Channel', + label: isTeam ? 'Private_Team' : 'Private_Channel', onValueChange: (value) => { logEvent(events.CR_TOGGLE_TYPE); // If we set the channel as public, encrypted status should be false @@ -212,10 +227,13 @@ class CreateChannelView extends React.Component { renderReadOnly() { const { readOnly, broadcast } = this.state; + const { route } = this.props; + const { isTeam } = route?.params; + return this.renderSwitch({ id: 'readonly', value: readOnly, - label: 'Read_Only_Channel', + label: isTeam ? 'Read_Only_Team' : 'Read_Only_Channel', onValueChange: (value) => { logEvent(events.CR_TOGGLE_READ_ONLY); this.setState({ readOnly: value }); @@ -246,10 +264,13 @@ class CreateChannelView extends React.Component { renderBroadcast() { const { broadcast, readOnly } = this.state; + const { route } = this.props; + const { isTeam } = route?.params; + return this.renderSwitch({ id: 'broadcast', value: broadcast, - label: 'Broadcast_Channel', + label: isTeam ? 'Broadcast_Team' : 'Broadcast_Channel', onValueChange: (value) => { logEvent(events.CR_TOGGLE_BROADCAST); this.setState({ @@ -364,7 +385,8 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ - create: data => dispatch(createChannelRequestAction(data)), + createChannel: data => dispatch(createChannelRequestAction(data)), + createTeam: data => dispatch(createTeamRequestAction(data)), removeUser: user => dispatch(removeUserAction(user)) }); diff --git a/app/views/NewMessageView.js b/app/views/NewMessageView.js index da0efdb42..d8cdc01cb 100644 --- a/app/views/NewMessageView.js +++ b/app/views/NewMessageView.js @@ -23,6 +23,7 @@ import { withTheme } from '../theme'; import { getUserSelector } from '../selectors/login'; import Navigation from '../lib/Navigation'; import { createChannelRequest } from '../actions/createChannel'; +import { createTeamRequest } from '../actions/createTeam'; import { goRoom } from '../utils/goRoom'; import SafeAreaView from '../containers/SafeAreaView'; @@ -113,7 +114,7 @@ class NewMessageView extends React.Component { createChannel = () => { logEvent(events.NEW_MSG_CREATE_CHANNEL); const { navigation } = this.props; - navigation.navigate('SelectedUsersViewCreateChannel', { nextAction: () => navigation.navigate('CreateChannelView') }); + navigation.navigate('SelectedUsersViewCreateChannel', { nextAction: () => navigation.navigate('CreateChannelView', { isTeam: false }) }); } createTeam = () => { @@ -265,7 +266,8 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = dispatch => ({ - createChannel: params => dispatch(createChannelRequest(params)) + createChannel: params => dispatch(createChannelRequest(params)), + createTeam: params => dispatch(createTeamRequest(params)) }); export default connect(mapStateToProps, mapDispatchToProps)(withTheme(NewMessageView));