bunch of fixes, need to refactoring to move state to the store in order to make it more fluxy
This commit is contained in:
@@ -5,6 +5,7 @@ class CreateChildren < ActiveRecord::Migration
|
||||
t.integer :gender
|
||||
t.date :date_of_birth
|
||||
t.integer :user_id
|
||||
t.boolean :on_the_way
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150319104317) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "carts", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.boolean "ordered", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "anonymous_id_string"
|
||||
t.integer "delivery_destination_id"
|
||||
t.boolean "confirmed"
|
||||
t.boolean "packed"
|
||||
t.boolean "canceled_on_check"
|
||||
t.boolean "canceled_on_delivery"
|
||||
t.boolean "delivered"
|
||||
t.text "internal_note"
|
||||
end
|
||||
|
||||
create_table "categories", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "section_id"
|
||||
t.string "image_url"
|
||||
t.integer "order"
|
||||
end
|
||||
|
||||
create_table "children", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "gender"
|
||||
t.date "date_of_birth"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
create_table "delivery_destinations", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "address"
|
||||
t.string "place"
|
||||
t.string "postal_code"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
t.text "note"
|
||||
t.boolean "email_verified"
|
||||
t.boolean "phone_verified"
|
||||
t.string "phone_verification_code"
|
||||
t.string "email_verification_code"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "user_id"
|
||||
t.string "anonymous_id_string"
|
||||
end
|
||||
|
||||
create_table "filter_criteria", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.string "field_name"
|
||||
t.integer "type"
|
||||
t.string "owner_type"
|
||||
t.integer "owner_id"
|
||||
end
|
||||
|
||||
create_table "filter_criteria_values", force: :cascade do |t|
|
||||
t.string "filter_text"
|
||||
t.string "filter_value"
|
||||
t.integer "filter_criteria_id"
|
||||
end
|
||||
|
||||
create_table "item_in_carts", force: :cascade do |t|
|
||||
t.integer "cart_id"
|
||||
t.integer "item_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "count"
|
||||
t.decimal "price"
|
||||
end
|
||||
|
||||
create_table "items", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "code", limit: 10
|
||||
t.decimal "current_input_price", precision: 5, scale: 2
|
||||
t.decimal "list_price", precision: 5, scale: 2
|
||||
t.integer "unit_id"
|
||||
t.decimal "units_in_pack", precision: 5, scale: 3
|
||||
t.text "description"
|
||||
t.integer "sub_category_id"
|
||||
t.integer "stock"
|
||||
t.boolean "on_display"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "tags"
|
||||
t.json "traits"
|
||||
t.integer "supplier_id"
|
||||
t.decimal "weight", precision: 5, scale: 3
|
||||
t.integer "special_offer_id"
|
||||
t.integer "supplier_id"
|
||||
end
|
||||
|
||||
create_table "media_types", force: :cascade do |t|
|
||||
t.string "name"
|
||||
end
|
||||
|
||||
create_table "multi_media_descriptions", force: :cascade do |t|
|
||||
t.string "url"
|
||||
t.integer "item_id"
|
||||
t.integer "media_type_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "places", force: :cascade do |t|
|
||||
t.string "postal_code"
|
||||
t.decimal "delivery_price"
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "sections", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "order"
|
||||
end
|
||||
|
||||
create_table "special_offers", force: :cascade do |t|
|
||||
t.string "image_url"
|
||||
t.boolean "start_page"
|
||||
t.integer "section_id"
|
||||
t.integer "category_id"
|
||||
t.integer "sub_category_id"
|
||||
t.integer "item_id"
|
||||
t.boolean "thank_you_page"
|
||||
t.boolean "search_result_page"
|
||||
t.boolean "checkout_page"
|
||||
t.date "beginning"
|
||||
t.date "ending"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "sub_categories", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "category_id"
|
||||
t.integer "order"
|
||||
end
|
||||
|
||||
create_table "suppliers", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "address"
|
||||
t.string "postal_code"
|
||||
t.string "town"
|
||||
t.string "phone"
|
||||
t.string "contact_person"
|
||||
t.string "email"
|
||||
t.text "note"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "units", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "short_name", limit: 4
|
||||
t.string "description_suffix"
|
||||
t.string "number_of_pieces_suffix"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "first_name"
|
||||
t.string "last_name"
|
||||
t.string "email"
|
||||
t.string "password_digest"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -4,11 +4,13 @@ class User < ActiveRecord::Base
|
||||
|
||||
accepts_nested_attributes_for :children
|
||||
|
||||
has_secure_password
|
||||
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
||||
has_secure_password :validations => false
|
||||
|
||||
validates :email, :uniqueness => {:case_sensitive => false, :message => "Email already exists!"},
|
||||
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "invalid email" }
|
||||
validates :first_name, :presence =>{ :message => "Ime je obavezno polje." }
|
||||
validates :last_name, :presence=>{ :message => "Prezime je obavezno polje." }
|
||||
|
||||
validates :password, confirmation: true, length: { in:6..20, too_short: 'password needs to be at least 6 characters long' }
|
||||
validates :email, :uniqueness => {:case_sensitive => false, :message => "Već postoji registrovani korisnik sa email adresom koju ste unijeli."},
|
||||
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "Neispravna email adresa." }
|
||||
|
||||
validates :password, :confirmation => { :message=> "Šifre se ne podudaraju.", :on => :create }, length: { too_long:'Šifra mora biti manja od 20 karaktera.', in:6..20, too_short: 'Šifra mora biti minimalne dužine od 6 karaktera.' }
|
||||
end
|
||||
|
||||
@@ -18,44 +18,75 @@ var Register = React.createClass({
|
||||
email: '',
|
||||
password: '',
|
||||
passwordConfirmation: '',
|
||||
registration: UserStore.getRegistrationState()
|
||||
registration: UserStore.getRegistrationState(),
|
||||
myBabyDOBDay: -1,
|
||||
myBabyDOBMonth: -1,
|
||||
myBabyDOBYear: -1,
|
||||
myBabyOnTheWay: false,
|
||||
loginState : UserStore.getLoginState()
|
||||
};
|
||||
},
|
||||
myBabyChange: function() {
|
||||
myBabyChange: function(e) {
|
||||
this.setState({
|
||||
myBabyDetailsVisible: true
|
||||
myBabyDetailsVisible: true,
|
||||
myBabyOnTheWay: (e.currentTarget.value === "1" ? true: false)
|
||||
});
|
||||
},
|
||||
renderMonthSelector: function() {
|
||||
var months = ['Januar', 'Februar', 'Mart', 'April', 'Maj', 'Juni',
|
||||
'Juli','August','Septembar', 'Oktobar','Novembar','Decembar'];
|
||||
|
||||
var monthsSelect = [];
|
||||
for(var i = 0; i < months.length; i++) {
|
||||
monthsSelect.push(<option value={i}>{months[i]}</option>)
|
||||
var monthsSelect = [<option value='-1'>Mjesec</option>];
|
||||
for(var i = 1; i <= months.length; i++) {
|
||||
monthsSelect.push(<option value={i}>{months[i - 1]}</option>)
|
||||
}
|
||||
|
||||
return (<select>{monthsSelect}</select>)
|
||||
return (<select onChange={this.onBabyDOBMonthChange}>{monthsSelect}</select>)
|
||||
},
|
||||
renderYearSelector: function() {
|
||||
var currentYear = (new Date().getFullYear());
|
||||
var years = [];
|
||||
years.push(<option>Godina</option>)
|
||||
years.push(<option value='-1'>Godina</option>)
|
||||
|
||||
for(var i = 0; i < 12; i++) {
|
||||
years.push(<option value={currentYear - i}>{currentYear - i}</option>)
|
||||
}
|
||||
|
||||
return (<select> {years} </select>)
|
||||
return (<select onChange={this.onBabyDOBYearChange}> {years} </select>)
|
||||
},
|
||||
renderDaySelector: function() {
|
||||
var days = [];
|
||||
days.push(<option>Dan</option>)
|
||||
days.push(<option value='-1'>Dan</option>)
|
||||
for(var i = 1; i <= 31; i++) {
|
||||
days.push(<option value={i}>{i}</option>)
|
||||
}
|
||||
|
||||
return (<select> {days} </select>)
|
||||
return (<select onChange={this.onBabyDOBDayChange}> {days} </select>)
|
||||
},
|
||||
onBabyDOBDayChange: function(e) {
|
||||
this.setState({
|
||||
myBabyDOBDay: e.currentTarget.value
|
||||
});
|
||||
},
|
||||
onBabyDOBMonthChange: function(e) {
|
||||
this.setState({
|
||||
myBabyDOBMonth: e.currentTarget.value
|
||||
});
|
||||
},
|
||||
onBabyDOBYearChange: function(e) {
|
||||
this.setState({
|
||||
myBabyDOBYear: e.currentTarget.value
|
||||
});
|
||||
},
|
||||
myBabyNameChange: function(e) {
|
||||
this.setState({
|
||||
babyName: e.currentTarget.value
|
||||
});
|
||||
},
|
||||
myBabyGenderChange: function(e) {
|
||||
this.setState({
|
||||
babyGender: e.currentTarget.value
|
||||
});
|
||||
},
|
||||
renderBabyDetails: function() {
|
||||
if (!this.state.myBabyDetailsVisible) {
|
||||
@@ -70,16 +101,16 @@ var Register = React.createClass({
|
||||
|
||||
<label for="baby_gender" className="col-md-4 control-label">Spol</label>
|
||||
<div className="col-md-4">
|
||||
<input type="radio" name="baby_gender"/> Djevojčica
|
||||
<input type="radio" name="baby_gender"/> Dječak
|
||||
<input type="radio" name="baby_gender"/> Jos ne znamo
|
||||
<input type="radio" name="baby_gender" value="0" onChange={this.myBabyGenderChange}/> Djevojčica
|
||||
<input type="radio" name="baby_gender" value="1" onChange={this.myBabyGenderChange}/> Dječak
|
||||
<input type="radio" name="baby_gender" value="2" onChange={this.myBabyGenderChange}/> Jos ne znamo
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
|
||||
<label for="baby_name" className="col-md-4 control-label">Ime</label>
|
||||
<div className="col-md-4">
|
||||
<input type="text" className="form-control" id="baby_name" placeholder="Ime bebe"/>
|
||||
<input type="text" className="form-control" id="baby_name" onChange={this.myBabyNameChange} placeholder="Ime bebe"/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
@@ -159,17 +190,30 @@ var Register = React.createClass({
|
||||
},
|
||||
onUserStoreChange: function() {
|
||||
this.setState({
|
||||
registration: UserStore.getRegistrationState()
|
||||
registration: UserStore.getRegistrationState(),
|
||||
loginState : UserStore.getLoginState()
|
||||
});
|
||||
},
|
||||
register: function(e) {
|
||||
if(this.validate()) {
|
||||
var children = [];
|
||||
if (this.state.myBabyDetailsVisible) {
|
||||
children.push({
|
||||
name: 'Dijete',
|
||||
gender: 1
|
||||
});
|
||||
|
||||
var dobOk = this.state.myBabyDOBDay !== -1 && this.state.myBabyDOBMonth !== -1 && this.state.myBabyDOBYear !== -1;
|
||||
|
||||
if (dobOk || this.state.babyName !== undefined || this.state.babyGender !== undefined) {
|
||||
var childInfo = {
|
||||
name: this.state.babyName,
|
||||
gender: this.state.babyGender,
|
||||
on_the_way: this.state.myBabyOnTheWay
|
||||
}
|
||||
|
||||
if(dobOk) {
|
||||
var dob = this.state.myBabyDOBDay + '/' + this.state.myBabyDOBMonth + '/' + this.state.myBabyDOBYear;
|
||||
childInfo.date_of_birth = dob;
|
||||
}
|
||||
children.push(childInfo);
|
||||
}
|
||||
}
|
||||
|
||||
var user = new UserRegistration({
|
||||
@@ -194,6 +238,17 @@ var Register = React.createClass({
|
||||
NavigationActions.goToHome();
|
||||
e.preventDefault();
|
||||
},
|
||||
prettyPrintError: function(err) {
|
||||
var errorInfo = [];
|
||||
for(var key in err) {
|
||||
if (err.hasOwnProperty(key)) {
|
||||
errorInfo.push(<li>{err[key]}</li>);
|
||||
}
|
||||
}
|
||||
return (<ul>
|
||||
{errorInfo}
|
||||
</ul>)
|
||||
},
|
||||
renderRegistrationState: function() {
|
||||
var rs = this.state.registration;
|
||||
if (!rs.performed) {
|
||||
@@ -202,7 +257,7 @@ var Register = React.createClass({
|
||||
} else if(rs.performed && !rs.success){
|
||||
return (<div>
|
||||
Desila se pogreška pri registraciji. Detalji greške su:
|
||||
{rs.error.responseJSON}
|
||||
{this.prettyPrintError(rs.error)}
|
||||
</div>)
|
||||
} else if (rs.performed && rs.success) {
|
||||
return (<div>
|
||||
@@ -216,6 +271,9 @@ var Register = React.createClass({
|
||||
var classes = cx({
|
||||
'hide': regSuccess
|
||||
});
|
||||
if (this.state.loginState.loggedIn) {
|
||||
return (<div>Vi ste već registrovani. Uživajte u kupovini.</div>)
|
||||
}
|
||||
return (<div>
|
||||
<span className="h3">Registracija</span>
|
||||
{this.renderRegistrationState()}
|
||||
@@ -265,8 +323,8 @@ var Register = React.createClass({
|
||||
<div className="form-group">
|
||||
<label for="my_baby" className="col-md-4 control-label">Moja beba</label>
|
||||
<div className="col-md-4">
|
||||
<input type="radio" onChange={this.myBabyChange} name="my_baby" id="already_born" /> Vec rođena
|
||||
<input type="radio" onChange={this.myBabyChange} id="on_the_way" name="my_baby" />Na putu
|
||||
<input type="radio" onChange={this.myBabyChange} name="my_baby" id="already_born" /> Vec rođena
|
||||
<input type="radio" onChange={this.myBabyChange} value="1" id="on_the_way" name="my_baby" />Na putu
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ var handleRegistrationFailure = function(error) {
|
||||
success: false,
|
||||
error: error
|
||||
};
|
||||
|
||||
|
||||
console.log('ERROR JE: ', error);
|
||||
};
|
||||
|
||||
var handleLoginSuccess = function(user) {
|
||||
@@ -141,4 +144,4 @@ AppDispatcher.register(function(payload) {
|
||||
|
||||
});
|
||||
|
||||
module.exports = UserStore;
|
||||
module.exports = UserStore;
|
||||
|
||||
Reference in New Issue
Block a user