1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-11-17 03:50:05 -05:00
moneygo/js/reducers/TransactionPageReducer.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-05-22 20:36:36 -04:00
var assign = require('object-assign');
2017-05-24 19:47:18 -04:00
var TransactionConstants = require('../constants/TransactionConstants');
2017-05-22 20:36:36 -04:00
var UserConstants = require('../constants/UserConstants');
2017-05-24 19:47:18 -04:00
var AccountConstants = require('../constants/AccountConstants');
2017-05-22 20:36:36 -04:00
var Account = require('../models').Account;
2017-05-24 19:47:18 -04:00
module.exports = function(state = {account: new Account(), pageSize: 1, page: 0, numPages: 0, transactions: [], endingBalance: "0", selection: -1, upToDate: false }, action) {
2017-05-22 20:36:36 -04:00
switch (action.type) {
2017-05-24 19:47:18 -04:00
case AccountConstants.ACCOUNT_SELECTED:
case TransactionConstants.FETCH_TRANSACTION_PAGE:
return assign({}, state, {
2017-05-22 20:36:36 -04:00
account: action.account,
pageSize: action.pageSize,
page: action.page,
numPages: 0,
transactions: [],
2017-05-24 19:47:18 -04:00
endingBalance: "0",
upToDate: true
});
case TransactionConstants.TRANSACTION_PAGE_FETCHED:
return assign({}, state, {
2017-05-22 20:36:36 -04:00
account: action.account,
pageSize: action.pageSize,
page: action.page,
numPages: action.numPages,
2017-05-24 19:47:18 -04:00
transactions: action.transactions.map(function(t) {return t.TransactionId}),
endingBalance: action.endingBalance,
upToDate: true
});
2017-05-22 20:36:36 -04:00
case UserConstants.USER_LOGGEDOUT:
return {
account: new Account(),
pageSize: 1,
page: 0,
numPages: 0,
transactions: [],
2017-05-24 19:47:18 -04:00
endingBalance: "0",
selection: -1,
upToDate: false
2017-05-22 20:36:36 -04:00
};
2017-05-24 19:47:18 -04:00
case TransactionConstants.TRANSACTION_CREATED:
case TransactionConstants.TRANSACTION_UPDATED:
return assign({}, state, {
upToDate: false
});
case TransactionConstants.TRANSACTION_REMOVED:
return assign({}, state, {
transactions: state.transactions.filter(function(t) {return t != action.transactionId}),
upToDate: false
});
case TransactionConstants.TRANSACTION_SELECTED:
return assign({}, state, {
selection: action.transactionId
});
case TransactionConstants.SELECTION_CLEARED:
return assign({}, state, {
selection: -1
});
2017-05-22 20:36:36 -04:00
default:
return state;
}
};