diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js
index a9c4962d1..41ca49db3 100644
--- a/app/actions/views/channel.js
+++ b/app/actions/views/channel.js
@@ -2,7 +2,6 @@
// See License.txt for license information.
import {batchActions} from 'redux-batched-actions';
-
import {ViewTypes} from 'app/constants';
import {updateStorage} from 'app/actions/storage';
@@ -186,11 +185,11 @@ export function unmarkFavorite(channelId) {
};
}
-export function leaveChannel(channel) {
+export function leaveChannel(channel, reset = false) {
return async (dispatch, getState) => {
const {currentId: teamId} = getState().entities.teams;
serviceLeaveChannel(teamId, channel.id)(dispatch, getState).then(() => {
- if (channel.isCurrent) {
+ if (channel.isCurrent || reset) {
selectInitialChannel(teamId)(dispatch, getState);
}
});
diff --git a/app/scenes/channel_info/channel_info.js b/app/scenes/channel_info/channel_info.js
index 392c25f92..3ef3d355d 100644
--- a/app/scenes/channel_info/channel_info.js
+++ b/app/scenes/channel_info/channel_info.js
@@ -2,7 +2,9 @@
// See License.txt for license information.
import React, {PropTypes, PureComponent} from 'react';
+import {injectIntl, intlShape} from 'react-intl';
import {
+ Alert,
ScrollView,
StyleSheet,
View
@@ -10,6 +12,7 @@ import {
import ChannelInfoHeader from './channel_info_header';
import ChannelInfoRow from './channel_info_row';
+import {Constants} from 'service/constants';
const style = StyleSheet.create({
container: {
@@ -32,18 +35,22 @@ const style = StyleSheet.create({
}
});
-export default class ChannelInfo extends PureComponent {
+class ChannelInfo extends PureComponent {
static propTypes = {
+ intl: intlShape.isRequired,
currentChannel: PropTypes.object.isRequired,
currentChannelCreatorName: PropTypes.string,
currentChannelMemberCount: PropTypes.number,
isFavorite: PropTypes.bool.isRequired,
+ leaveChannelRequest: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
actions: PropTypes.shape({
getChannelStats: PropTypes.func.isRequired,
goToChannelMembers: PropTypes.func.isRequired,
markFavorite: PropTypes.func.isRequired,
- unmarkFavorite: PropTypes.func.isRequired
+ unmarkFavorite: PropTypes.func.isRequired,
+ goBack: PropTypes.func.isRequired,
+ leaveChannel: PropTypes.func.isRequired
})
}
@@ -55,15 +62,25 @@ export default class ChannelInfo extends PureComponent {
};
}
+ componentDidMount() {
+ this.props.actions.getChannelStats(this.props.currentChannel.team_id, this.props.currentChannel.id);
+ }
+
componentWillReceiveProps(nextProps) {
const isFavorite = nextProps.isFavorite;
if (isFavorite !== this.state.isFavorite) {
this.setState({isFavorite});
}
+ this.navigateAfterLeave(nextProps.leaveChannelRequest);
}
- componentDidMount() {
- this.props.actions.getChannelStats(this.props.currentChannel.team_id, this.props.currentChannel.id);
+ navigateAfterLeave(leaveChannelRequest) {
+ if (
+ leaveChannelRequest !== this.props.leaveChannelRequest &&
+ leaveChannelRequest.status === 'success'
+ ) {
+ this.props.actions.goBack();
+ }
}
handleFavorite = () => {
@@ -74,6 +91,40 @@ export default class ChannelInfo extends PureComponent {
toggleFavorite(currentChannel.id);
}
+ handleLeave() {
+ const {formatMessage} = this.props.intl;
+ const channel = this.props.currentChannel;
+ const term = channel.type === Constants.OPEN_CHANNEL ?
+ formatMessage({id: 'mobile.channel_info.publicChannel', defaultMessage: 'Public Channel'}) :
+ formatMessage({id: 'mobile.channel_info.privateChannel', defaultMessage: 'Private Channel'});
+
+ Alert.alert(
+ formatMessage({id: 'mobile.channel_info.alertTitleLeaveChannel', defaultMessage: 'Leave {term}'}, {term}),
+ formatMessage({
+ id: 'mobile.channel_info.alertMessageLeaveChannel',
+ defaultMessage: 'Are you sure you want to leave the {term} with {name}?'
+ }, {
+ term: term.toLowerCase(),
+ name: channel.display_name
+ }),
+ [{
+ text: formatMessage({id: 'mobile.channel_info.alertNo', defaultMessage: 'No'})
+ }, {
+ text: formatMessage({id: 'mobile.channel_info.alertYes', defaultMessage: 'Yes'}),
+ onPress: () => {
+ this.props.actions.leaveChannel(channel, true);
+ }
+ }]
+ );
+ }
+
+ renderLeaveChannelRow() {
+ const channel = this.props.currentChannel;
+ const isDefaultChannel = channel.name === Constants.DEFAULT_CHANNEL;
+ const isDirectMessage = channel.type === 'D';
+ return !isDefaultChannel && !isDirectMessage;
+ }
+
render() {
const {
currentChannel,
@@ -135,10 +186,11 @@ export default class ChannelInfo extends PureComponent {
true}
+ action={() => this.handleLeave()}
defaultMessage='Leave Channel'
icon='sign-out'
textId='navbar.leave'
+ shouldRender={this.renderLeaveChannelRow()}
/>
f.id);
const isFavorite = favoriteChannels.indexOf(currentChannel.id) > -1;
+ const leaveChannelRequest = state.requests.channels.leaveChannel;
return {
...ownProps,
@@ -27,6 +28,7 @@ function mapStateToProps(state, ownProps) {
currentChannelCreatorName,
currentChannelMemberCount,
isFavorite,
+ leaveChannelRequest,
theme: getTheme(state)
};
}
@@ -37,7 +39,9 @@ function mapDispatchToProps(dispatch) {
getChannelStats,
goToChannelMembers,
markFavorite,
- unmarkFavorite
+ unmarkFavorite,
+ leaveChannel,
+ goBack
}, dispatch)
};
}
diff --git a/app/scenes/channel_info/channel_info_row.js b/app/scenes/channel_info/channel_info_row.js
index e2aa7cb3a..a37aea9e1 100644
--- a/app/scenes/channel_info/channel_info_row.js
+++ b/app/scenes/channel_info/channel_info_row.js
@@ -45,8 +45,11 @@ function createTouchableComponent(children, action) {
}
function channelInfoRow(props) {
- const {action, defaultMessage, detail, icon, iconColor, textColor, textId, togglable} = props;
+ const {action, defaultMessage, detail, icon, iconColor, textColor, textId, togglable, shouldRender = true} = props;
+ if (!shouldRender) {
+ return null;
+ }
const RowComponent = (