From e3e0207760732218cbdaea7377695a9c2dd51c49 Mon Sep 17 00:00:00 2001 From: Thomas Ferreira Date: Sat, 9 Dec 2017 13:32:49 +0100 Subject: [PATCH] Update AccountsSideList on accounts list edit --- application/app.py | 27 ++++++++++++------- static/src/actions/accounts.js | 8 ++++-- .../src/components/AccountsSideList/index.js | 3 --- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/application/app.py b/application/app.py index ad559b3..6ae7f00 100644 --- a/application/app.py +++ b/application/app.py @@ -139,13 +139,11 @@ def get_balances_route(): return jsonify(result=get_balances()) -@app.route("/api/accounts", methods=["GET"]) -@requires_auth def get_accounts(): - accountsList = [] - accountsObjects = Account.get_accounts(g.current_user) - for account in accountsObjects: - accountsList.append({ + accounts_list = [] + accounts_objects = Account.get_accounts(g.current_user) + for account in accounts_objects: + accounts_list.append({ 'id': account.id, 'label': account.label, 'bank': account.bank, @@ -153,7 +151,13 @@ def get_accounts(): 'bic': account.bic, 'projected_date': account.projected_date }) - return jsonify(result=accountsList) + return accounts_list + + +@app.route("/api/accounts", methods=["GET"]) +@requires_auth +def get_accounts_route(): + return jsonify(result=get_accounts()) @app.route("/api/accounts/create", methods=["POST"]) @@ -180,7 +184,8 @@ def create_account(): return jsonify( id=account.id, - balances=get_balances() + balances=get_balances(), + accounts=get_accounts() ) @@ -203,7 +208,8 @@ def edit_account(): return jsonify(message="Account with that IBAN already exists"), 409 return jsonify( - balances=get_balances() + balances=get_balances(), + accounts=get_accounts() ) @@ -224,7 +230,8 @@ def delete_account(): return jsonify(message="Failed to delete account."), 409 return jsonify( - status='ok' + status='ok', + accounts=get_accounts() ) diff --git a/static/src/actions/accounts.js b/static/src/actions/accounts.js index 66ab7a4..bfd9a3d 100644 --- a/static/src/actions/accounts.js +++ b/static/src/actions/accounts.js @@ -66,8 +66,9 @@ export function createAccount(token, account) { ) .then(parseJSON) .then(response => { - dispatch(selectAccount(response.id)) dispatch(receiveBalancesData(response.balances)) + dispatch(receiveAccountsData(response.accounts)) + dispatch(selectAccount(response.id)) }) .catch(error => { if (error.status === 401) { @@ -90,6 +91,7 @@ export function editAccount(token, account) { ) .then(parseJSON) .then(response => { + dispatch(receiveAccountsData(response.accounts)) dispatch(receiveBalancesData(response.balances)) }) .catch(error => { @@ -104,7 +106,9 @@ export function deleteAccount(token, id) { return dispatch => { delete_account(token, id) .then(parseJSON) - .then(response => {}) + .then(response => { + dispatch(receiveAccountsData(response.accounts)) + }) .catch(error => { if (error.status === 401) { dispatch(logoutAndRedirect(error)) diff --git a/static/src/components/AccountsSideList/index.js b/static/src/components/AccountsSideList/index.js index 57fc7ad..9adde86 100644 --- a/static/src/components/AccountsSideList/index.js +++ b/static/src/components/AccountsSideList/index.js @@ -130,19 +130,16 @@ export default class AccountsSideList extends React.Component { createAccount(account) { const token = this.props.token this.props.createAccount(token, account) - this.fetchData() } editAccount(account) { const token = this.props.token this.props.editAccount(token, account) - this.fetchData() } deleteAccount(id) { const token = this.props.token this.props.deleteAccount(token, id) - this.fetchData() this.selectDefaultAccount() }