|
|
@ -3,6 +3,8 @@ |
|
|
|
<AddTxForm /> |
|
|
|
<AddTxForm /> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
import React from 'react'; |
|
|
|
import React from 'react'; |
|
|
|
|
|
|
|
import ReactMixin from 'react-mixin'; |
|
|
|
|
|
|
|
import Catalyst from 'react-catalyst'; |
|
|
|
import autobind from 'autobind-decorator'; |
|
|
|
import autobind from 'autobind-decorator'; |
|
|
|
|
|
|
|
|
|
|
|
@autobind |
|
|
|
@autobind |
|
|
@ -28,27 +30,32 @@ class TxForm extends React.Component { |
|
|
|
|
|
|
|
|
|
|
|
handleChange(evt) { |
|
|
|
handleChange(evt) { |
|
|
|
var currTx = this.state.tx; |
|
|
|
var currTx = this.state.tx; |
|
|
|
console.log(evt.target.name); |
|
|
|
|
|
|
|
console.log(evt.target.value); |
|
|
|
|
|
|
|
currTx[evt.target.name] = evt.target.value; |
|
|
|
currTx[evt.target.name] = evt.target.value; |
|
|
|
console.log(currTx); |
|
|
|
|
|
|
|
this.setState({updated: currTx}); |
|
|
|
this.setState({updated: currTx}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defaultTxState() { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
id: '', amount: '', currency: '', |
|
|
|
|
|
|
|
date: '2015-12-16', note: '' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resetForm() { |
|
|
|
|
|
|
|
this.setState({tx: this.defaultTxState()}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
render() { |
|
|
|
this.state = this.state || {}; |
|
|
|
this.state = this.state || {}; |
|
|
|
if (this.state.updated) { |
|
|
|
if (this.state.updated) { |
|
|
|
this.state.tx = this.state.updated; |
|
|
|
this.state.tx = this.state.updated; |
|
|
|
delete this.state["updated"]; |
|
|
|
delete this.state["updated"]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.state.tx = this.props.tx; |
|
|
|
this.state.tx = JSON.parse(JSON.stringify(this.props.tx)); |
|
|
|
} |
|
|
|
|
|
|
|
if (Object.keys(this.state.tx).length == 0) { |
|
|
|
|
|
|
|
this.state.tx = { |
|
|
|
|
|
|
|
id: '', amount: '', currency: '', |
|
|
|
|
|
|
|
date: '2015-12-16', note: '' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (Object.keys(this.state.tx).length == 0) |
|
|
|
|
|
|
|
this.state.tx = this.defaultTxState(); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<form className="tx-edit" ref="txForm" onSubmit={this.updateTx}> |
|
|
|
<form className="tx-edit" ref="txForm" onSubmit={this.updateTx}> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="grid-block"> |
|
|
@ -86,7 +93,8 @@ class TxForm extends React.Component { |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="grid-block"> |
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
<div className="small-12 medium-12 grid-content"> |
|
|
|
<input type="hidden" ref="id" value={this.state.tx.id} /> |
|
|
|
<input type="hidden" ref="id" value={this.state.tx.id} /> |
|
|
|
<button type="submit" className="success button">+ Add Tx</button> |
|
|
|
<button type="submit" className="success button">+ {( (this.state.tx.id) ? "Edit" : "Add" )} Tx</button> |
|
|
|
|
|
|
|
<button onClick={this.resetForm} className="default button">Reset</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
</form> |
|
|
@ -100,4 +108,6 @@ TxForm.propTypes = { |
|
|
|
tx : React.PropTypes.object, |
|
|
|
tx : React.PropTypes.object, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReactMixin.onClass(TxForm, Catalyst.LinkedStateMixin); |
|
|
|
|
|
|
|
|
|
|
|
export default TxForm; |
|
|
|
export default TxForm; |
|
|
|