From 12896bd23eeba79884245c1c29fdc568cf21a7fa Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 14 Mar 2016 08:50:46 -0400 Subject: Converting to Webpack. Stage 1. --- webapp/components/register_app_modal.jsx | 411 +++++++++++++++++++++++++++++++ 1 file changed, 411 insertions(+) create mode 100644 webapp/components/register_app_modal.jsx (limited to 'webapp/components/register_app_modal.jsx') diff --git a/webapp/components/register_app_modal.jsx b/webapp/components/register_app_modal.jsx new file mode 100644 index 000000000..c632233cf --- /dev/null +++ b/webapp/components/register_app_modal.jsx @@ -0,0 +1,411 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import * as Client from 'utils/client.jsx'; +import ModalStore from 'stores/modal_store.jsx'; + +import {Modal} from 'react-bootstrap'; + +import Constants from 'utils/constants.jsx'; +import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl'; + +const ActionTypes = Constants.ActionTypes; + +const holders = defineMessages({ + required: { + id: 'register_app.required', + defaultMessage: 'Required' + }, + optional: { + id: 'register_app.optional', + defaultMessage: 'Optional' + } +}); + +import React from 'react'; + +class RegisterAppModal extends React.Component { + constructor() { + super(); + + this.handleSubmit = this.handleSubmit.bind(this); + this.onHide = this.onHide.bind(this); + this.save = this.save.bind(this); + this.updateShow = this.updateShow.bind(this); + + this.state = { + clientId: '', + clientSecret: '', + saved: false, + show: false + }; + } + componentDidMount() { + ModalStore.addModalListener(ActionTypes.TOGGLE_REGISTER_APP_MODAL, this.updateShow); + } + componentWillUnmount() { + ModalStore.removeModalListener(ActionTypes.TOGGLE_REGISTER_APP_MODAL, this.updateShow); + } + updateShow(show) { + if (!show) { + if (this.state.clientId !== '' && !this.state.saved) { + return; + } + + this.setState({ + clientId: '', + clientSecret: '', + saved: false, + homepageError: null, + callbackError: null, + serverError: null, + nameError: null + }); + } + + this.setState({show}); + } + handleSubmit(e) { + e.preventDefault(); + + var state = this.state; + state.serverError = null; + + var app = {}; + + var name = this.refs.name.value; + if (!name || name.length === 0) { + state.nameError = true; + this.setState(state); + return; + } + state.nameError = null; + app.name = name; + + var homepage = this.refs.homepage.value; + if (!homepage || homepage.length === 0) { + state.homepageError = true; + this.setState(state); + return; + } + state.homepageError = null; + app.homepage = homepage; + + var desc = this.refs.desc.value; + app.description = desc; + + var rawCallbacks = this.refs.callback.value.trim(); + if (!rawCallbacks || rawCallbacks.length === 0) { + state.callbackError = true; + this.setState(state); + return; + } + state.callbackError = null; + app.callback_urls = rawCallbacks.split('\n'); + + Client.registerOAuthApp(app, + (data) => { + state.clientId = data.id; + state.clientSecret = data.client_secret; + this.setState(state); + }, + (err) => { + state.serverError = err.message; + this.setState(state); + } + ); + } + onHide(e) { + if (!this.state.saved && this.state.clientId !== '') { + e.preventDefault(); + return; + } + + this.setState({clientId: '', clientSecret: '', saved: false}); + } + save() { + this.setState({saved: this.refs.save.checked}); + } + render() { + const {formatMessage} = this.props.intl; + var nameError; + if (this.state.nameError) { + nameError = ( +
+ +
+ ); + } + var homepageError; + if (this.state.homepageError) { + homepageError = ( +
+ +
+ ); + } + var callbackError; + if (this.state.callbackError) { + callbackError = ( +
+ +
+ ); + } + var serverError; + if (this.state.serverError) { + serverError =
; + } + + var body = ''; + var footer = ''; + if (this.state.clientId === '') { + body = ( +
+
+

+ +

+
+ +
+ + {nameError} +
+
+
+ +
+ + {homepageError} +
+
+
+ +
+ +
+
+
+ +
+