// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import ConfirmModal from 'components/confirm_modal.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import Constants from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
import {updateActive} from 'actions/user_actions.jsx';
import {adminResetMfa} from 'actions/admin_actions.jsx';
import * as UserUtils from 'mattermost-redux/utils/user_utils';
import {FormattedMessage} from 'react-intl';
import PropTypes from 'prop-types';
import React from 'react';
export default class SystemUsersDropdown extends React.Component {
static propTypes = {
/*
* User to manage with dropdown
*/
user: PropTypes.object.isRequired,
/*
* Function to open password reset, takes user as an argument
*/
doPasswordReset: PropTypes.func.isRequired,
/*
* Function to open manage teams, takes user as an argument
*/
doManageTeams: PropTypes.func.isRequired,
/*
* Function to open manage roles, takes user as an argument
*/
doManageRoles: PropTypes.func.isRequired,
/*
* Function to open manage tokens, takes user as an argument
*/
doManageTokens: PropTypes.func.isRequired
};
constructor(props) {
super(props);
this.state = {
serverError: null,
showDemoteModal: false,
showDeactivateMemberModal: false,
user: null,
role: null
};
}
handleMakeActive = (e) => {
e.preventDefault();
updateActive(this.props.user.id, true, null,
(err) => {
this.setState({serverError: err.message});
}
);
}
handleManageTeams = (e) => {
e.preventDefault();
this.props.doManageTeams(this.props.user);
}
handleManageRoles = (e) => {
e.preventDefault();
this.props.doManageRoles(this.props.user);
}
handleManageTokens = (e) => {
e.preventDefault();
this.props.doManageTokens(this.props.user);
}
handleResetPassword = (e) => {
e.preventDefault();
this.props.doPasswordReset(this.props.user);
}
handleResetMfa = (e) => {
e.preventDefault();
adminResetMfa(this.props.user.id,
null,
(err) => {
this.setState({serverError: err.message});
}
);
}
handleDemoteSystemAdmin = (user, role) => {
this.setState({
serverError: this.state.serverError,
showDemoteModal: true,
user,
role
});
}
handleDemoteCancel = () => {
this.setState({
serverError: null,
showDemoteModal: false,
user: null,
role: null
});
}
handleDemoteSubmit = () => {
if (this.state.role === 'member') {
this.doMakeMember();
}
const teamUrl = TeamStore.getCurrentTeamUrl();
if (teamUrl) {
// the channel is added to the URL cause endless loading not being fully fixed
window.location.href = teamUrl + '/channels/town-square';
} else {
window.location.href = '/';
}
}
handleShowDeactivateMemberModal = (e) => {
e.preventDefault();
this.setState({showDeactivateMemberModal: true});
}
handleDeactivateMember = () => {
updateActive(this.props.user.id, false, null,
(err) => {
this.setState({serverError: err.message});
}
);
this.setState({showDeactivateMemberModal: false});
}
handleDeactivateCancel = () => {
this.setState({showDeactivateMemberModal: false});
}
renderDeactivateMemberModal = () => {
const title = (