2015-06-11 17:22:11 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-10-01 11:16:38 +02:00
|
|
|
import { History } from 'react-router';
|
2015-06-11 17:22:11 +02:00
|
|
|
|
2015-07-13 16:57:25 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2016-01-11 19:10:24 +01:00
|
|
|
import UserActions from '../../actions/user_actions';
|
|
|
|
|
2015-07-13 16:57:25 +02:00
|
|
|
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-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,
|
2016-01-11 18:24:55 +01:00
|
|
|
location: React.PropTypes.object,
|
|
|
|
children: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element,
|
|
|
|
React.PropTypes.string
|
2016-03-04 14:27:56 +01:00
|
|
|
]),
|
2016-03-07 14:04:34 +01:00
|
|
|
whitelabelName: React.PropTypes.string
|
2015-07-13 16:57:25 +02:00
|
|
|
},
|
|
|
|
|
2015-10-01 11:16:38 +02:00
|
|
|
mixins: [History],
|
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-10-06 16:40:02 +02:00
|
|
|
|
2015-10-09 13:51:21 +02:00
|
|
|
handleSuccess(response) {
|
2015-08-05 19:22:58 +02:00
|
|
|
if (response.user) {
|
2016-01-11 18:24:55 +01:00
|
|
|
const notification = new GlobalNotificationModel(getLangText('Sign up successful'), 'success', 50000);
|
2015-08-05 19:22:58 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2016-01-11 18:24:55 +01:00
|
|
|
|
2015-10-06 16:40:02 +02:00
|
|
|
// Refactor this to its own component
|
2015-08-05 19:22:58 +02:00
|
|
|
this.props.handleSuccess(getLangText('We sent an email to your address') + ' ' + response.user.email + ', ' + getLangText('please confirm') + '.');
|
2015-10-06 16:40:02 +02:00
|
|
|
} else {
|
2015-11-02 15:38:37 +01:00
|
|
|
UserActions.fetchCurrentUser(true);
|
2015-08-05 19:22:58 +02:00
|
|
|
}
|
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() {
|
2016-01-11 18:24:55 +01:00
|
|
|
const { token } = this.props.location.query;
|
|
|
|
return token ? { token } : null;
|
2015-09-16 19:00:59 +02:00
|
|
|
},
|
|
|
|
|
2015-07-13 16:57:25 +02:00
|
|
|
render() {
|
2016-02-08 14:08:54 +01:00
|
|
|
const { children,
|
|
|
|
headerMessage,
|
|
|
|
location: { query: { email: emailQuery } },
|
2016-03-04 14:27:56 +01:00
|
|
|
submitMessage,
|
2016-03-07 14:04:34 +01:00
|
|
|
whitelabelName } = this.props;
|
2015-10-06 16:40:02 +02:00
|
|
|
|
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">
|
2016-01-11 18:24:55 +01:00
|
|
|
{submitMessage}
|
|
|
|
</button>
|
|
|
|
}
|
2015-07-13 16:57:25 +02:00
|
|
|
spinner={
|
2015-10-12 17:55:02 +02:00
|
|
|
<span className="btn btn-default btn-wide btn-spinner">
|
|
|
|
<AscribeSpinner color="dark-blue" size="md" />
|
2015-07-13 18:13:47 +02:00
|
|
|
</span>
|
2016-01-11 18:24:55 +01:00
|
|
|
}>
|
2015-08-06 10:23:01 +02:00
|
|
|
<div className="ascribe-form-header">
|
2016-03-04 14:27:56 +01:00
|
|
|
<h3>{whitelabelName ? `Welcome to ${whitelabelName}` : 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"
|
2016-01-12 15:07:38 +01:00
|
|
|
defaultValue={emailQuery}
|
2015-07-13 16:57:25 +02:00
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='password'
|
2016-03-07 14:04:34 +01:00
|
|
|
label={getLangText('Password')}>
|
2015-07-13 16:57:25 +02:00
|
|
|
<input
|
|
|
|
type="password"
|
2016-03-07 14:04:34 +01:00
|
|
|
placeholder={getLangText('Use a combination of minimum 10 characters and numbers')}
|
2015-07-13 16:57:25 +02:00
|
|
|
autoComplete="on"
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='password_confirm'
|
2016-03-07 14:04:34 +01:00
|
|
|
label={getLangText('Confirm Password')}>
|
2015-07-13 16:57:25 +02:00
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
placeholder={getLangText('Enter your password once again')}
|
|
|
|
autoComplete="on"
|
|
|
|
required/>
|
|
|
|
</Property>
|
2016-01-11 18:24:55 +01:00
|
|
|
{children}
|
2015-07-13 16:57:25 +02:00
|
|
|
<Property
|
|
|
|
name="terms"
|
2016-02-05 10:38:59 +01:00
|
|
|
className="ascribe-property-collapsible-toggle">
|
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;
|