summaryrefslogtreecommitdiffstats
path: root/webapp/components/admin_console/revoke_token_button/revoke_token_button.jsx
blob: 4829a0cde99e198e855b353aa1b3f2c3a65b94eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';

import {trackEvent} from 'actions/diagnostics_actions.jsx';

export default class RevokeTokenButton extends React.PureComponent {
    static propTypes = {

        /*
         * Token id to revoke
         */
        tokenId: PropTypes.string.isRequired,

        /*
         * Function to call on error
         */
        onError: PropTypes.func.isRequired,

        actions: PropTypes.shape({

            /**
             * Function to revoke a user access token
             */
            revokeUserAccessToken: PropTypes.func.isRequired
        }).isRequired
    };

    handleClick = async (e) => {
        e.preventDefault();

        const {error} = await this.props.actions.revokeUserAccessToken(this.props.tokenId);
        trackEvent('system_console', 'revoke_user_access_token');

        if (error) {
            this.props.onError(error.message);
        }
    }

    render() {
        return (
            <button
                className='btn btn-danger'
                onClick={this.handleClick}
            >
                <FormattedMessage
                    id='admin.revoke_token_button.delete'
                    defaultMessage='Delete'
                />
            </button>
        );
    }
}