From 3cd8057d28b28f360b630bbc323fdf22d144b83b Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 29 Jun 2017 10:03:57 -0400 Subject: Various updates to match latest mattermost-redux (#6794) --- webapp/actions/channel_actions.jsx | 50 ++++++++++++++++---------------------- webapp/routes/route_team.jsx | 16 ++++++------ 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index beee61c49..887aca030 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -164,14 +164,12 @@ export function openDirectChannelToUser(userId, success, error) { } ChannelActions.createDirectChannel(UserStore.getCurrentId(), userId)(dispatch, getState).then( - (data) => { + (result) => { loadProfilesForSidebar(); - if (data && success) { - success(data, false); - } else if (data == null && error) { - browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channelName); - const serverError = getState().requests.channels.createChannel.error; - error({id: serverError.server_error_id, ...serverError}); + if (result.data && success) { + success(result.data, false); + } else if (result.error && error) { + error({id: result.error.server_error_id, ...result.error}); } } ); @@ -237,17 +235,14 @@ export function loadDMsAndGMsForUnreads() { } } -export function joinChannel(channel, success, error) { - ChannelActions.joinChannel(UserStore.getCurrentId(), null, channel.id)(dispatch, getState).then( - (data) => { - if (data && success) { - success(data); - } else if (data == null && error) { - const serverError = getState().requests.channels.joinChannel.error; - error({id: serverError.server_error_id, ...serverError}); - } - } - ); +export async function joinChannel(channel, success, error) { + const {data, serverError} = await ChannelActions.joinChannel(UserStore.getCurrentId(), null, channel.id)(dispatch, getState); + + if (data && success) { + success(data); + } else if (data == null && error) { + error({id: serverError.server_error_id, ...serverError}); + } } export function updateChannel(channel, success, error) { @@ -373,15 +368,12 @@ export function leaveChannel(channelId, success) { ); } -export function deleteChannel(channelId, success, error) { - ChannelActions.deleteChannel(channelId)(dispatch, getState).then( - (data) => { - if (data && success) { - success(data); - } else if (data == null && error) { - const serverError = getState().requests.channels.members.error; - error({id: serverError.server_error_id, ...serverError}); - } - } - ); +export async function deleteChannel(channelId, success, error) { + const {data, serverError} = await ChannelActions.deleteChannel(channelId)(dispatch, getState); + + if (data && success) { + success(data); + } else if (serverError && error) { + error({id: serverError.server_error_id, ...serverError}); + } } diff --git a/webapp/routes/route_team.jsx b/webapp/routes/route_team.jsx index f8ff3b593..59cf6d673 100644 --- a/webapp/routes/route_team.jsx +++ b/webapp/routes/route_team.jsx @@ -51,10 +51,10 @@ function doChannelChange(state, replace, callback) { if (!channel) { joinChannel(UserStore.getCurrentId(), TeamStore.getCurrentId(), null, state.params.channel)(dispatch, getState).then( - (data) => { - if (data) { - GlobalActions.emitChannelClickEvent(data.channel); - } else if (data == null) { + (result) => { + if (result.data) { + GlobalActions.emitChannelClickEvent(result.data.channel); + } else if (result.error) { if (state.params.team) { replace('/' + state.params.team + '/channels/town-square'); } else { @@ -192,11 +192,11 @@ function onChannelByIdentifierEnter(state, replace, callback) { callback(); } else { joinChannel(UserStore.getCurrentId(), TeamStore.getCurrentId(), null, identifier)(dispatch, getState).then( - (data) => { - if (data) { - GlobalActions.emitChannelClickEvent(data.channel); + (result) => { + if (result.data) { + GlobalActions.emitChannelClickEvent(result.data.channel); callback(); - } else if (data == null) { + } else if (result.error) { handleError(state, replace, callback); } } -- cgit v1.2.3-1-g7c22