#4695 Move instances of Client.updateTeamMemberRoles() in components to an action (#4870)

This commit is contained in:
Björn Roland
2016-12-22 14:46:13 +01:00
committed by enahum
parent 670234dc66
commit 84c6e376fa
3 changed files with 26 additions and 16 deletions

View File

@@ -75,3 +75,20 @@ export function removeUserFromTeam(teamId, userId, success, error) {
}
);
}
export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) {
Client.updateTeamMemberRoles(teamId, userId, newRoles,
() => {
AsyncClient.getTeamMember(teamId, userId);
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}

View File

@@ -11,6 +11,7 @@ import Constants from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import {updateUserRoles, updateActive} from 'actions/user_actions.jsx';
import {updateTeamMemberRoles} from 'actions/team_actions.jsx';
import {FormattedMessage} from 'react-intl';
@@ -52,13 +53,11 @@ export default class AdminTeamMembersDropdown extends React.Component {
}
);
Client.updateTeamMemberRoles(
updateTeamMemberRoles(
this.props.teamMember.team_id,
this.props.user.id,
'team_user',
() => {
AsyncClient.getTeamMember(this.props.teamMember.team_id, this.props.user.id);
},
null,
(err) => {
this.setState({serverError: err.message});
}
@@ -109,13 +108,11 @@ export default class AdminTeamMembersDropdown extends React.Component {
}
doMakeTeamAdmin() {
Client.updateTeamMemberRoles(
updateTeamMemberRoles(
this.props.teamMember.team_id,
this.props.user.id,
'team_user team_admin',
() => {
AsyncClient.getTeamMember(this.props.teamMember.team_id, this.props.user.id);
},
null,
(err) => {
this.setState({serverError: err.message});
}

View File

@@ -7,10 +7,9 @@ import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import {removeUserFromTeam} from 'actions/team_actions.jsx';
import {removeUserFromTeam, updateTeamMemberRoles} 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';
import * as Utils from 'utils/utils.jsx';
@@ -44,12 +43,11 @@ export default class TeamMembersDropdown extends React.Component {
if (this.props.user.id === me.id && me.roles.includes('system_admin')) {
this.handleDemote(this.props.user, 'team_user');
} else {
Client.updateTeamMemberRoles(
updateTeamMemberRoles(
this.props.teamMember.team_id,
this.props.user.id,
'team_user',
() => {
AsyncClient.getTeamMember(this.props.teamMember.team_id, this.props.user.id);
AsyncClient.getUser(this.props.user.id);
},
(err) => {
@@ -103,12 +101,11 @@ export default class TeamMembersDropdown extends React.Component {
if (this.props.user.id === me.id && me.roles.includes('system_admin')) {
this.handleDemote(this.props.user, 'team_user team_admin');
} else {
Client.updateTeamMemberRoles(
updateTeamMemberRoles(
this.props.teamMember.team_id,
this.props.user.id,
'team_user team_admin',
() => {
AsyncClient.getTeamMember(this.props.teamMember.team_id, this.props.user.id);
AsyncClient.getUser(this.props.user.id);
},
(err) => {
@@ -139,12 +136,11 @@ export default class TeamMembersDropdown extends React.Component {
}
handleDemoteSubmit() {
Client.updateTeamMemberRoles(
updateTeamMemberRoles(
this.props.teamMember.team_id,
this.props.user.id,
this.state.newRole,
() => {
AsyncClient.getTeamMember(this.props.teamMember.team_id, this.props.user.id);
AsyncClient.getUser(this.props.user.id);
const teamUrl = TeamStore.getCurrentTeamUrl();