#4697 Move Client.createChannel() in components to an action (#4855)

* #4697 Move instances of Client.createChannel() in components to an action
This commit is contained in:
Björn Roland
2016-12-22 15:46:34 +01:00
committed by enahum
parent 257a2234c4
commit 8a92908dad
2 changed files with 43 additions and 21 deletions

View File

@@ -275,3 +275,39 @@ export function updateChannelNotifyProps(data, success, error) {
}
);
}
export function createChannel(channel, success, error) {
Client.createChannel(
channel,
(data) => {
Client.getChannel(
data.id,
(data2) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data2.channel,
member: data2.channel
});
if (success) {
success(data2);
}
},
(err) => {
AsyncClient.dispatchError(err, 'getChannel');
if (error) {
error(err);
}
}
);
},
(err) => {
AsyncClient.dispatchError(err, 'createChannel');
if (error) {
error(err);
}
}
);
}

View File

@@ -2,7 +2,6 @@
// See License.txt for license information.
import * as Utils from 'utils/utils.jsx';
import Client from 'client/web_client.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
@@ -10,12 +9,9 @@ import NewChannelModal from './new_channel_modal.jsx';
import ChangeURLModal from './change_url_modal.jsx';
import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl';
import {createChannel} from 'actions/channel_actions.jsx';
import {browserHistory} from 'react-router/es6';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
const SHOW_NEW_CHANNEL = 1;
const SHOW_EDIT_URL = 2;
const SHOW_EDIT_URL_THEN_COMPLETE = 3;
@@ -106,25 +102,15 @@ class NewChannelFlow extends React.Component {
header: this.state.channelHeader,
type: this.state.channelType
};
Client.createChannel(
createChannel(
channel,
(data) => {
Client.getChannel(
data.id,
(data2) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data2.channel,
member: data2.member
});
this.doOnModalExited = () => {
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + data.channel.name);
};
this.doOnModalExited = () => {
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + data2.channel.name);
};
this.props.onModalDismissed();
}
);
this.props.onModalDismissed();
},
(err) => {
if (err.id === 'model.channel.is_valid.2_or_more.app_error') {