diff --git a/client/src/actions/user-actions.js b/client/src/actions/user-actions.js index 9279fa53..26caed17 100644 --- a/client/src/actions/user-actions.js +++ b/client/src/actions/user-actions.js @@ -4,6 +4,7 @@ const UserActions = Reflux.createActions([ 'checkLoginStatus', 'login', 'logout', + 'signup', 'sendRecoverPassword', 'recoverPassword' ]); diff --git a/client/src/app/main/main-signup/main-signup-page.js b/client/src/app/main/main-signup/main-signup-page.js index a4b9eb57..490bc060 100644 --- a/client/src/app/main/main-signup/main-signup-page.js +++ b/client/src/app/main/main-signup/main-signup-page.js @@ -1,19 +1,22 @@ import React from 'react'; -import {ListenerMixin} from 'reflux'; +import Reflux from 'reflux'; import ReCAPTCHA from 'react-google-recaptcha'; +import CommonActions from 'actions/common-actions'; import UserActions from 'actions/user-actions'; import UserStore from 'stores/user-store'; +import i18n from 'lib-app/i18n'; -import Button from 'core-components/button'; +import SubmitButton from 'core-components/submit-button'; +import Message from 'core-components/message'; import Form from 'core-components/form'; import Input from 'core-components/input'; import Widget from 'core-components/widget'; -import WidgetTransition from 'core-components/widget-transition'; -const CommonActions = require('actions/common-actions'); let MainSignUpPageWidget = React.createClass({ + + mixins: [Reflux.listenTo(UserStore, 'onUserStoreChanged')], componentDidMount() { if (UserStore.isLoggedIn()) { @@ -21,38 +24,75 @@ let MainSignUpPageWidget = React.createClass({ } }, + getInitialState() { + return { + loading: false, + email: null + }; + }, + render() { return (
- - -
-
- - - - -
-
- -
- -
-
-
+ +
+
+ + + + +
+
+ +
+ SIGN UP +
+ + {this.renderMessage()} +
); }, + + renderMessage() { + switch (this.state.message) { + case 'success': + return {i18n('SIGNUP_SUCCESS')}; + case 'fail': + return {i18n('EMAIL_EXISTS')}; + default: + return null; + } + }, + + getFormProps() { + return { + loading: this.state.loading, + className: 'signup-widget__form', + onSubmit: this.handleLoginFormSubmit + }; + }, getInputProps() { return { inputType: 'secondary', className: 'signup-widget__input' - } + }; }, handleLoginFormSubmit(formState) { - UserActions.login(formState.email, formState.password); + this.setState({ + loading: true + }); + + UserActions.signup(formState); + }, + + onUserStoreChanged(event) { + this.setState({ + loading: false, + message: (event === 'SIGNUP_FAIL') ? 'fail': 'success' + }); } }); diff --git a/client/src/app/main/main-signup/main-signup-page.scss b/client/src/app/main/main-signup/main-signup-page.scss index d2018cb5..b3e0824d 100644 --- a/client/src/app/main/main-signup/main-signup-page.scss +++ b/client/src/app/main/main-signup/main-signup-page.scss @@ -1,17 +1,21 @@ .main-signup-page { - height: 629px; + height: 669px; .signup-widget { padding: 30px; text-align: center; + &__form { + margin-bottom: 20px; + } + &__inputs { display: inline-block; margin: 0 auto; } &__captcha { - margin: 20px 0; + margin: 10px 84px 20px; height: 78px; width: 304px; } diff --git a/client/src/core-components/message.js b/client/src/core-components/message.js index 72a39b63..976a4630 100644 --- a/client/src/core-components/message.js +++ b/client/src/core-components/message.js @@ -15,7 +15,8 @@ const Message = React.createClass({ getDefaultProps() { return { - type: 'info' + type: 'info', + leftAligned: false }; }, diff --git a/client/src/data/fixtures/user-fixtures.js b/client/src/data/fixtures/user-fixtures.js index 11523e1a..78fdbd78 100644 --- a/client/src/data/fixtures/user-fixtures.js +++ b/client/src/data/fixtures/user-fixtures.js @@ -84,5 +84,24 @@ module.exports = [ }; } } + }, + { + path: 'user/signup', + time: 1000, + response: function (data) { + + if (data.email.length > 15) { + return { + status: 'success', + data: {} + }; + } else { + return { + status: 'fail', + message: 'Email already exists', + data: {} + }; + } + } } ]; diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index 1a24eea4..6a56b4ac 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -7,15 +7,19 @@ export default { 'RECOVER_SENT': 'An email with recover instructions has been sent.', 'NEW_PASSWORD': 'New password', 'REPEAT_NEW_PASSWORD': 'Repeat new password', - 'VALID_RECOVER': 'Password recovered successfully', - 'INVALID_RECOVER': 'Invalid recover data', 'BACK_LOGIN_FORM': 'Back to login form', - 'EMAIL_NOT_EXIST': 'Email does not exist', //ERRORS + 'EMAIL_NOT_EXIST': 'Email does not exist', 'ERROR_EMPTY': 'Invalid value', 'ERROR_PASSWORD': 'Invalid password', 'ERROR_NAME': 'Invalid name', 'ERROR_EMAIL': 'Invalid email', - 'PASSWORD_NOT_MATCH': 'Password does not match' + 'PASSWORD_NOT_MATCH': 'Password does not match', + 'INVALID_RECOVER': 'Invalid recover data', + + //MESSAGES + 'SIGNUP_SUCCESS': 'You have registered successfully in our support system.', + 'VALID_RECOVER': 'Password recovered successfully', + 'EMAIL_EXISTS': 'Email already exists, please try to log in or recover password' }; \ No newline at end of file diff --git a/client/src/stores/user-store.js b/client/src/stores/user-store.js index f70461d1..800a4bd7 100644 --- a/client/src/stores/user-store.js +++ b/client/src/stores/user-store.js @@ -12,6 +12,7 @@ const UserStore = Reflux.createStore({ this.listenTo(UserActions.checkLoginStatus, this.checkLoginStatus); this.listenTo(UserActions.login, this.loginUser); + this.listenTo(UserActions.signup, this.signupUser); this.listenTo(UserActions.logout, this.logoutUser); this.listenTo(UserActions.recoverPassword, this.recoverPassword); this.listenTo(UserActions.sendRecoverPassword, this.sendRecoverPassword); @@ -34,6 +35,13 @@ const UserStore = Reflux.createStore({ } }, + signupUser(signupData) { + return API.call({ + path: 'user/signup', + data: signupData + }).then(this.handleSignupSuccess, this.handleSignupFail); + }, + loginUser(loginData) { let onSuccessLogin = (loginData.remember) ? this.handleLoginSuccessWithRemember : this.handleLoginSuccess; let onFailedLogin = (loginData.isAutomatic) ? null : this.handleLoginFail; @@ -109,6 +117,14 @@ const UserStore = Reflux.createStore({ handleLoginFail() { this.trigger('LOGIN_FAIL'); + }, + + handleSignupSuccess() { + this.trigger('SIGNUP_SUCCESS'); + }, + + handleSignupFail() { + this.trigger('SIGNUP_FAIL'); } });