registration progress
This commit is contained in:
@@ -72,6 +72,12 @@ var NavigationActions = {
|
|||||||
actionType: NavigationConstants.CHANGE_URL,
|
actionType: NavigationConstants.CHANGE_URL,
|
||||||
url: '/dostava'
|
url: '/dostava'
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
goToHome: function() {
|
||||||
|
AppDispatcher.handleAction({
|
||||||
|
actionType: NavigationConstants.CHANGE_URL,
|
||||||
|
url: '/'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
39
front-ui/app/actions/userActions.js
Normal file
39
front-ui/app/actions/userActions.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
var AppDispatcher = require('../dispatcher/appDispatcher');
|
||||||
|
var UserConstants = require('../constants/userConstants');
|
||||||
|
|
||||||
|
// Define action methods
|
||||||
|
var UserActions = {
|
||||||
|
|
||||||
|
registerUser: function(user) {
|
||||||
|
AppDispatcher.handleAction({
|
||||||
|
actionType: UserConstants.REGISTER_USER,
|
||||||
|
user: user
|
||||||
|
});
|
||||||
|
|
||||||
|
user.save(null, {
|
||||||
|
success: function() {
|
||||||
|
alert('saved!');
|
||||||
|
UserActions.registrationSuccess();
|
||||||
|
},
|
||||||
|
error: function(model, response, options) {
|
||||||
|
alert('error');
|
||||||
|
console.log('error:', response);
|
||||||
|
UserActions.registrationFailure(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
registrationSuccess: function() {
|
||||||
|
AppDispatcher.handleAction({
|
||||||
|
actionType: UserConstants.REGISTRATION_SUCCESS
|
||||||
|
});
|
||||||
|
},
|
||||||
|
registrationFailure: function(error) {
|
||||||
|
AppDispatcher.handleAction({
|
||||||
|
actionType: UserConstants.REGISTRATION_FAILURE,
|
||||||
|
error: error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = UserActions;
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
var React = require("react/addons"),
|
var React = require("react/addons"),
|
||||||
UserRegistration = require('../../models/userRegistration'),
|
UserRegistration = require('../../models/userRegistration'),
|
||||||
RibicaValidationMixin = require('../../components/shared/mixins/ribicaValidationMixin');
|
RibicaValidationMixin = require('../../components/shared/mixins/ribicaValidationMixin'),
|
||||||
|
UserStore = require('../../stores/userStore'),
|
||||||
|
NavigationActions = require('../../actions/navigationActions'),
|
||||||
|
UserActions = require('../../actions/userActions');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Register = React.createClass({
|
var Register = React.createClass({
|
||||||
@@ -13,7 +17,8 @@ var Register = React.createClass({
|
|||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
passwordConfirmation: '',
|
passwordConfirmation: '',
|
||||||
errors: {}
|
errors: {},
|
||||||
|
registrationState: UserStore.getRegistrationState()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
myBabyChange: function() {
|
myBabyChange: function() {
|
||||||
@@ -149,10 +154,20 @@ var Register = React.createClass({
|
|||||||
renderErrorMessage: function(message){
|
renderErrorMessage: function(message){
|
||||||
return (<div className='error-message'>{message}</div>)
|
return (<div className='error-message'>{message}</div>)
|
||||||
},
|
},
|
||||||
doRegister: function(e) {
|
componentDidMount: function() {
|
||||||
|
UserStore.addChangeListener(this.onUserStoreChange);
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
UserStore.removeChangeListener(this.onUserStoreChange);
|
||||||
|
},
|
||||||
|
onUserStoreChange: function() {
|
||||||
|
this.setState({
|
||||||
|
registrationState: UserStore.getRegistrationState()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
register: function(e) {
|
||||||
// TODO: move this to the UserRegistrationStore
|
// TODO: move this to the UserRegistrationStore
|
||||||
if(this.validate()) {
|
if(this.validate()) {
|
||||||
alert('all fine!');
|
|
||||||
var user = new UserRegistration({
|
var user = new UserRegistration({
|
||||||
first_name: this.state.firstName,
|
first_name: this.state.firstName,
|
||||||
last_name: this.state.lastName,
|
last_name: this.state.lastName,
|
||||||
@@ -161,29 +176,41 @@ var Register = React.createClass({
|
|||||||
password_confirmation: this.state.passwordConfirmation
|
password_confirmation: this.state.passwordConfirmation
|
||||||
});
|
});
|
||||||
|
|
||||||
user.save(null, {
|
UserActions.registerUser(user);
|
||||||
success: function() {
|
|
||||||
alert('saved!');
|
|
||||||
},
|
|
||||||
error: function(model, response, options) {
|
|
||||||
alert('error');
|
|
||||||
console.log('error:', response);
|
|
||||||
}.bind(this)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
},
|
},
|
||||||
|
successContinue: function(e) {
|
||||||
|
NavigationActions.goToHome();
|
||||||
|
e.preventDefault();
|
||||||
|
},
|
||||||
|
renderRegistrationState: function() {
|
||||||
|
var rs = this.state.registrationState;
|
||||||
|
if (!rs.performed) {
|
||||||
|
|
||||||
|
return (<div></div>)
|
||||||
|
} else if(rs.performed && !rs.success){
|
||||||
|
return (<div>
|
||||||
|
Desila se pogreska pri registraciji. Detalji greske su:
|
||||||
|
{rs.error.responseJSON}
|
||||||
|
</div>)
|
||||||
|
} else if (rs.performed && rs.success) {
|
||||||
|
return (<div>
|
||||||
|
Uspjesno ste se registrovali na Ribicu. Kliknite <a onClick={this.successContinue}>ovdje</a> za nastavak.
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
},
|
||||||
render : function() {
|
render : function() {
|
||||||
|
var cx = React.addons.classSet;
|
||||||
|
var regSuccess = this.state.registrationState.performed && this.state.registrationState.success;
|
||||||
|
var classes = cx({
|
||||||
|
'hide': regSuccess
|
||||||
|
});
|
||||||
return (<div>
|
return (<div>
|
||||||
<span className="h3">Registracija</span>
|
<span className="h3">Registracija</span>
|
||||||
{this.state.firstName} |
|
{this.renderRegistrationState()}
|
||||||
{this.state.lastName} |
|
<div className="center" className={classes}>
|
||||||
{this.state.email} |
|
|
||||||
{this.state.password} |
|
|
||||||
{this.state.passwordConfirmation} |
|
|
||||||
{this.isValid() ? "yes" : "no"} |
|
|
||||||
<div className="center">
|
|
||||||
<form className="form-horizontal">
|
<form className="form-horizontal">
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@@ -239,7 +266,7 @@ var Register = React.createClass({
|
|||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<div className="col-md-4">
|
<div className="col-md-4">
|
||||||
|
|
||||||
<button onClick={this.doRegister} type="button" className="btn btn-default btn-lg">
|
<button onClick={this.register} type="button" className="btn btn-default btn-lg">
|
||||||
Register2
|
Register2
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
8
front-ui/app/constants/userConstants.js
Normal file
8
front-ui/app/constants/userConstants.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
var keyMirror = require('react/lib/keyMirror');
|
||||||
|
|
||||||
|
// Define action constants
|
||||||
|
module.exports = keyMirror({
|
||||||
|
REGISTER_USER : null,
|
||||||
|
REGISTRATION_SUCCESS: null,
|
||||||
|
REGISTRATION_FAILURE: null
|
||||||
|
});
|
||||||
87
front-ui/app/stores/userStore.js
Normal file
87
front-ui/app/stores/userStore.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
var AppDispatcher = require('../dispatcher/appDispatcher');
|
||||||
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
var UserConstants = require('../constants/userConstants');
|
||||||
|
var _ = require('underscore');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _registrationState = {};
|
||||||
|
|
||||||
|
var handleRegistrationSuccess = function() {
|
||||||
|
_registrationState = {
|
||||||
|
performed: true,
|
||||||
|
success: true
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var handleRegistrationFailure = function(error) {
|
||||||
|
_registrationState = {
|
||||||
|
performed: true,
|
||||||
|
success: false,
|
||||||
|
error: error
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Extend SectionStore with EventEmitter to add eventing capabilities
|
||||||
|
var UserStore = _.extend({}, EventEmitter.prototype, {
|
||||||
|
|
||||||
|
getRegistrationState: function() {
|
||||||
|
//return _categoryDetails;
|
||||||
|
return _registrationState;
|
||||||
|
},
|
||||||
|
// Emit Change event
|
||||||
|
emitChange: function() {
|
||||||
|
console.log("Emmiting Section change!");
|
||||||
|
this.emit('change');
|
||||||
|
},
|
||||||
|
|
||||||
|
// Add change listener
|
||||||
|
addChangeListener: function(callback) {
|
||||||
|
this.on('change', callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Remove change listener
|
||||||
|
removeChangeListener: function(callback) {
|
||||||
|
this.removeListener('change', callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Register callback with AppDispatcher
|
||||||
|
AppDispatcher.register(function(payload) {
|
||||||
|
var action = payload.action;
|
||||||
|
var text;
|
||||||
|
|
||||||
|
switch(action.actionType) {
|
||||||
|
|
||||||
|
// Respond to SELECT_ITEM action
|
||||||
|
//case SectionConstants.LOAD_SECTIONS:
|
||||||
|
//loadSections();
|
||||||
|
//break;
|
||||||
|
|
||||||
|
//case SectionConstants.SET_SECTION_HOVER:
|
||||||
|
//setHovered(action.section.get('id'));
|
||||||
|
//break;
|
||||||
|
|
||||||
|
//case SectionConstants.UNSET_SECTION_HOVER:
|
||||||
|
//setHovered('');
|
||||||
|
//break;
|
||||||
|
|
||||||
|
case UserConstants.REGISTRATION_SUCCESS:
|
||||||
|
handleRegistrationSuccess();
|
||||||
|
break;
|
||||||
|
case UserConstants.REGISTRATION_FAILURE:
|
||||||
|
handleRegistrationFailure(action.error);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If action was responded to, emit change event
|
||||||
|
UserStore.emitChange();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = UserStore;
|
||||||
Reference in New Issue
Block a user