From 20bb59222c6a3a9f3904c716765a92609f36994b Mon Sep 17 00:00:00 2001 From: sipp11 Date: Wed, 16 Dec 2015 04:25:31 +0700 Subject: [PATCH] UpdateForm --- src/components/AuthenticatedApp.js | 4 +-- src/components/Tx.js | 19 ++++++++++----- src/components/TxForm.js | 39 +++++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/components/AuthenticatedApp.js b/src/components/AuthenticatedApp.js index cf53aca..e7cf2c5 100644 --- a/src/components/AuthenticatedApp.js +++ b/src/components/AuthenticatedApp.js @@ -37,14 +37,14 @@ export default class AuthenticatedApp extends React.Component { -
+ {/*
-
+
*/} ); } diff --git a/src/components/Tx.js b/src/components/Tx.js index a2b1c73..85a5124 100644 --- a/src/components/Tx.js +++ b/src/components/Tx.js @@ -51,13 +51,21 @@ class Tx extends React.Component { getTxState() { return { account: AccountStore.account, - txs: TxStore.txs + txs: TxStore.txs, + tx: {} } } + changeTx(selTx) { + this.setState({tx: selTx}); + } + renderTx(tx) { return ( -
  • {tx.date} {tx.amount} {tx.currency}
  • +
  • + Edit + {tx.date} {tx.amount} {tx.currency} +
  • ) } @@ -77,7 +85,6 @@ class Tx extends React.Component { } render() { - return (
    @@ -85,12 +92,12 @@ class Tx extends React.Component {

    -
      {this.state.txs.map(this.renderTx)}
    +
      {this.state.txs.map(this.renderTx)}
    -
    - +
    ) diff --git a/src/components/TxForm.js b/src/components/TxForm.js index 0d00faf..413695a 100644 --- a/src/components/TxForm.js +++ b/src/components/TxForm.js @@ -26,20 +26,45 @@ class TxForm extends React.Component { this.refs.txForm.reset(); } + 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}); + } + 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: '' + }; + } return (
    - +
    - +
    - +
    +
    - +
    @@ -70,7 +96,8 @@ class TxForm extends React.Component { TxForm.propTypes = { txFormHandler : React.PropTypes.func.isRequired, - accounts : React.PropTypes.array.isRequired + accounts : React.PropTypes.array.isRequired, + tx : React.PropTypes.object, } export default TxForm;