accountSettlementReducer.js
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
import AccountSettlementInitialState from './accountSettlementInitialState'
import Immutable, {List, Record} from 'immutable';
const {
ACCOUNT_LIST_REQUEST,
ACCOUNT_LIST_SUCCESS,
ACCOUNT_LIST_FAILURE,
SWITCH_SHOP,
LOGOUT,
} = require('../../constants/actionTypes').default;
const initialState = new AccountSettlementInitialState;
export default function messageReducer(state = initialState, action) {
if (!(state instanceof AccountSettlementInitialState)) return initialState.merge(state);
switch (action.type) {
case ACCOUNT_LIST_REQUEST: {
let nextState = state.set('isFetching', true)
.set('error', null);
return nextState;
}
break;
case ACCOUNT_LIST_SUCCESS: {
let {totalAmount, list} = action.payload;
let nextState = state.set('isFetching', false)
.set('error', null)
.set('sum', totalAmount || '0.00')
.set('list', Immutable.fromJS(list || []));
return nextState;
}
break;
case ACCOUNT_LIST_FAILURE: {
let nextState = state.set('isFetching', false)
.set('error', action.playload);
return nextState;
}
break;
case SWITCH_SHOP:
case LOGOUT:
return initialState;
break;
}
return state;
}