import PropTypes from 'prop-types'; // Copyright (c) 2016-present 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: PropTypes.object, location: PropTypes.object, loading: 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 (
); } if (this.state.type === Constants.Integrations.COMMAND) { headerText = (