// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import LoadingScreen from 'components/loading_screen.jsx';
import RevokeTokenButton from 'components/admin_console/revoke_token_button';
import {Client4} from 'mattermost-redux/client';
import * as UserUtils from 'mattermost-redux/utils/user_utils';
import React from 'react';
import {Modal} from 'react-bootstrap';
import PropTypes from 'prop-types';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
export default class ManageTokensModal extends React.PureComponent {
static propTypes = {
/**
* Set to render the modal
*/
show: PropTypes.bool.isRequired,
/**
* The user the roles are being managed for
*/
user: PropTypes.object,
/**
* The user access tokens for a user, object with token ids as keys
*/
userAccessTokens: PropTypes.object,
/**
* Function called when modal is dismissed
*/
onModalDismissed: PropTypes.func.isRequired,
actions: PropTypes.shape({
/**
* Function to get a user's access tokens
*/
getUserAccessTokensForUser: PropTypes.func.isRequired
}).isRequired
};
constructor(props) {
super(props);
this.state = {error: null};
}
componentWillReceiveProps(nextProps) {
const userId = this.props.user ? this.props.user.id : null;
const nextUserId = nextProps.user ? nextProps.user.id : null;
if (nextUserId && nextUserId !== userId) {
this.props.actions.getUserAccessTokensForUser(nextUserId, 0, 200);
}
}
handleError = (error) => {
this.setState({
error
});
}
renderContents = () => {
const {user, userAccessTokens} = this.props;
if (!user) {
return