summaryrefslogtreecommitdiffstats
path: root/webapp/actions/team_actions.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/actions/team_actions.jsx')
-rw-r--r--webapp/actions/team_actions.jsx168
1 files changed, 86 insertions, 82 deletions
diff --git a/webapp/actions/team_actions.jsx b/webapp/actions/team_actions.jsx
index f263108fd..83fbfa0a9 100644
--- a/webapp/actions/team_actions.jsx
+++ b/webapp/actions/team_actions.jsx
@@ -1,15 +1,10 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';
-import Constants from 'utils/constants.jsx';
-const ActionTypes = Constants.ActionTypes;
-
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
-import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import {browserHistory} from 'react-router/es6';
@@ -19,85 +14,84 @@ const dispatch = store.dispatch;
const getState = store.getState;
import {getUser} from 'mattermost-redux/actions/users';
+import {
+ createTeam as createTeamRedux,
+ updateTeam as updateTeamRedux,
+ removeUserFromTeam as removeUserFromTeamRedux,
+ getTeamStats,
+ checkIfTeamExists as checkIfTeamExistsRedux,
+ updateTeamMemberRoles as updateTeamMemberRolesRedux,
+ addUsersToTeam as addUsersToTeamRedux,
+ sendEmailInvitesToTeam,
+ getTeamsForUser as getTeamsForUserRedux,
+ getTeamMembersForUser as getTeamMembersForUserRedux
+} from 'mattermost-redux/actions/teams';
export function checkIfTeamExists(teamName, onSuccess, onError) {
- Client.findTeamByName(teamName, onSuccess, onError);
+ checkIfTeamExistsRedux(teamName)(dispatch, getState).then(
+ (exists) => {
+ if (exists != null && onSuccess) {
+ onSuccess(exists);
+ } else if (exists == null && onError) {
+ const serverError = getState().requests.teams.getTeam.error;
+ onError({id: serverError.server_error_id, ...serverError});
+ }
+ }
+ );
}
export function createTeam(team, onSuccess, onError) {
- Client.createTeam(team,
+ createTeamRedux(team)(dispatch, getState).then(
(rteam) => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.CREATED_TEAM,
- team: rteam,
- member: {team_id: rteam.id, user_id: UserStore.getCurrentId(), roles: 'team_admin team_user'}
- });
-
- browserHistory.push('/' + rteam.name + '/channels/town-square');
-
- if (onSuccess) {
+ if (rteam && onSuccess) {
+ browserHistory.push('/' + rteam.name + '/channels/town-square');
onSuccess(rteam);
+ } else if (rteam == null && onError) {
+ const serverError = getState().requests.teams.createTeam.error;
+ onError({id: serverError.server_error_id, ...serverError});
}
- },
- onError
+ }
);
}
export function updateTeam(team, onSuccess, onError) {
- Client.updateTeam(team,
+ updateTeamRedux(team)(dispatch, getState).then(
(rteam) => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.UPDATE_TEAM,
- team: rteam
- });
-
- browserHistory.push('/' + rteam.name + '/channels/town-square');
-
- if (onSuccess) {
+ if (rteam && onSuccess) {
+ browserHistory.push('/' + rteam.name + '/channels/town-square');
onSuccess(rteam);
+ } else if (rteam == null && onError) {
+ const serverError = getState().requests.teams.updateTeam.error;
+ onError({id: serverError.server_error_id, ...serverError});
}
},
- onError
);
}
export function removeUserFromTeam(teamId, userId, success, error) {
- Client.removeUserFromTeam(
- teamId,
- userId,
- () => {
- TeamStore.removeMemberInTeam(teamId, userId);
- UserStore.removeProfileFromTeam(teamId, userId);
- UserStore.emitInTeamChange();
+ removeUserFromTeamRedux(teamId, userId)(dispatch, getState).then(
+ (data) => {
getUser(userId)(dispatch, getState);
- AsyncClient.getTeamStats(teamId);
+ getTeamStats(teamId)(dispatch, getState);
- if (success) {
+ if (data && success) {
success();
+ } else if (data == null && error) {
+ const serverError = getState().requests.teams.removeUserFromTeam.error;
+ error({id: serverError.server_error_id, ...serverError});
}
},
- (err) => {
- AsyncClient.dispatchError(err, 'removeUserFromTeam');
-
- if (error) {
- error(err);
- }
- }
);
}
export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) {
- Client.updateTeamMemberRoles(teamId, userId, newRoles,
- () => {
- AsyncClient.getTeamMember(teamId, userId);
-
- if (success) {
+ updateTeamMemberRolesRedux(teamId, userId, newRoles)(dispatch, getState).then(
+ (data) => {
+ if (data && success) {
success();
- }
- },
- (err) => {
- if (error) {
- error(err);
+ } else if (data == null && error) {
+ const serverError = getState().requests.teams.updateTeamMember.error;
+ error({id: serverError.server_error_id, ...serverError});
}
}
);
@@ -122,25 +116,13 @@ export function addUserToTeamFromInvite(data, hash, inviteId, success, error) {
}
export function addUsersToTeam(teamId, userIds, success, error) {
- Client.addUsersToTeam(
- teamId,
- userIds,
+ addUsersToTeamRedux(teamId, userIds)(dispatch, getState).then(
(teamMembers) => {
- teamMembers.forEach((member) => {
- TeamStore.removeMemberNotInTeam(teamId, member.user_id);
- UserStore.removeProfileNotInTeam(teamId, member.user_id);
- });
- UserStore.emitNotInTeamChange();
-
- if (success) {
+ if (teamMembers && success) {
success(teamMembers);
- }
- },
- (err) => {
- AsyncClient.dispatchError(err, 'addUsersToTeam');
-
- if (error) {
- error(err);
+ } else if (teamMembers == null && error) {
+ const serverError = getState().requests.teams.addUserToTeam.error;
+ error({id: serverError.server_error_id, ...serverError});
}
}
);
@@ -163,16 +145,20 @@ export function getInviteInfo(inviteId, success, error) {
}
export function inviteMembers(data, success, error) {
- Client.inviteMembers(
- data,
- () => {
- if (success) {
+ if (!data.invites) {
+ success();
+ }
+ const emails = [];
+ data.invites.forEach((i) => {
+ emails.push(i.email);
+ });
+ sendEmailInvitesToTeam(TeamStore.getCurrentId(), emails)(dispatch, getState).then(
+ (result) => {
+ if (result && success) {
success();
- }
- },
- (err) => {
- if (err) {
- error(err);
+ } else if (result == null && error) {
+ const serverError = getState().requests.teams.emailInvite.error;
+ error({id: serverError.server_error_id, ...serverError});
}
}
);
@@ -184,9 +170,27 @@ export function switchTeams(url) {
}
export function getTeamsForUser(userId, success, error) {
- Client.getTeamsForUser(userId, success, error);
+ getTeamsForUserRedux(userId)(dispatch, getState).then(
+ (result) => {
+ if (result && success) {
+ success(result);
+ } else if (result == null && error) {
+ const serverError = getState().requests.teams.getTeams.error;
+ error({id: serverError.server_error_id, ...serverError});
+ }
+ }
+ );
}
export function getTeamMembersForUser(userId, success, error) {
- Client.getTeamMembersForUser(userId, success, error);
+ getTeamMembersForUserRedux(userId)(dispatch, getState).then(
+ (result) => {
+ if (result && success) {
+ success(result);
+ } else if (result == null && error) {
+ const serverError = getState().requests.teams.getTeamMembers.error;
+ error({id: serverError.server_error_id, ...serverError});
+ }
+ }
+ );
}