groupPurchaseDetailReducer.js
5.09 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
import InitialState from './groupPurchaseDetailInitialState';
import Immutable from 'immutable';
const {
SET_GROUP_NO,
SET_ACTIVITY_ID,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
RESOURCEINFO_REQUEST,
RESOURCEINFO_SUCCESS,
RESOURCEINFO_FAILURE,
ACTIVITY_GROUP_DETAIL_REQUEST,
ACTIVITY_GROUP_DETAIL_SUCCESS,
ACTIVITY_GROUP_DETAIL_FAILURE,
UPDATE_LEFTTIME,
SHOWSHARVIEW,
SHOWCOUPONVIEW,
SHOWSNAPSHOOTSHARE,
COUPONINFO_REQUEST,
COUPONINFO_SUCCESS,
COUPONINFO_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function couponReducer(state = initialState, action) {
if (!(state instanceof InitialState)) {
return initialState.merge(state);
}
switch (action.type) {
case SHOWSHARVIEW: {
return state.set('showShareView', action.payload);
}
case SHOWCOUPONVIEW: {
return state.set('showCouponView', action.payload);
}
case SHOWSNAPSHOOTSHARE: {
return state.set('showSnapshootShare', action.payload);
}
case SET_ACTIVITY_ID: {
return state.set('activityId', action.payload);
}
case SET_GROUP_NO: {
return state.set('groupNo', action.payload);
}
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_SUCCESS: {
let {
collageProductVoList,
page,
page_total,
total,
endReached,
} = action.payload;
return state.setIn(['productList', 'page'], page)
.setIn(['productList', 'pagetotal'], page_total)
.setIn(['productList', 'total'], total)
.setIn(['productList', 'list'], Immutable.fromJS(collageProductVoList))
.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], null)
.setIn(['productList', 'endReached'], endReached);
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
case RESOURCEINFO_REQUEST: {
return state.setIn(['resourceInfo', 'isFetching'], true)
.setIn(['resourceInfo', 'error'], null);
}
case RESOURCEINFO_SUCCESS: {
return state.setIn(['resourceInfo', 'isFetching'], false)
.setIn(['resourceInfo', 'resourceList'], Immutable.fromJS(action.payload))
.setIn(['resourceInfo', 'error'], null);
}
case RESOURCEINFO_FAILURE: {
return state.setIn(['resourceInfo', 'isFetching'], false)
.setIn(['resourceInfo', 'error'], action.payload);
}
case COUPONINFO_REQUEST: {
return state.setIn(['couponInfo', 'isFetching'], true)
.setIn(['couponInfo', 'error'], null);
}
case COUPONINFO_SUCCESS: {
return state.setIn(['couponInfo', 'isFetching'], false)
.setIn(['couponInfo', 'data'], action.payload)
.setIn(['couponInfo', 'error'], null);
}
case COUPONINFO_FAILURE: {
return state.setIn(['couponInfo', 'isFetching'], false)
.setIn(['couponInfo', 'error'], action.payload);
}
case ACTIVITY_GROUP_DETAIL_REQUEST: {
return state.setIn(['groupDetail', 'isFetching'], true)
.setIn(['groupDetail', 'error'], null);
}
case ACTIVITY_GROUP_DETAIL_SUCCESS: {
let {
groupId,
leftTime,
isNewCustomer,
pageGo,
groupRole,
lackNum,
openerJoinItem,
yourJoinItem,
membershipItems,
joinLimit,
} = action.payload;
return state.setIn(['groupDetail', 'isFetching'], false)
.setIn(['groupDetail', 'error'], null)
.setIn(['groupDetail', 'groupId'], groupId)
.setIn(['groupDetail', 'leftTime'], leftTime)
.setIn(['groupDetail', 'isNewCustomer'], isNewCustomer)
.setIn(['groupDetail', 'pageGo'], pageGo)
.setIn(['groupDetail', 'groupRole'], groupRole)
.setIn(['groupDetail', 'lackNum'], lackNum)
.setIn(['groupDetail', 'openerJoinItem'], Immutable.fromJS(openerJoinItem))
.setIn(['groupDetail', 'yourJoinItem'], Immutable.fromJS(yourJoinItem))
.setIn(['groupDetail', 'membershipItems'], Immutable.fromJS(membershipItems))
.setIn(['groupDetail', 'joinLimit'], joinLimit);
}
case ACTIVITY_GROUP_DETAIL_FAILURE: {
return state.setIn(['groupDetail', 'isFetching'], false)
.setIn(['groupDetail', 'error'], action.payload);
}
case UPDATE_LEFTTIME: {
return state.setIn(['groupDetail', 'leftTime'], action.payload);
}
}
return state;
}