onion/js/components/ascribe_forms/form_signup.js

175 lines
6.3 KiB
JavaScript
Raw Normal View History

2015-06-11 17:22:11 +02:00
'use strict';
import React from 'react';
2015-07-13 16:57:25 +02:00
import Router from 'react-router';
2015-06-11 17:22:11 +02:00
2015-07-13 16:57:25 +02:00
import UserStore from '../../stores/user_store';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import Form from './form';
import Property from './property';
2015-06-11 17:22:11 +02:00
import InputCheckbox from './input_checkbox';
2015-07-13 16:57:25 +02:00
2015-10-01 09:45:12 +02:00
import AppConstants from '../../constants/application_constants';
2015-08-07 15:08:02 +02:00
import ApiUrls from '../../constants/api_urls';
2015-10-12 17:55:02 +02:00
import AscribeSpinner from '../ascribe_spinner';
import { getLangText } from '../../utils/lang_utils';
2015-07-13 16:57:25 +02:00
2015-06-11 17:22:11 +02:00
let SignupForm = React.createClass({
2015-07-13 16:57:25 +02:00
propTypes: {
2015-07-13 19:53:16 +02:00
headerMessage: React.PropTypes.string,
submitMessage: React.PropTypes.string,
2015-07-13 20:47:43 +02:00
handleSuccess: React.PropTypes.func,
children: React.PropTypes.element
2015-07-13 16:57:25 +02:00
},
mixins: [Router.Navigation, Router.State],
2015-07-13 16:57:25 +02:00
2015-07-13 19:53:16 +02:00
getDefaultProps() {
return {
2015-07-15 00:37:45 +02:00
headerMessage: getLangText('Welcome to ascribe'),
submitMessage: getLangText('Sign up')
2015-07-13 19:53:16 +02:00
};
},
2015-07-13 16:57:25 +02:00
getInitialState() {
return UserStore.getState();
2015-06-11 17:22:11 +02:00
},
2015-07-13 16:57:25 +02:00
componentDidMount() {
UserStore.listen(this.onChange);
let { redirect } = this.getQuery();
2015-10-01 15:38:37 +02:00
if (redirect && redirect !== 'signup'){
this.transitionTo(redirect, null, this.getQuery());
}
2015-07-13 16:57:25 +02:00
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
// if user is already logged in, redirect him to piece list
if(this.state.currentUser && this.state.currentUser.email) {
2015-10-01 09:45:12 +02:00
let { redirectAuthenticated } = this.getQuery();
if ( redirectAuthenticated) {
/*
* redirectAuthenticated contains an arbirary path
* eg pieces/<id>, editions/<bitcoin_id>, collection, settings, ...
* hence transitionTo cannot be used directly
*/
window.location = AppConstants.baseUrl + redirectAuthenticated;
}
window.setTimeout(() => this.transitionTo('pieces'));
2015-07-13 16:57:25 +02:00
}
2015-06-11 17:22:11 +02:00
},
handleSuccess(response){
if (response.user) {
let notification = new GlobalNotificationModel(getLangText('Sign up successful'), 'success', 50000);
GlobalNotificationActions.appendGlobalNotification(notification);
this.props.handleSuccess(getLangText('We sent an email to your address') + ' ' + response.user.email + ', ' + getLangText('please confirm') + '.');
}
else if (response.redirect) {
2015-10-01 09:45:12 +02:00
let { redirectAuthenticated } = this.getQuery();
if ( redirectAuthenticated) {
/*
* redirectAuthenticated contains an arbirary path
* eg pieces/<id>, editions/<bitcoin_id>, collection, settings, ...
* hence transitionTo cannot be used directly
*/
window.location = AppConstants.baseUrl + redirectAuthenticated;
}
this.transitionTo('pieces');
}
2015-07-13 16:57:25 +02:00
},
2015-07-28 15:33:47 +02:00
2015-09-16 19:00:59 +02:00
getFormData() {
if (this.getQuery().token){
return {token: this.getQuery().token};
}
return null;
},
2015-07-13 16:57:25 +02:00
render() {
let tooltipPassword = getLangText('Your password must be at least 10 characters') + '.\n ' +
getLangText('This password is securing your digital property like a bank account') + '.\n ' +
getLangText('Store it in a safe place') + '!';
2015-09-17 14:20:46 +02:00
let email = this.getQuery().email || null;
2015-06-11 17:22:11 +02:00
return (
2015-07-13 16:57:25 +02:00
<Form
className="ascribe-form-bordered"
ref='form'
2015-08-07 15:08:02 +02:00
url={ApiUrls.users_signup}
2015-09-16 19:00:59 +02:00
getFormData={this.getFormData}
2015-07-13 16:57:25 +02:00
handleSuccess={this.handleSuccess}
buttons={
2015-10-12 17:55:02 +02:00
<button type="submit" className="btn btn-default btn-wide">
2015-07-15 00:37:45 +02:00
{this.props.submitMessage}
2015-07-13 16:57:25 +02:00
</button>}
spinner={
2015-10-12 17:55:02 +02:00
<span className="btn btn-default btn-wide btn-spinner">
<AscribeSpinner color="dark-blue" size="md" />
</span>
2015-07-13 16:57:25 +02:00
}>
2015-08-06 10:23:01 +02:00
<div className="ascribe-form-header">
2015-07-15 00:37:45 +02:00
<h3>{this.props.headerMessage}</h3>
2015-08-06 10:23:01 +02:00
</div>
2015-07-13 16:57:25 +02:00
<Property
name='email'
label={getLangText('Email')}>
<input
type="email"
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
autoComplete="on"
2015-08-06 13:56:37 +02:00
defaultValue={email}
2015-07-13 16:57:25 +02:00
required/>
</Property>
<Property
name='password'
label={getLangText('Password')}
tooltip={tooltipPassword}>
<input
type="password"
placeholder={getLangText('Use a combination of minimum 10 chars and numbers')}
autoComplete="on"
required/>
</Property>
<Property
name='password_confirm'
label={getLangText('Confirm Password')}
tooltip={tooltipPassword}>
<input
type="password"
placeholder={getLangText('Enter your password once again')}
autoComplete="on"
required/>
</Property>
2015-07-13 20:47:43 +02:00
{this.props.children}
2015-07-13 16:57:25 +02:00
<Property
name="terms"
className="ascribe-property-collapsible-toggle"
2015-07-13 16:57:25 +02:00
style={{paddingBottom: 0}}>
2015-07-28 15:46:55 +02:00
<InputCheckbox>
2015-07-14 19:53:49 +02:00
<span>
2015-09-22 11:41:10 +02:00
{' ' + getLangText('I agree to the Terms of Service of ascribe') + ' '}
2015-07-15 16:57:41 +02:00
(<a href="https://www.ascribe.io/terms" target="_blank" style={{fontSize: '0.9em', color: 'rgba(0,0,0,0.7)'}}>
2015-07-14 19:53:49 +02:00
{getLangText('read')}
</a>)
</span>
</InputCheckbox>
2015-07-13 16:57:25 +02:00
</Property>
</Form>
2015-06-11 17:22:11 +02:00
);
}
});
2015-07-13 20:47:43 +02:00
2015-07-13 16:57:25 +02:00
export default SignupForm;