<commit_before>// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import BackstageHeader from 'components/backstage/components/backstage_header.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import {Link} from 'react-router/es6';

import UserStore from 'stores/user_store.jsx';
import IntegrationStore from 'stores/integration_store.jsx';

import Constants from 'utils/constants.jsx';

export default class ConfirmIntegration extends React.Component {
    static get propTypes() {
        return {
            team: React.PropTypes.object,
            location: React.PropTypes.object,
            loading: React.PropTypes.bool
        };
    }

    constructor(props) {
        super(props);

        this.handleIntegrationChange = this.handleIntegrationChange.bind(this);

        const userId = UserStore.getCurrentId();

        this.state = {
            type: this.props.location.query.type,
            id: this.props.location.query.id,
            oauthApps: IntegrationStore.getOAuthApps(userId),
            loading: !IntegrationStore.hasReceivedOAuthApps(userId)
        };
    }

    componentDidMount() {
        IntegrationStore.addChangeListener(this.handleIntegrationChange);
    }

    componentWillUnmount() {
        IntegrationStore.removeChangeListener(this.handleIntegrationChange);
    }

    handleIntegrationChange() {
        const userId = UserStore.getCurrentId();

        this.setState({
            oauthApps: IntegrationStore.getOAuthApps(userId),
            loading: !IntegrationStore.hasReceivedOAuthApps(userId)
        });
    }

    render() {
        let headerText = null;
        let helpText = null;
        let tokenText = null;

        if (this.props.loading === true) {
            return (<div/>);
        }

        if (this.state.type === Constants.Integrations.COMMAND) {
            headerText = (
                <FormattedMessage
                    id={'installed_commands.header'}
                    defaultMessage='Slash Commands'
                />
            );
            helpText = (
                <p>
                    <FormattedHTMLMessage
                        id='add_command.doneHelp'<commit_msg>Close confirm_integration On Enter Keypress (#5600)<commit_after>// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import React from 'react';

import BackstageHeader from 'components/backstage/components/backstage_header.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import {Link, browserHistory} from 'react-router/es6';

import UserStore from 'stores/user_store.jsx';
import IntegrationStore from 'stores/integration_store.jsx';

import Constants from 'utils/constants.jsx';

export default class ConfirmIntegration extends React.Component {
    static get propTypes() {
        return {
            team: React.PropTypes.object,
            location: React.PropTypes.object,
            loading: React.PropTypes.bool
        };
    }

    constructor(props) {
        super(props);

        this.handleIntegrationChange = this.handleIntegrationChange.bind(this);
        this.handleKeyPress = this.handleKeyPress.bind(this);

        const userId = UserStore.getCurrentId();

        this.state = {
            type: this.props.location.query.type,
            id: this.props.location.query.id,
            oauthApps: IntegrationStore.getOAuthApps(userId),
            loading: !IntegrationStore.hasReceivedOAuthApps(userId)
        };
    }

    componentDidMount() {
        IntegrationStore.addChangeListener(this.handleIntegrationChange);
        window.addEventListener('keypress', this.handleKeyPress);
    }

    componentWillUnmount() {
        IntegrationStore.removeChangeListener(this.handleIntegrationChange);
        window.removeEventListener('keypress', this.handleKeyPress);
    }

    handleIntegrationChange() {
        const userId = UserStore.getCurrentId();

        this.setState({
            oauthApps: IntegrationStore.getOAuthApps(userId),
            loading: !IntegrationStore.hasReceivedOAuthApps(userId)
        });
    }

    handleKeyPress(e) {
        if (e.key === 'Enter') {
            browserHistory.push('/' + this.props.team.name + '/integrations/' + this.state.type);
        }
    }

    render() {
        let headerText = null;
        let helpText = null;
        let tokenText = null;

        if (this.props.loading === true) {
            return (<div/>);
        }

        if (this.state.type === Constants.Integrations.COMMAND) {
            headerText = (
                <FormattedMessage
                    id={'installed_commands.header'}
                    defaultMessage='Slash Commands'
                />
            );
            helpText = (
                <p>
                    <FormattedHTMLMessage
                        id='add_command.doneHelp'
{'fraction_non_alphanumeric': 0.1008234585258084, 'fraction_numerical': 0.0028118096003213497, 'mean_word_length': 2.2892998678996035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3399547', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1319, 'n_words': 249}