Skip to content

Commit

Permalink
Update AccountsSideList on accounts list edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Ferreira committed Dec 9, 2017
1 parent ce92bd9 commit e3e0207
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
27 changes: 17 additions & 10 deletions application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,25 @@ 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,
'iban': account.iban,
'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"])
Expand All @@ -180,7 +184,8 @@ def create_account():

return jsonify(
id=account.id,
balances=get_balances()
balances=get_balances(),
accounts=get_accounts()
)


Expand All @@ -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()
)


Expand All @@ -224,7 +230,8 @@ def delete_account():
return jsonify(message="Failed to delete account."), 409

return jsonify(
status='ok'
status='ok',
accounts=get_accounts()
)


Expand Down
8 changes: 6 additions & 2 deletions static/src/actions/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -90,6 +91,7 @@ export function editAccount(token, account) {
)
.then(parseJSON)
.then(response => {
dispatch(receiveAccountsData(response.accounts))
dispatch(receiveBalancesData(response.balances))
})
.catch(error => {
Expand All @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions static/src/components/AccountsSideList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit e3e0207

Please sign in to comment.