diff --git a/src/actions/TxActions.js b/src/actions/TxActions.js
index ca5d5ab..a2323f3 100644
--- a/src/actions/TxActions.js
+++ b/src/actions/TxActions.js
@@ -1,5 +1,5 @@
import AppDispatcher from '../dispatchers/AppDispatcher.js';
-import {TX_GET} from '../constants/TxConstants.js';
+import {TX_GET, TX_NEW} from '../constants/TxConstants.js';
export default {
@@ -8,6 +8,13 @@ export default {
actionType: TX_GET,
txs: txs
})
+ },
+
+ newTx: (tx) => {
+ AppDispatcher.dispatch({
+ actionType: TX_NEW,
+ tx: tx
+ })
}
}
diff --git a/src/components/AuthenticatedApp.js b/src/components/AuthenticatedApp.js
index e442333..cf53aca 100644
--- a/src/components/AuthenticatedApp.js
+++ b/src/components/AuthenticatedApp.js
@@ -41,7 +41,6 @@ export default class AuthenticatedApp extends React.Component {
@@ -61,17 +60,15 @@ export default class AuthenticatedApp extends React.Component {
)
} else {
return (
)
}
diff --git a/src/components/Login.js b/src/components/Login.js
index 709f3ea..a828f28 100644
--- a/src/components/Login.js
+++ b/src/components/Login.js
@@ -25,7 +25,23 @@ class Login extends React.Component {
render() {
return (
);
}
diff --git a/src/components/Tx.js b/src/components/Tx.js
index 58dd4ad..a2b1c73 100644
--- a/src/components/Tx.js
+++ b/src/components/Tx.js
@@ -61,20 +61,37 @@ class Tx extends React.Component {
)
}
+ newTx(tx) {
+ /*
+ creating tx via REST; if ok, push to this.state.txs too.
+ */
+ delete tx['id'];
+ TxService.newTx(tx);
+ }
+
updateTx(tx) {
- console.log("updateTx: " + tx);
+ tx.user = this.props.user.user_id;
+ if (!tx.id) {
+ this.newTx(tx);
+ }
}
render() {
return (
-
{this.state.account.title}
-
- {this.state.txs.map(this.renderTx)}
-
-
-
+
+
{this.state.account.title}
+
+
+
+
{this.state.txs.map(this.renderTx)}
+
+
+
+
+
+
)
}
diff --git a/src/components/TxForm.js b/src/components/TxForm.js
index ad0643d..0d00faf 100644
--- a/src/components/TxForm.js
+++ b/src/components/TxForm.js
@@ -21,7 +21,8 @@ class TxForm extends React.Component {
note : this.refs.note.value
}
// 3. Add the tx to the App State
- this.props.UpdateTx(tx);
+ // console.log(this.props);
+ this.props.txFormHandler(tx);
this.refs.txForm.reset();
}
@@ -67,4 +68,9 @@ class TxForm extends React.Component {
}
};
+TxForm.propTypes = {
+ txFormHandler : React.PropTypes.func.isRequired,
+ accounts : React.PropTypes.array.isRequired
+}
+
export default TxForm;
diff --git a/src/constants/TxConstants.js b/src/constants/TxConstants.js
index 8a27e3e..fbd81c8 100644
--- a/src/constants/TxConstants.js
+++ b/src/constants/TxConstants.js
@@ -1,7 +1,9 @@
var BASE_URL = 'http://rocket.dev/';
export default {
BASE_URL: BASE_URL,
- TX_URL_SUFFIX: '/txs',
+ TX_LIST_URL_SUFFIX: '/txs/',
+ TX_URL: BASE_URL + 'tx/',
ACCOUNT_GET: 'ACCOUNT_GET',
TX_GET: 'TX_GET',
+ TX_NEW: 'TX_NEW',
}
diff --git a/src/services/TxService.js b/src/services/TxService.js
index d02da81..45d6522 100644
--- a/src/services/TxService.js
+++ b/src/services/TxService.js
@@ -1,7 +1,7 @@
import request from 'reqwest';
import when from 'when';
import {ACCOUNT_URL} from '../constants/AccountConstants';
-import {TX_URL_SUFFIX} from '../constants/TxConstants';
+import {TX_URL, TX_LIST_URL_SUFFIX} from '../constants/TxConstants';
import TxActions from '../actions/TxActions';
import LoginStore from '../stores/LoginStore';
@@ -9,7 +9,7 @@ class AccountService {
getTxs(accountId) {
request({
- url: ACCOUNT_URL + accountId + TX_URL_SUFFIX + '/',
+ url: ACCOUNT_URL + accountId + TX_LIST_URL_SUFFIX,
method: 'GET',
headers: {
'Authorization': 'Bearer ' + LoginStore.jwt
@@ -20,6 +20,23 @@ class AccountService {
});
}
+ newTx(tx) {
+ request({
+ url: TX_URL,
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer ' + LoginStore.jwt
+ },
+ data: tx
+ })
+ .then(function(response) {
+ console.log('new tx created');
+ console.log(response);
+ TxActions.newTx(response);
+ console.log('---- new tx created ----');
+ });
+ }
+
}
export default new AccountService()
diff --git a/src/stores/TxStore.js b/src/stores/TxStore.js
index d757095..7b39c38 100644
--- a/src/stores/TxStore.js
+++ b/src/stores/TxStore.js
@@ -1,5 +1,5 @@
import {ACCOUNT_GET} from '../constants/AccountConstants';
-import {TX_GET} from '../constants/TxConstants';
+import {TX_GET, TX_NEW} from '../constants/TxConstants';
import {LOGOUT_USER} from '../constants/LoginConstants';
import BaseStore from './BaseStore';
@@ -22,6 +22,10 @@ class TxStore extends BaseStore {
this._txs = action.txs;
this.emitChange();
break;
+ case TX_NEW:
+ this._txs.push(action.tx);
+ this.emitChange();
+ break;
case LOGOUT_USER:
this._account = null;
this._txs = [];