// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Client from '../utils/client.jsx'; import BrowserStore from '../stores/browser_store.jsx'; import UserStore from '../stores/user_store.jsx'; import Constants from '../utils/constants.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'mm-intl'; const holders = defineMessages({ passwordError: { id: 'team_signup_password.passwordError', defaultMessage: 'Please enter at least {chars} characters' }, creating: { id: 'team_signup_password.creating', defaultMessage: 'Creating team...' } }); class TeamSignupPasswordPage extends React.Component { constructor(props) { super(props); this.submitBack = this.submitBack.bind(this); this.submitNext = this.submitNext.bind(this); this.state = {}; } submitBack(e) { e.preventDefault(); this.props.state.wizard = 'username'; this.props.updateParent(this.props.state); } submitNext(e) { e.preventDefault(); var password = ReactDOM.findDOMNode(this.refs.password).value.trim(); if (!password || password.length < Constants.MIN_PASSWORD_LENGTH) { this.setState({passwordError: this.props.intl.formatMessage(holders.passwordError, {chars: Constants.MIN_PASSWORD_LENGTH})}); return; } this.setState({passwordError: null, serverError: null}); $('#finish-button').button('loading'); var teamSignup = JSON.parse(JSON.stringify(this.props.state)); teamSignup.user.password = password; teamSignup.user.allow_marketing = true; delete teamSignup.wizard; Client.createTeamFromSignup(teamSignup, () => { Client.track('signup', 'signup_team_08_complete'); var props = this.props; Client.loginByEmail(teamSignup.team.name, teamSignup.team.email, teamSignup.user.password, () => { UserStore.setLastEmail(teamSignup.team.email); if (this.props.hash > 0) { BrowserStore.setGlobalItem(this.props.hash, JSON.stringify({wizard: 'finished'})); } $('#sign-up-button').button('reset'); props.state.wizard = 'finished'; props.updateParent(props.state, true); window.location.href = '/' + teamSignup.team.name + '/channels/town-square'; }, (err) => { if (err.id === 'api.user.login.not_verified.app_error') { window.location.href = '/verify_email?email=' + encodeURIComponent(teamSignup.team.email) + '&teamname=' + encodeURIComponent(teamSignup.team.name); } else { this.setState({serverError: err.message}); $('#finish-button').button('reset'); } } ); }, (err) => { this.setState({serverError: err.message}); $('#finish-button').button('reset'); } ); } render() { Client.track('signup', 'signup_team_07_password'); var passwordError = null; var passwordDivStyle = 'form-group'; if (this.state.passwordError) { passwordError =
; passwordDivStyle = ' has-error'; } var serverError = null; if (this.state.serverError) { serverError =
; } return (

{this.props.state.team.email}
{passwordError} {serverError}

); } } TeamSignupPasswordPage.defaultProps = { state: {}, hash: '' }; TeamSignupPasswordPage.propTypes = { intl: intlShape.isRequired, state: React.PropTypes.object, hash: React.PropTypes.string, updateParent: React.PropTypes.func }; export default injectIntl(TeamSignupPasswordPage);