From 82b36b3721d6ee129d27c3fc3957d4e37643d4a6 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 26 Jun 2017 13:25:43 -0400 Subject: PLT-6815 Do not disconnect websocket when joining a team (#6746) * Do not disconnect websocket when joining a team * Fix eslint error --- webapp/actions/team_actions.jsx | 41 +++++++++------------- .../select_team/components/select_team_item.jsx | 27 +++++++------- webapp/components/select_team/select_team.jsx | 1 - 3 files changed, 29 insertions(+), 40 deletions(-) (limited to 'webapp') diff --git a/webapp/actions/team_actions.jsx b/webapp/actions/team_actions.jsx index a0d208301..af132b139 100644 --- a/webapp/actions/team_actions.jsx +++ b/webapp/actions/team_actions.jsx @@ -18,7 +18,6 @@ import {viewChannel} from 'mattermost-redux/actions/channels'; import * as TeamActions from 'mattermost-redux/actions/teams'; import {TeamTypes} from 'mattermost-redux/action_types'; -import {batchActions} from 'redux-batched-actions'; export function checkIfTeamExists(teamName, onSuccess, onError) { TeamActions.checkIfTeamExists(teamName)(dispatch, getState).then( @@ -92,30 +91,24 @@ export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) export function addUserToTeamFromInvite(data, hash, inviteId, success, error) { Client4.addToTeamFromInvite(hash, data, inviteId).then( - (team) => { - const member = { - team_id: team.id, - user_id: getState().entities.users.currentUserId, - roles: 'team_user', - delete_at: 0, - msg_count: 0, - mention_count: 0 - }; - - dispatch(batchActions([ - { - type: TeamTypes.RECEIVED_TEAMS_LIST, - data: [team] - }, - { - type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, - data: member + (member) => { + TeamActions.getTeam(member.team_id)(dispatch, getState).then( + (team) => { + dispatch({ + type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, + data: { + ...member, + delete_at: 0, + msg_count: 0, + mention_count: 0 + } + }); + + if (success) { + success(team); + } } - ])); - - if (success) { - success(team); - } + ); }, ).catch( (err) => { diff --git a/webapp/components/select_team/components/select_team_item.jsx b/webapp/components/select_team/components/select_team_item.jsx index 201c9c8ab..0d47ba7e1 100644 --- a/webapp/components/select_team/components/select_team_item.jsx +++ b/webapp/components/select_team/components/select_team_item.jsx @@ -1,30 +1,28 @@ -import PropTypes from 'prop-types'; - // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import React from 'react'; +import * as Utils from 'utils/utils.jsx'; +import {addUserToTeamFromInvite} from 'actions/team_actions.jsx'; -import {Link} from 'react-router/es6'; +import React from 'react'; +import PropTypes from 'prop-types'; +import {Link, browserHistory} from 'react-router/es6'; import {Tooltip, OverlayTrigger} from 'react-bootstrap'; import {Constants} from 'utils/constants.jsx'; -import * as Utils from 'utils/utils.jsx'; -export default class SelectTeamItem extends React.Component { +export default class SelectTeamItem extends React.PureComponent { static propTypes = { team: PropTypes.object.isRequired, - url: PropTypes.string.isRequired, onTeamClick: PropTypes.func.isRequired, loading: PropTypes.bool.isRequired }; - constructor(props) { - super(props); - - this.handleTeamClick = this.handleTeamClick.bind(this); - } - - handleTeamClick() { + handleTeamClick = () => { + addUserToTeamFromInvite('', '', this.props.team.invite_id, + () => { + browserHistory.push(`/${this.props.team.name}/channels/town-square`); + } + ); this.props.onTeamClick(this.props.team); } @@ -71,7 +69,6 @@ export default class SelectTeamItem extends React.Component { {showDescriptionTooltip} {this.props.team.display_name} diff --git a/webapp/components/select_team/select_team.jsx b/webapp/components/select_team/select_team.jsx index fe706af0f..7c90160bb 100644 --- a/webapp/components/select_team/select_team.jsx +++ b/webapp/components/select_team/select_team.jsx @@ -84,7 +84,6 @@ export default class SelectTeam extends React.Component { -- cgit v1.2.3-1-g7c22