// 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: 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 (
); } if (this.state.type === Constants.Integrations.COMMAND) { headerText = ( ); helpText = (

); tokenText = (

); } else if (this.state.type === Constants.Integrations.INCOMING_WEBHOOK) { headerText = ( ); helpText = (

); tokenText = (

); } else if (this.state.type === Constants.Integrations.OUTGOING_WEBHOOK) { headerText = ( ); helpText = (

); tokenText = (

); } else if (this.state.type === Constants.Integrations.OAUTH_APP) { let oauthApp = {}; for (var i = 0; i < this.state.oauthApps.length; i++) { if (this.state.oauthApps[i].id === this.state.id) { oauthApp = this.state.oauthApps[i]; break; } } if (oauthApp) { headerText = ( ); helpText = []; helpText.push(

); helpText.push(


); helpText.push(

); tokenText = (

); } } return (
{headerText}

{helpText} {tokenText}
); } }