From f5fec3a157e6c9146a0c4e28dd5f70e6c066affd Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Fri, 28 Aug 2015 08:37:55 -0400
Subject: Added the ability to create a team with SSO services and added the
 ability to turn off email sign up.

---
 web/react/components/team_signup_with_sso.jsx | 137 ++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)
 create mode 100644 web/react/components/team_signup_with_sso.jsx

(limited to 'web/react/components/team_signup_with_sso.jsx')

diff --git a/web/react/components/team_signup_with_sso.jsx b/web/react/components/team_signup_with_sso.jsx
new file mode 100644
index 000000000..57996d7cc
--- /dev/null
+++ b/web/react/components/team_signup_with_sso.jsx
@@ -0,0 +1,137 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var client = require('../utils/client.jsx');
+var Constants = require('../utils/constants.jsx');
+
+export default class SSOSignUpPage extends React.Component {
+    constructor(props) {
+        super(props);
+
+        this.handleSubmit = this.handleSubmit.bind(this);
+        this.nameChange = this.nameChange.bind(this);
+
+        this.state = {name: ''};
+    }
+    handleSubmit(e) {
+        e.preventDefault();
+        var team = {};
+        var state = this.state;
+        state.nameError = null;
+        state.serverError = null;
+
+        team.display_name = this.state.name;
+
+        if (team.display_name.length <= 3) {
+            return;
+        }
+
+        if (!team.display_name) {
+            state.nameError = 'Please enter a team name';
+            this.setState(state);
+            return;
+        }
+
+        team.name = utils.cleanUpUrlable(team.display_name);
+        team.type = 'O';
+
+        client.createTeamWithSSO(team,
+            this.props.service,
+            function success(data) {
+                if (data.follow_link) {
+                    window.location.href = data.follow_link;
+                } else {
+                    window.location.href = '/';
+                }
+            },
+            function fail(err) {
+                state.serverError = err.message;
+                this.setState(state);
+            }.bind(this)
+        );
+    }
+    nameChange() {
+        this.setState({name: this.refs.teamname.getDOMNode().value.trim()});
+    }
+    render() {
+        var nameError = null;
+        var nameDivClass = 'form-group';
+        if (this.state.nameError) {
+            nameError = <label className='control-label'>{this.state.nameError}</label>;
+            nameDivClass += ' has-error';
+        }
+
+        var serverError = null;
+        if (this.state.serverError) {
+            serverError = <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>;
+        }
+
+        var disabled = false;
+        if (this.state.name.length <= 3) {
+            disabled = true;
+        }
+
+        var button = null;
+
+        if (this.props.service === Constants.GITLAB_SERVICE) {
+            button = (
+                <a
+                    className='btn btn-custom-login gitlab btn-full'
+                    href='#'
+                    onClick={this.handleSubmit}
+                    disabled={disabled}
+                >
+                    <span className='icon'/>
+                    <span>Create {strings.Team} with GitLab Account</span>
+                </a>
+            );
+        } else if (this.props.service === Constants.GOOGLE_SERVICE) {
+            button = (
+                <a
+                    className='btn btn-custom-login google btn-full'
+                    href='#'
+                    onClick={this.handleSubmit}
+                    disabled={disabled}
+                >
+                    <span className='icon'/>
+                    <span>Create {strings.Team} with Google Apps Account</span>
+                </a>
+            );
+        }
+
+        return (
+            <form
+                role='form'
+                onSubmit={this.handleSubmit}
+            >
+                <div className={nameDivClass}>
+                    <input
+                        autoFocus={true}
+                        type='text'
+                        ref='teamname'
+                        className='form-control'
+                        placeholder='Enter name of new team'
+                        maxLength='128'
+                        onChange={this.nameChange}
+                    />
+                    {nameError}
+                </div>
+                <div className='form-group'>
+                    {button}
+                    {serverError}
+                </div>
+                <div className='form-group margin--extra-2x'>
+                    <span><a href='/find_team'>{'Find my ' + strings.Team}</a></span>
+                </div>
+            </form>
+        );
+    }
+}
+
+SSOSignUpPage.defaultProps = {
+    service: ''
+};
+SSOSignUpPage.propTypes = {
+    service: React.PropTypes.string
+};
-- 
cgit v1.2.3-1-g7c22

