Navigation Menu

Skip to content

Commit

Permalink
Fixing delay with initial values in Appo form
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkerio committed Aug 16, 2016
1 parent 26c5e42 commit 8177114
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
9 changes: 8 additions & 1 deletion app/assets/frontend/javascripts/actions/appos.js
Expand Up @@ -67,7 +67,8 @@ export function fulFillForm() {
.then(json => dispatch(setAppoForm(json)));
};
};


/* Auxiliar Method */
function setAppoForm(appo_arrays) {
return {
type: FULFILL_FORM,
Expand Down Expand Up @@ -103,7 +104,12 @@ function receiveAppo(update_form) {
};
};

/*
Load pets owned for a customer
owner defines if it gets the pets (:id, :name) for owner or for appointment model
*/
export function getPets(id, owner=true) {
console.log('############# In action getPets!!!');
return function (dispatch) {
let data = {
method: 'POST',
Expand All @@ -126,6 +132,7 @@ export function getPets(id, owner=true) {
};

export function setPets(pets_options) {
console.log('>>>>>>>>>>>>> Fields in setPets: ' + JSON.stringify(pets_options));
return {
type: SET_PETS,
pets_options
Expand Down
Expand Up @@ -56,7 +56,8 @@ class AppoModalNewComponent extends Component {
}

componentWillReceiveProps(nextProps) {
if ( JSON.stringify(nextProps.appo_arrays.owners) != JSON.stringify(this.state.owners_options) ) {
// if ( JSON.stringify(nextProps.appo_arrays.owners) != JSON.stringify(this.state.owners_options) ) {
if ( ! this.state.owners_options.length ) {
let action = ApposActionCreators.fulFillForm();
this.props.dispatch(action);
this.setState({
Expand All @@ -81,7 +82,6 @@ class AppoModalNewComponent extends Component {
let action = ApposActionCreators.createAppo(fields);
this.props.dispatch(action); // thunk middlew
console.log( ">>>>>> Sending data >>>>>>> " + JSON.stringify(fields));
// browserHistory.push('/appointments');
window.location='/appointments';
}

Expand All @@ -97,9 +97,10 @@ class AppoModalNewComponent extends Component {
}

changeOwner(value) {
this.setState({owner_id: value['value']});
this.setState({owner_id: value['value']}); // change owner
let action = ApposActionCreators.getPets(value['value'], true);
this.props.dispatch(action);
setTimeout(function(){ console.log(">> #># setTimeout 6000"); }, 6000);
this.setState({pets_options: this.props.pets_options});
}

Expand Down Expand Up @@ -161,7 +162,7 @@ class AppoModalNewComponent extends Component {
<Modal.Title>Modal Überschrift </Modal.Title>
</Modal.Header>
<Modal.Body>
<form>
<form>
<label htmlFor="owner">Eigentümer: </label>
<Select name="owners" options={this.state.owners_options} value={this.state.owner_id} onChange={this.changeOwner.bind(this)} />

Expand Down
42 changes: 39 additions & 3 deletions app/assets/javascripts/bundle.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions app/models/application_record.rb
@@ -1,3 +1,10 @@
# Chipotle Software (c) 2016 MIT License
class ApplicationRecord < ActiveRecord::Base

# To load a module
# include MyExtendedFeature

# Tells Rails to not use `application_records` as table name for all classes inheriting
# badname for than functionality BTW
self.abstract_class = true
end
4 changes: 2 additions & 2 deletions app/models/pet.rb
Expand Up @@ -4,10 +4,10 @@ class Pet < ApplicationRecord
belongs_to :kind
belongs_to :user


# Public: Returns pets
#
# appo_id - The Integer number of appointemnt id.
# id - integer number.
# owner - get pet(s) for owner or for appointment
#
# Returns hash object or nil.
def self.get_pets(id, owner)
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -8,6 +8,7 @@
"url": "https://github.com/aarkerio/rails4vet.git"
},
"dependencies": {
"ansi-regex": "^2.0.0",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
Expand Down

0 comments on commit 8177114

Please sign in to comment.