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