From f0f53260984a210f44458d86ed5ac9e3afb3f363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Roland?= Date: Wed, 21 Dec 2016 18:48:06 +0100 Subject: [PATCH] #4698 Move Client.updateActive() in components to an action (#4858) * #4698 Move instances of Client.updateActive() in components to an action * Use null for empty success function --- webapp/actions/user_actions.jsx | 17 +++++++++++++++++ .../admin_team_members_dropdown.jsx | 12 +++--------- webapp/components/team_members_dropdown.jsx | 7 +++---- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 812bc2716f..b666413d97 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -432,3 +432,20 @@ export function checkMfa(loginId, success, error) { } ); } + +export function updateActive(userId, active, success, error) { + Client.updateActive(userId, active, + () => { + AsyncClient.getUser(userId); + + if (success) { + success(); + } + }, + (err) => { + if (error) { + error(err); + } + } + ); +} diff --git a/webapp/components/admin_console/admin_team_members_dropdown.jsx b/webapp/components/admin_console/admin_team_members_dropdown.jsx index 2532594931..4a42ded3ac 100644 --- a/webapp/components/admin_console/admin_team_members_dropdown.jsx +++ b/webapp/components/admin_console/admin_team_members_dropdown.jsx @@ -10,7 +10,7 @@ import Client from 'client/web_client.jsx'; import Constants from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; -import {updateUserRoles} from 'actions/user_actions.jsx'; +import {updateUserRoles, updateActive} from 'actions/user_actions.jsx'; import {FormattedMessage} from 'react-intl'; @@ -92,10 +92,7 @@ export default class AdminTeamMembersDropdown extends React.Component { handleMakeActive(e) { e.preventDefault(); - Client.updateActive(this.props.user.id, true, - () => { - AsyncClient.getUser(this.props.user.id); - }, + updateActive(this.props.user.id, true, null, (err) => { this.setState({serverError: err.message}); } @@ -104,10 +101,7 @@ export default class AdminTeamMembersDropdown extends React.Component { handleMakeNotActive(e) { e.preventDefault(); - Client.updateActive(this.props.user.id, false, - () => { - AsyncClient.getUser(this.props.user.id); - }, + updateActive(this.props.user.id, false, null, (err) => { this.setState({serverError: err.message}); } diff --git a/webapp/components/team_members_dropdown.jsx b/webapp/components/team_members_dropdown.jsx index b2fae4585e..1961d6b5a2 100644 --- a/webapp/components/team_members_dropdown.jsx +++ b/webapp/components/team_members_dropdown.jsx @@ -8,6 +8,7 @@ import UserStore from 'stores/user_store.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import {removeUserFromTeam} from 'actions/team_actions.jsx'; +import {updateActive} from 'actions/user_actions.jsx'; import Client from 'client/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; @@ -74,9 +75,8 @@ export default class TeamMembersDropdown extends React.Component { } handleMakeActive() { - Client.updateActive(this.props.user.id, true, + updateActive(this.props.user.id, true, () => { - AsyncClient.getUser(this.props.user.id); AsyncClient.getChannelStats(ChannelStore.getCurrentId()); AsyncClient.getTeamStats(this.props.teamMember.team_id); }, @@ -87,9 +87,8 @@ export default class TeamMembersDropdown extends React.Component { } handleMakeNotActive() { - Client.updateActive(this.props.user.id, false, + updateActive(this.props.user.id, false, () => { - AsyncClient.getUser(this.props.user.id); AsyncClient.getChannelStats(ChannelStore.getCurrentId()); AsyncClient.getTeamStats(this.props.teamMember.team_id); },