1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 21:52:08 +02:00
onion/js/components/signup_container.js

167 lines
5.6 KiB
JavaScript
Raw Normal View History

2015-06-20 16:43:18 +02:00
'use strict';
import React from 'react';
import Router from 'react-router';
import { mergeOptions } from '../utils/general_utils';
import { getLangText } from '../utils/lang_utils';
import UserStore from '../stores/user_store';
2015-06-20 16:43:18 +02:00
import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions';
import Form from './ascribe_forms/form';
import Property from './ascribe_forms/property';
2015-07-10 16:04:57 +02:00
import FormPropertyHeader from './ascribe_forms/form_property_header';
2015-06-20 16:43:18 +02:00
import InputCheckbox from './ascribe_forms/input_checkbox';
2015-07-10 15:56:54 +02:00
2015-06-20 16:43:18 +02:00
import apiUrls from '../constants/api_urls';
2015-06-22 10:50:22 +02:00
let SignupContainer = React.createClass({
2015-06-20 16:43:18 +02:00
mixins: [Router.Navigation],
getInitialState() {
return mergeOptions({
2015-06-22 10:50:22 +02:00
submitted: false,
message: null
}, UserStore.getState());
},
componentDidMount() {
UserStore.listen(this.onChange);
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
2015-06-22 10:50:22 +02:00
},
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-22 10:50:22 +02:00
handleSuccess(message){
this.setState({
submitted: true,
message: message
});
},
2015-06-20 16:43:18 +02:00
render() {
2015-06-22 10:50:22 +02:00
if (this.state.submitted){
return (
<div className="ascribe-login-wrapper">
<br/>
<div className="ascribe-login-text ascribe-login-header">
{this.state.message}
</div>
</div>
);
}
2015-06-20 16:43:18 +02:00
return (
<div className="ascribe-login-wrapper">
<br/>
2015-06-22 10:50:22 +02:00
<SignupForm handleSuccess={this.handleSuccess}/>
2015-06-20 16:43:18 +02:00
</div>
);
}
});
2015-06-22 10:50:22 +02:00
let SignupForm = React.createClass({
2015-07-10 15:56:54 +02:00
propTypes: {
handleSuccess: React.PropTypes.func
},
2015-06-20 16:43:18 +02:00
mixins: [Router.Navigation],
2015-06-22 10:50:22 +02:00
handleSuccess(response){
2015-06-20 16:43:18 +02:00
let notificationText = getLangText('Sign up successful');
2015-06-22 10:50:22 +02:00
let notification = new GlobalNotificationModel(notificationText, 'success', 50000);
2015-06-20 16:43:18 +02:00
GlobalNotificationActions.appendGlobalNotification(notification);
this.props.handleSuccess(getLangText('We sent an email to your address') + ' ' + response.user.email +
', ' + getLangText('please confirm') + '.');
2015-06-20 16:43:18 +02:00
},
2015-07-10 18:51:35 +02:00
getFormData(){
return {terms: this.refs.form.refs.terms.refs.input.state.value};
},
2015-06-20 16:43:18 +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-06-20 16:43:18 +02:00
return (
<Form
2015-07-10 16:04:57 +02:00
className="ascribe-form-bordered"
2015-06-22 10:50:22 +02:00
ref='form'
url={apiUrls.users_signup}
handleSuccess={this.handleSuccess}
2015-07-10 18:51:35 +02:00
getFormData={this.getFormData}
2015-06-22 10:50:22 +02:00
buttons={
<button type="submit" className="btn ascribe-btn ascribe-btn-login">
{getLangText('Sign up to ascribe')}
2015-06-22 10:50:22 +02:00
</button>}
spinner={
<button className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
</button>
}>
2015-07-10 16:04:57 +02:00
<FormPropertyHeader>
<h3>{getLangText('Welcome to ascribe')}</h3>
</FormPropertyHeader>
2015-06-20 16:43:18 +02:00
<Property
name='email'
label={getLangText('Email')}>
2015-06-20 16:43:18 +02:00
<input
type="email"
2015-07-07 10:28:39 +02:00
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
2015-06-20 16:43:18 +02:00
autoComplete="on"
required/>
</Property>
<Property
name='password'
label={getLangText('Password')}
2015-06-20 16:43:18 +02:00
tooltip={tooltipPassword}>
<input
type="password"
2015-07-07 10:28:39 +02:00
placeholder={getLangText('Use a combination of minimum 10 chars and numbers')}
2015-06-20 16:43:18 +02:00
autoComplete="on"
required/>
</Property>
<Property
name='password_confirm'
label={getLangText('Confirm Password')}
2015-06-20 16:43:18 +02:00
tooltip={tooltipPassword}>
<input
type="password"
placeholder={getLangText('Enter your password once again')}
2015-06-20 16:43:18 +02:00
autoComplete="on"
required/>
</Property>
<Property
name='promo_code'
label={getLangText('Promocode')}>
2015-06-20 16:43:18 +02:00
<input
2015-06-25 14:39:39 +02:00
type="text"
placeholder={getLangText('Enter a promocode here (Optional)')}/>
2015-06-20 16:43:18 +02:00
</Property>
2015-07-10 15:56:54 +02:00
<Property
name="terms"
2015-07-10 16:04:57 +02:00
className="ascribe-settings-property-collapsible-toggle"
style={{paddingBottom: 0}}>
2015-07-10 18:51:35 +02:00
<InputCheckbox/>
2015-07-10 15:56:54 +02:00
</Property>
2015-06-20 16:43:18 +02:00
</Form>
);
}
});
2015-06-22 10:50:22 +02:00
export default SignupContainer;