From ef33f3fcd1fec2b3552293f6cdb8045dcc7d214d Mon Sep 17 00:00:00 2001 From: David Lu Date: Mon, 15 Aug 2016 11:10:31 -0400 Subject: PLT-3005 Added confirmation screen to integrations (#3747) --- .../integrations/components/add_command.jsx | 6 +- .../components/add_incoming_webhook.jsx | 6 +- .../integrations/components/add_oauth_app.jsx | 4 +- .../components/add_outgoing_webhook.jsx | 7 +- .../components/confirm_integration.jsx | 243 +++++++++++++++++++++ .../components/installed_incoming_webhook.jsx | 2 +- 6 files changed, 256 insertions(+), 12 deletions(-) create mode 100644 webapp/components/integrations/components/confirm_integration.jsx (limited to 'webapp/components/integrations') diff --git a/webapp/components/integrations/components/add_command.jsx b/webapp/components/integrations/components/add_command.jsx index 300e55a70..55fe9e121 100644 --- a/webapp/components/integrations/components/add_command.jsx +++ b/webapp/components/integrations/components/add_command.jsx @@ -160,8 +160,8 @@ export default class AddCommand extends React.Component { AsyncClient.addCommand( command, - () => { - browserHistory.push('/' + this.props.team.name + '/integrations/commands'); + (data) => { + browserHistory.push('/' + this.props.team.name + '/integrations/confirm?type=commands&id=' + data.token); }, (err) => { this.setState({ @@ -313,7 +313,7 @@ export default class AddCommand extends React.Component { /> diff --git a/webapp/components/integrations/components/add_incoming_webhook.jsx b/webapp/components/integrations/components/add_incoming_webhook.jsx index 4a3779aff..fa8a47a9c 100644 --- a/webapp/components/integrations/components/add_incoming_webhook.jsx +++ b/webapp/components/integrations/components/add_incoming_webhook.jsx @@ -73,8 +73,8 @@ export default class AddIncomingWebhook extends React.Component { AsyncClient.addIncomingHook( hook, - () => { - browserHistory.push('/' + this.props.team.name + '/integrations/incoming_webhooks'); + (data) => { + browserHistory.push('/' + this.props.team.name + '/integrations/confirm?type=incoming_webhooks&id=' + data.id); }, (err) => { this.setState({ @@ -114,7 +114,7 @@ export default class AddIncomingWebhook extends React.Component { /> diff --git a/webapp/components/integrations/components/add_oauth_app.jsx b/webapp/components/integrations/components/add_oauth_app.jsx index 7e56aea8f..4c01c5af0 100644 --- a/webapp/components/integrations/components/add_oauth_app.jsx +++ b/webapp/components/integrations/components/add_oauth_app.jsx @@ -144,8 +144,8 @@ export default class AddOAuthApp extends React.Component { OAuthActions.registerOAuthApp( app, - () => { - browserHistory.push('/' + this.props.team.name + '/integrations/oauth2-apps'); + (data) => { + browserHistory.push('/' + this.props.team.name + '/integrations/confirm?type=oauth2-apps&id=' + data.id); }, (err) => { this.setState({ diff --git a/webapp/components/integrations/components/add_outgoing_webhook.jsx b/webapp/components/integrations/components/add_outgoing_webhook.jsx index 540b565cd..bf0d327ef 100644 --- a/webapp/components/integrations/components/add_outgoing_webhook.jsx +++ b/webapp/components/integrations/components/add_outgoing_webhook.jsx @@ -119,8 +119,8 @@ export default class AddOutgoingWebhook extends React.Component { AsyncClient.addOutgoingHook( hook, - () => { - browserHistory.push('/' + this.props.team.name + '/integrations/outgoing_webhooks'); + (data) => { + browserHistory.push('/' + this.props.team.name + '/integrations/confirm?type=outgoing_webhooks&id=' + data.token); }, (err) => { this.setState({ @@ -176,6 +176,7 @@ export default class AddOutgoingWebhook extends React.Component { render() { const contentTypeOption1 = 'application/x-www-form-urlencoded'; const contentTypeOption2 = 'application/json'; + return (
@@ -186,7 +187,7 @@ export default class AddOutgoingWebhook extends React.Component { /> diff --git a/webapp/components/integrations/components/confirm_integration.jsx b/webapp/components/integrations/components/confirm_integration.jsx new file mode 100644 index 000000000..96e24c575 --- /dev/null +++ b/webapp/components/integrations/components/confirm_integration.jsx @@ -0,0 +1,243 @@ +// 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 {browserHistory, Link} from 'react-router/es6'; +import SpinnerButton from 'components/spinner_button.jsx'; + +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.isRequired, + location: React.PropTypes.object + }; + } + + constructor(props) { + super(props); + + this.handleDone = this.handleDone.bind(this); + + 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) + }); + } + + handleDone() { + browserHistory.push('/' + this.props.team.name + '/integrations/' + this.state.type); + this.setState({ + id: '' + }); + } + + render() { + let headerText = null; + let helpText = null; + let tokenText = null; + 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} +
+ + + +
+
+ ); + } +} diff --git a/webapp/components/integrations/components/installed_incoming_webhook.jsx b/webapp/components/integrations/components/installed_incoming_webhook.jsx index 965ed2bc9..2b514d5ec 100644 --- a/webapp/components/integrations/components/installed_incoming_webhook.jsx +++ b/webapp/components/integrations/components/installed_incoming_webhook.jsx @@ -102,7 +102,7 @@ export default class InstalledIncomingWebhook extends React.Component { />
-
+