orderListReducer.js
1.65 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
49
'use strict';
import InitialState from './orderListInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_ERROR,
SET_TIP_MESSAGE,
SELECT_ORDER_TYPE_SUCCESS,
GET_ORDER_LIST_REQUEST,
GET_ORDER_LIST_FAILURE,
GET_ORDER_LIST_SUCCESS,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function appReducer(state = initialState, action) {
switch (action.type) {
case SET_ERROR:
return state.set('error',action.payload);
case SET_TIP_MESSAGE:
return state.set('tipMessage', action.payload);
case SELECT_ORDER_TYPE_SUCCESS:
return state.set('currentOrderType', action.payload);
case GET_ORDER_LIST_REQUEST:
return state.set('isFetching', true)
.set('error', null);
case GET_ORDER_LIST_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case GET_ORDER_LIST_SUCCESS:
let json = action.payload;
return state.set('isFetching', false)
.set('error', null)
.set('currentOrderList', Immutable.fromJS(json.list))
.set('currentOrderListType', json.orderType)
.set('currentPage', json.currentPage)
.set('pageCount', json.pageCount)
.set('total', json.total)
.set('endReached', json.endReached)
.setIn(["orderList", json.orderType], Immutable.fromJS(json));
}
return state;
}