Commit 96066e31 authored by Joram Wilander's avatar Joram Wilander Committed by GitHub

MM-12496 Remove flux store usages in team* components (#1880)

* Remove flux store usages in team* components

* Fix bug not pulling joinable teams on load
parent b2054f42
......@@ -3,21 +3,15 @@
import {connect} from 'react-redux';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentRelativeTeamUrl} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import SystemUsersDropdown from './system_users_dropdown.jsx';
function mapStateToProps(state) {
const team = getCurrentTeam(state);
let teamUrl;
if (team) {
teamUrl = '/' + team.name;
}
return {
currentUser: getCurrentUser(state),
teamUrl,
teamUrl: getCurrentRelativeTeamUrl(state),
};
}
......
......@@ -3,12 +3,24 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getChannelStats} from 'mattermost-redux/actions/channels';
import {getTeamStats, updateTeamMemberSchemeRoles} from 'mattermost-redux/actions/teams';
import {getUser} from 'mattermost-redux/actions/users';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentRelativeTeamUrl} from 'mattermost-redux/selectors/entities/teams';
import TeamMembersDropdown from './team_members_dropdown.jsx';
function mapStateToProps(state) {
return {
currentUser: getCurrentUser(state),
currentChannelId: getCurrentChannelId(state),
teamUrl: getCurrentRelativeTeamUrl(state),
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
......@@ -20,4 +32,4 @@ function mapDispatchToProps(dispatch) {
};
}
export default connect(null, mapDispatchToProps)(TeamMembersDropdown);
export default connect(mapStateToProps, mapDispatchToProps)(TeamMembersDropdown);
......@@ -8,16 +8,16 @@ import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'utils/browser_history';
import {removeUserFromTeam} from 'actions/team_actions.jsx';
import {loadMyTeamMembers, updateActive} from 'actions/user_actions.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import * as Utils from 'utils/utils.jsx';
import ConfirmModal from 'components/confirm_modal.jsx';
export default class TeamMembersDropdown extends React.Component {
static propTypes = {
user: PropTypes.object.isRequired,
currentUser: PropTypes.object.isRequired,
currentChannelId: PropTypes.string.isRequired,
teamMember: PropTypes.object.isRequired,
teamUrl: PropTypes.string.isRequired,
actions: PropTypes.shape({
getUser: PropTypes.func.isRequired,
getTeamStats: PropTypes.func.isRequired,
......@@ -29,15 +29,6 @@ export default class TeamMembersDropdown extends React.Component {
constructor(props) {
super(props);
this.handleMakeMember = this.handleMakeMember.bind(this);
this.handleRemoveFromTeam = this.handleRemoveFromTeam.bind(this);
this.handleMakeActive = this.handleMakeActive.bind(this);
this.handleMakeNotActive = this.handleMakeNotActive.bind(this);
this.handleMakeAdmin = this.handleMakeAdmin.bind(this);
this.handleDemote = this.handleDemote.bind(this);
this.handleDemoteSubmit = this.handleDemoteSubmit.bind(this);
this.handleDemoteCancel = this.handleDemoteCancel.bind(this);
this.state = {
serverError: null,
showDemoteModal: false,
......@@ -46,8 +37,8 @@ export default class TeamMembersDropdown extends React.Component {
};
}
async handleMakeMember() {
const me = UserStore.getCurrentUser();
handleMakeMember = async () => {
const me = this.props.currentUser;
if (this.props.user.id === me.id && me.roles.includes('system_admin')) {
this.handleDemote(this.props.user, 'team_user');
} else {
......@@ -63,13 +54,11 @@ export default class TeamMembersDropdown extends React.Component {
}
}
handleRemoveFromTeam() {
handleRemoveFromTeam = () => {
removeUserFromTeam(
this.props.teamMember.team_id,
this.props.user.id,
() => {
UserStore.removeProfileFromTeam(this.props.teamMember.team_id, this.props.user.id);
UserStore.emitInTeamChange();
this.props.actions.getTeamStats(this.props.teamMember.team_id);
},
(err) => {
......@@ -78,10 +67,10 @@ export default class TeamMembersDropdown extends React.Component {
);
}
handleMakeActive() {
handleMakeActive = () => {
updateActive(this.props.user.id, true,
() => {
this.props.actions.getChannelStats(ChannelStore.getCurrentId());
this.props.actions.getChannelStats(this.props.currentChannelId);
this.props.actions.getTeamStats(this.props.teamMember.team_id);
},
(err) => {
......@@ -90,10 +79,10 @@ export default class TeamMembersDropdown extends React.Component {
);
}
handleMakeNotActive() {
handleMakeNotActive = () => {
updateActive(this.props.user.id, false,
() => {
this.props.actions.getChannelStats(ChannelStore.getCurrentId());
this.props.actions.getChannelStats(this.props.currentChannelId);
this.props.actions.getTeamStats(this.props.teamMember.team_id);
},
(err) => {
......@@ -102,8 +91,8 @@ export default class TeamMembersDropdown extends React.Component {
);
}
async handleMakeAdmin() {
const me = UserStore.getCurrentUser();
handleMakeAdmin = async () => {
const me = this.props.currentUser;
if (this.props.user.id === me.id && me.roles.includes('system_admin')) {
this.handleDemote(this.props.user, 'team_user team_admin');
} else {
......@@ -116,7 +105,7 @@ export default class TeamMembersDropdown extends React.Component {
}
}
handleDemote(user, role, newRole) {
handleDemote = (user, role, newRole) => {
this.setState({
serverError: this.state.serverError,
showDemoteModal: true,
......@@ -126,7 +115,7 @@ export default class TeamMembersDropdown extends React.Component {
});
}
handleDemoteCancel() {
handleDemoteCancel = () => {
this.setState({
serverError: null,
showDemoteModal: false,
......@@ -136,18 +125,13 @@ export default class TeamMembersDropdown extends React.Component {
});
}
async handleDemoteSubmit() {
handleDemoteSubmit = async () => {
const {error} = await this.props.actions.updateTeamMemberSchemeRoles(this.props.teamMember.team_id, this.props.user.id, true, false);
if (error) {
this.setState({serverError: error.message});
} else {
this.props.actions.getUser(this.props.user.id);
const teamUrl = TeamStore.getCurrentTeamUrl();
if (teamUrl) {
browserHistory.push(teamUrl);
} else {
browserHistory.push('/');
}
browserHistory.push(this.props.teamUrl);
}
}
......@@ -188,7 +172,7 @@ export default class TeamMembersDropdown extends React.Component {
);
}
const me = UserStore.getCurrentUser();
const me = this.props.currentUser;
let showMakeMember = (Utils.isAdmin(teamMember.roles) || teamMember.scheme_admin) && !Utils.isSystemAdmin(user.roles);
let showMakeAdmin = !Utils.isAdmin(teamMember.roles) && !Utils.isSystemAdmin(user.roles) && !teamMember.scheme_admin;
let showMakeActive = false;
......
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import TeamStore from 'stores/team_store.jsx';
import * as Utils from 'utils/utils.jsx';
import GeneralTab from './team_general_tab';
import ImportTab from './team_import_tab.jsx';
export default class TeamSettings extends React.Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.state = {team: TeamStore.getCurrent()};
}
componentDidMount() {
TeamStore.addChangeListener(this.onChange);
}
componentWillUnmount() {
TeamStore.removeChangeListener(this.onChange);
}
onChange() {
const team = TeamStore.getCurrent();
if (!Utils.areObjectsEqual(this.state.team, team)) {
this.setState({team});
}
}
render() {
if (!this.state.team) {
return null;
}
let result;
switch (this.props.activeTab) {
case 'general':
result = (
<div>
<GeneralTab
team={this.state.team}
activeSection={this.props.activeSection}
updateSection={this.props.updateSection}
closeModal={this.props.closeModal}
collapseModal={this.props.collapseModal}
/>
</div>
);
break;
case 'import':
result = (
<div>
<ImportTab
team={this.state.team}
activeSection={this.props.activeSection}
updateSection={this.props.updateSection}
closeModal={this.props.closeModal}
collapseModal={this.props.collapseModal}
/>
</div>
);
break;
default:
result = (
<div/>
);
break;
}
return result;
}
}
TeamSettings.defaultProps = {
activeTab: '',
activeSection: '',
};
TeamSettings.propTypes = {
activeTab: PropTypes.string.isRequired,
activeSection: PropTypes.string.isRequired,
updateSection: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
collapseModal: PropTypes.func.isRequired,
};
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import TeamSettings from './team_settings.jsx';
function mapStateToProps(state) {
return {
team: getCurrentTeam(state),
};
}
export default connect(mapStateToProps)(TeamSettings);
\ No newline at end of file
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import GeneralTab from 'components/team_general_tab';
import ImportTab from 'components/team_import_tab.jsx';
const TeamSettings = ({activeTab, activeSection, updateSection, closeModal, collapseModal, team}) => {
if (!team) {
return null;
}
let result;
switch (activeTab) {
case 'general':
result = (
<div>
<GeneralTab
team={team}
activeSection={activeSection}
updateSection={updateSection}
closeModal={closeModal}
collapseModal={collapseModal}
/>
</div>
);
break;
case 'import':
result = (
<div>
<ImportTab
team={team}
activeSection={activeSection}
updateSection={updateSection}
closeModal={closeModal}
collapseModal={collapseModal}
/>
</div>
);
break;
default:
result = (
<div/>
);
break;
}
return result;
};
TeamSettings.defaultProps = {
activeTab: '',
activeSection: '',
};
TeamSettings.propTypes = {
activeTab: PropTypes.string.isRequired,
activeSection: PropTypes.string.isRequired,
updateSection: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
collapseModal: PropTypes.func.isRequired,
team: PropTypes.object.isRequired,
};
export default TeamSettings;
\ No newline at end of file
......@@ -13,7 +13,7 @@ import {t} from 'utils/i18n';
import {AsyncComponent} from 'components/async_load';
import loadSettingsSidebar from 'bundle-loader?lazy!./settings_sidebar.jsx';
import TeamSettings from './team_settings.jsx';
import TeamSettings from './team_settings';
const holders = defineMessages({
generalTab: {
......
......@@ -4,9 +4,10 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getTeams} from 'mattermost-redux/actions/teams';
import {getMyTeams, getJoinableTeamIds, getTeamMemberships, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {withRouter} from 'react-router-dom';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getMyTeams, getJoinableTeamIds, getTeamMemberships, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {getIsLhsOpen} from 'selectors/lhs';
......
......@@ -30,6 +30,10 @@ export default class TeamSidebar extends React.PureComponent {
}).isRequired,
}
componentDidMount() {
this.props.actions.getTeams(0, 200);
}
render() {
const root = document.querySelector('#root');
if (this.props.myTeams.length <= 1) {
......
......@@ -10532,8 +10532,8 @@
"dev": true
},
"mattermost-redux": {
"version": "github:mattermost/mattermost-redux#f1453e5b9290e4f32db1e1566a0103cf33c0d9e4",
"from": "github:mattermost/mattermost-redux#f1453e5b9290e4f32db1e1566a0103cf33c0d9e4",
"version": "github:mattermost/mattermost-redux#4b1fadba2b4385293d188ca15893d9e716a27673",
"from": "github:mattermost/mattermost-redux#4b1fadba2b4385293d188ca15893d9e716a27673",
"requires": {
"deep-equal": "1.0.1",
"eslint-plugin-header": "1.2.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment