From dbfd93daa75a0998bc8645245f9cc1ad77f3cadd Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Mon, 23 Jan 2017 15:22:26 +0100 Subject: Move instances of Client.deleteChannel() in components to an action (#5164) --- webapp/actions/channel_actions.jsx | 20 ++++++++++++++++++++ webapp/components/delete_channel_modal.jsx | 14 ++------------ 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'webapp') diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index 340f90fc4..4b4e3e10c 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -461,3 +461,23 @@ export function leaveChannel(channelId, success, error) { } ); } + +export function deleteChannel(channelId, success, error) { + Client.deleteChannel( + channelId, + () => { + loadChannelsForCurrentUser(); + + if (success) { + success(); + } + }, + (err) => { + AsyncClient.dispatchError(err, 'handleDelete'); + + if (error) { + error(err); + } + } + ); +} diff --git a/webapp/components/delete_channel_modal.jsx b/webapp/components/delete_channel_modal.jsx index 1b642861a..a6577a4a9 100644 --- a/webapp/components/delete_channel_modal.jsx +++ b/webapp/components/delete_channel_modal.jsx @@ -1,8 +1,6 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import * as AsyncClient from 'utils/async_client.jsx'; -import Client from 'client/web_client.jsx'; import {Modal} from 'react-bootstrap'; import TeamStore from 'stores/team_store.jsx'; import Constants from 'utils/constants.jsx'; @@ -13,7 +11,7 @@ import {browserHistory} from 'react-router/es6'; import React from 'react'; -import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx'; +import {deleteChannel} from 'actions/channel_actions.jsx'; export default class DeleteChannelModal extends React.Component { constructor(props) { @@ -31,15 +29,7 @@ export default class DeleteChannelModal extends React.Component { } browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/town-square'); - Client.deleteChannel( - this.props.channel.id, - () => { - loadChannelsForCurrentUser(); - }, - (err) => { - AsyncClient.dispatchError(err, 'handleDelete'); - } - ); + deleteChannel(this.props.channel.id); } onHide() { -- cgit v1.2.3-1-g7c22