1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-24 02:16:10 +01:00
onion/js/components/ascribe_forms/form_signup.js

138 lines
4.7 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 { getLangText } from '../../utils/lang_utils';
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';
import FormPropertyHeader from './form_property_header';
2015-06-11 17:22:11 +02:00
import InputCheckbox from './input_checkbox';
2015-07-13 16:57:25 +02:00
import apiUrls from '../../constants/api_urls';
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],
2015-07-13 19:53:16 +02:00
getDefaultProps() {
return {
headerMessage: 'Welcome to ascribe',
submitMessage: 'Sign up'
};
},
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);
},
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) {
this.transitionTo('pieces');
}
2015-06-11 17:22:11 +02:00
},
2015-07-13 16:57:25 +02:00
handleSuccess(response){
let notificationText = getLangText('Sign up successful');
let notification = new GlobalNotificationModel(notificationText, 'success', 50000);
GlobalNotificationActions.appendGlobalNotification(notification);
this.props.handleSuccess(getLangText('We sent an email to your address') + ' ' + response.user.email +
', ' + getLangText('please confirm') + '.');
},
getFormData(){
return {terms: this.refs.form.refs.terms.refs.input.state.value};
},
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-06-11 17:22:11 +02:00
return (
2015-07-13 16:57:25 +02:00
<Form
className="ascribe-form-bordered"
ref='form'
url={apiUrls.users_signup}
handleSuccess={this.handleSuccess}
getFormData={this.getFormData}
buttons={
<button type="submit" className="btn ascribe-btn ascribe-btn-login">
2015-07-13 19:53:16 +02:00
{getLangText(this.props.submitMessage)}
2015-07-13 16:57:25 +02:00
</button>}
spinner={
<span className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
2015-07-13 16:57:25 +02:00
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
</span>
2015-07-13 16:57:25 +02:00
}>
<FormPropertyHeader>
2015-07-13 19:53:16 +02:00
<h3>{getLangText(this.props.headerMessage)}</h3>
2015-07-13 16:57:25 +02:00
</FormPropertyHeader>
<Property
name='email'
label={getLangText('Email')}>
<input
type="email"
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
autoComplete="on"
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-settings-property-collapsible-toggle"
style={{paddingBottom: 0}}>
<InputCheckbox/>
</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;