PLT-6213 Move team store and actions over to use redux (#6222)

* Move team store and actions over to user redux

* Fix JS error when inviting by email
Этот коммит содержится в:
Joram Wilander
2017-04-26 15:49:15 -04:00
коммит произвёл GitHub
родитель 1fef5bf5fe
Коммит 7307156c49
27 изменённых файлов: 387 добавлений и 390 удалений

Просмотреть файл

@@ -36,6 +36,7 @@ import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {ChannelTypes} from 'mattermost-redux/action_types';
import {removeUserFromTeam} from 'mattermost-redux/actions/teams';
export function emitChannelClickEvent(channel) {
function userVisitedFakeChannel(chan, success, fail) {
@@ -189,16 +190,7 @@ export function emitPostFocusRightHandSideFromSearch(post, isMentionSearch) {
}
export function emitLeaveTeam() {
Client.removeUserFromTeam(
TeamStore.getCurrentId(),
UserStore.getCurrentId(),
() => {
// DO nothing. The websocket should cause a re-direct
},
(err) => {
AsyncClient.dispatchError(err, 'removeUserFromTeam');
}
);
removeUserFromTeam(TeamStore.getCurrentId(), UserStore.getCurrentId())(dispatch, getState);
}
export function emitLoadMorePostsEvent() {
@@ -467,7 +459,6 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr
export function clientLogout(redirectTo = '/') {
BrowserStore.clear();
ErrorStore.clearLastError();
TeamStore.clear();
ChannelStore.clear();
stopPeriodicStatusUpdates();
WebsocketActions.close();

Просмотреть файл

@@ -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);
}
export function createTeam(team, onSuccess, onError) {
Client.createTeam(team,
(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) {
onSuccess(rteam);
}
},
onError
);
}
export function updateTeam(team, onSuccess, onError) {
Client.updateTeam(team,
(rteam) => {
AppDispatcher.handleServerAction({
type: ActionTypes.UPDATE_TEAM,
team: rteam
});
browserHistory.push('/' + rteam.name + '/channels/town-square');
if (onSuccess) {
onSuccess(rteam);
}
},
onError
);
}
export function removeUserFromTeam(teamId, userId, success, error) {
Client.removeUserFromTeam(
teamId,
userId,
() => {
TeamStore.removeMemberInTeam(teamId, userId);
UserStore.removeProfileFromTeam(teamId, userId);
UserStore.emitInTeamChange();
getUser(userId)(dispatch, getState);
AsyncClient.getTeamStats(teamId);
if (success) {
success();
}
},
(err) => {
AsyncClient.dispatchError(err, 'removeUserFromTeam');
if (error) {
error(err);
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 updateTeamMemberRoles(teamId, userId, newRoles, success, error) {
Client.updateTeamMemberRoles(teamId, userId, newRoles,
() => {
AsyncClient.getTeamMember(teamId, userId);
export function createTeam(team, onSuccess, onError) {
createTeamRedux(team)(dispatch, getState).then(
(rteam) => {
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});
}
}
);
}
if (success) {
success();
export function updateTeam(team, onSuccess, onError) {
updateTeamRedux(team)(dispatch, getState).then(
(rteam) => {
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});
}
},
(err) => {
if (error) {
error(err);
);
}
export function removeUserFromTeam(teamId, userId, success, error) {
removeUserFromTeamRedux(teamId, userId)(dispatch, getState).then(
(data) => {
getUser(userId)(dispatch, getState);
getTeamStats(teamId)(dispatch, getState);
if (data && success) {
success();
} else if (data == null && error) {
const serverError = getState().requests.teams.removeUserFromTeam.error;
error({id: serverError.server_error_id, ...serverError});
}
},
);
}
export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) {
updateTeamMemberRolesRedux(teamId, userId, newRoles)(dispatch, getState).then(
(data) => {
if (data && success) {
success();
} 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});
}
}
);
}

Просмотреть файл

@@ -39,10 +39,12 @@ import {
updateUserPassword,
createUser,
login,
loadMe as loadMeRedux
loadMe as loadMeRedux,
updateUserRoles as updateUserRolesRedux
} from 'mattermost-redux/actions/users';
import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/general';
import {getTeamMembersByIds, getMyTeamMembers} from 'mattermost-redux/actions/teams';
export function loadMe(callback) {
loadMeRedux()(dispatch, getState).then(
@@ -169,30 +171,13 @@ export function loadProfilesWithoutTeam(page, perPage, success) {
}
function loadTeamMembersForProfiles(userIds, teamId, success, error) {
Client.getTeamMembersByIds(
teamId,
userIds,
getTeamMembersByIds(teamId, userIds)(dispatch, getState).then(
(data) => {
const memberMap = {};
for (let i = 0; i < data.length; i++) {
memberMap[data[i].user_id] = data[i];
}
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MEMBERS_IN_TEAM,
team_id: teamId,
team_members: memberMap
});
if (success) {
if (data && success) {
success(data);
}
},
(err) => {
AsyncClient.dispatchError(err, 'getTeamMembersByIds');
if (error) {
error(err);
} else if (data == null && error) {
const serverError = getState().requests.teams.getTeamMembers.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
@@ -585,7 +570,7 @@ export function updateUserNotifyProps(props, success, error) {
}
export function updateUserRoles(userId, newRoles, success, error) {
updateUserRoles(userId, newRoles)(dispatch, getState).then(
updateUserRolesRedux(userId, newRoles)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
@@ -852,13 +837,9 @@ export function getMissingProfiles(ids) {
}
export function loadMyTeamMembers() {
Client.getMyTeamMembers((data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_TEAM_MEMBERS,
team_members: data
});
AsyncClient.getMyTeamsUnread();
}, (err) => {
AsyncClient.dispatchError(err, 'getMyTeamMembers');
});
getMyTeamMembers()(dispatch, getState).then(
() => {
AsyncClient.getMyTeamsUnread();
}
);
}

Просмотреть файл

@@ -280,7 +280,6 @@ function handleLeaveTeamEvent(msg) {
// if they are on the team being removed redirect them to default team
if (TeamStore.getCurrentId() === msg.data.team_id) {
TeamStore.setCurrentId('');
Client.setTeamId('');
BrowserStore.removeGlobalItem('team');
BrowserStore.removeGlobalItem(msg.data.team_id);