couponReducer.js
2.79 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
import InitialState from './couponInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_FLITER,
UNUSE_COUPON_LIST_REQUEST,
UNUSE_COUPON_LIST_SUCCESS,
UNUSE_COUPON_LIST_FAILURE,
USED_COUPON_LIST_REQUEST,
USED_COUPON_LIST_SUCCESS,
USED_COUPON_LIST_FAILURE,
SHOW_USED_COUPON_DETAIL,
SHOW_UNUSED_COUPON_DETAIL,
RESET_DATA,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function detailReducer(state=initialState, action) {
switch(action.type) {
case UNUSE_COUPON_LIST_REQUEST: {
return state.setIn(['unuseCoupon', 'isFetching'], true)
.setIn(['unuseCoupon', 'error'], null);
}
case UNUSE_COUPON_LIST_SUCCESS: {
return state.setIn(['unuseCoupon', 'isFetching'], false)
.setIn(['unuseCoupon', 'currentPage'], action.payload.currentPage)
.setIn(['unuseCoupon', 'pageSize'], action.payload.pageSize)
.setIn(['unuseCoupon', 'total'], action.payload.total)
.setIn(['unuseCoupon', 'endReached'], action.payload.endReached)
.setIn(['unuseCoupon', 'couponList'], Immutable.fromJS(action.payload.couponList))
.setIn(['unuseCoupon', 'error'], null);
}
case UNUSE_COUPON_LIST_FAILURE: {
return state.setIn(['unuseCoupon', 'isFetching'], false)
.setIn(['unuseCoupon', 'error'], action.payload);
}
case USED_COUPON_LIST_REQUEST: {
return state.setIn(['usedCoupon', 'isFetching'], true)
.setIn(['usedCoupon', 'error'], null);
}
case USED_COUPON_LIST_SUCCESS: {
return state.setIn(['usedCoupon', 'isFetching'], false)
.setIn(['usedCoupon', 'currentPage'], action.payload.currentPage)
.setIn(['usedCoupon', 'pageSize'], action.payload.pageSize)
.setIn(['usedCoupon', 'total'], action.payload.total)
.setIn(['usedCoupon', 'endReached'], action.payload.endReached)
.setIn(['usedCoupon', 'couponList'], Immutable.fromJS(action.payload.couponList))
.setIn(['usedCoupon', 'error'], null);
}
case USED_COUPON_LIST_FAILURE: {
return state.setIn(['usedCoupon', 'isFetching'], false)
.setIn(['usedCoupon', 'error'], action.payload);
}
case SET_FLITER: {
return state.set('fliter', action.payload);
}
case RESET_DATA: {
return state.setIn(['unuseCoupon', 'isFetching'], false)
.setIn(['unuseCoupon', 'currentPage'], 0)
.setIn(['unuseCoupon', 'pageSize'], 10)
.setIn(['unuseCoupon', 'total'], 0)
.setIn(['unuseCoupon', 'endReached'], false)
.setIn(['unuseCoupon', 'couponList'], Immutable.fromJS([]))
.setIn(['unuseCoupon', 'error'], null);
}
case SHOW_USED_COUPON_DETAIL: {
return state.setIn(['usedCoupon', 'couponList'], Immutable.fromJS(action.payload))
}
case SHOW_UNUSED_COUPON_DETAIL: {
return state.setIn(['unuseCoupon', 'couponList'], Immutable.fromJS(action.payload))
}
break;
}
return state;
}