Skip to content

Commit

Permalink
Merge pull request #74 from tferreira/fixfetch
Browse files Browse the repository at this point in the history
Dispatch to reducers on data changes (PART 2)
  • Loading branch information
tferreira authored Dec 10, 2017
2 parents 2803647 + e3e0207 commit 83e40ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
28 changes: 18 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 @@ -179,7 +183,9 @@ def create_account():
return jsonify(message="Account with that IBAN already exists"), 409

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


Expand All @@ -202,7 +208,8 @@ def edit_account():
return jsonify(message="Account with that IBAN already exists"), 409

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


Expand All @@ -223,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
12 changes: 10 additions & 2 deletions static/src/actions/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
edit_account,
delete_account
} from '../utils/http_functions'
import { receiveBalancesData } from './balances'
import { logoutAndRedirect } from './auth'

export function receiveAccountsData(data) {
Expand Down Expand Up @@ -65,6 +66,8 @@ export function createAccount(token, account) {
)
.then(parseJSON)
.then(response => {
dispatch(receiveBalancesData(response.balances))
dispatch(receiveAccountsData(response.accounts))
dispatch(selectAccount(response.id))
})
.catch(error => {
Expand All @@ -87,7 +90,10 @@ export function editAccount(token, account) {
account.projected_date
)
.then(parseJSON)
.then(response => {})
.then(response => {
dispatch(receiveAccountsData(response.accounts))
dispatch(receiveBalancesData(response.balances))
})
.catch(error => {
if (error.status === 401) {
dispatch(logoutAndRedirect(error))
Expand All @@ -100,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
5 changes: 0 additions & 5 deletions static/src/components/AccountsSideList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,16 @@ export default class AccountsSideList extends React.Component {
createAccount(account) {
const token = this.props.token
this.props.createAccount(token, account)
this.props.updateBalance()
this.fetchData()
}

editAccount(account) {
const token = this.props.token
this.props.editAccount(token, account)
this.props.updateBalance()
this.fetchData()
}

deleteAccount(id) {
const token = this.props.token
this.props.deleteAccount(token, id)
this.fetchData()
this.selectDefaultAccount()
}

Expand Down

0 comments on commit 83e40ad

Please sign in to comment.