outletReducer.js
7.56 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
'use strict';
import InitialState from './outletInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_ACTIVITY_FLITER,
SET_FLITER,
SHOW_TOAST,
HIDE_TOAST,
GET_CATEGORY_REQUEST,
GET_CATEGORY_SUCCESS,
GET_CATEGORY_FAILURE,
GET_OUTLETHOMERESOURCE_REQUEST,
GET_OUTLETHOMERESOURCE_SUCCESS,
GET_OUTLETHOMERESOURCE_FAILURE,
GET_PRODUCT_REQUEST,
GET_PRODUCT_SUCCESS,
GET_PRODUCT_FAILURE,
GET_OUTLET_ACTIVITY_LIST_REQUEST,
GET_OUTLET_ACTIVITY_LIST_SUCCESS,
GET_OUTLET_ACTIVITY_LIST_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function outletReducer(state=initialState, action) {
switch(action.type) {
case GET_CATEGORY_REQUEST: {
return state.setIn(['categoryList', 'isFetching'], true);
}
case GET_CATEGORY_SUCCESS: {
return state.setIn(['categoryList', 'list'], Immutable.fromJS(action.payload))
.setIn(['categoryList', 'isFetching'], false);
}
case GET_CATEGORY_FAILURE: {
return state.setIn(['categoryList', 'isFetching'], false)
.setIn(['categoryList', 'error'], action.payload);
}
case GET_OUTLETHOMERESOURCE_REQUEST: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.isFetching = true;
item.error = '';
item.ptr = action.payload.ptr;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_OUTLETHOMERESOURCE_SUCCESS: {
let categoryNavigationList;
if (action.payload.json.list) {
action.payload.json.list.map((item, i) => {
let template_name = item.template_name;
if (template_name == 'categoryNavigation') {
categoryNavigationList = item.data;
}
});
}
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.honeResource = action.payload.json;
item.categoryNavigationList = categoryNavigationList;
item.isFetching = false;
item.error = '';
item.ptr = false;
item.Navfliter = 0;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_OUTLETHOMERESOURCE_FAILURE: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
let error = action.payload.error;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.isFetching = false;
item.error = error;
item.ptr = false;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_PRODUCT_REQUEST: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
let categoryNavigationItem = action.payload.categoryNavigationItem;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.categoryNavigationList.map((item0, i) => {
let categoryName = item0.categoryName;
if (categoryNavigationItem.categoryName == categoryName) {
item0.isFetching = true;
item0.error = null;
}
});
}
});
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_PRODUCT_SUCCESS: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
let categoryNavigationItem = action.payload.categoryNavigationItem;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.categoryNavigationList.map((item0, i) => {
let categoryName = item0.categoryName;
if (categoryNavigationItem.categoryName == categoryName) {
item0.list = action.payload.json.list;
item0.isFetching = false;
item0.currentPage = action.payload.json.currentPage;
item0.endReached = action.payload.json.endReached;
item0.pageCount = action.payload.json.pageCount;
item0.total = action.payload.json.total;
}
});
}
});
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_PRODUCT_FAILURE: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
let categoryNavigationItem = action.payload.categoryNavigationItem;
let error = action.payload.error;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.categoryNavigationList.map((item0, i) => {
let categoryName = item0.categoryName;
if (categoryNavigationItem.categoryName == categoryName) {
item0.isFetching = false;
item0.error = error;
}
});
}
});
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_OUTLET_ACTIVITY_LIST_REQUEST: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.activityFetching = true;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_OUTLET_ACTIVITY_LIST_SUCCESS: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.activityList = action.payload.json;
item.activityMore = false;
item.activityFetching = false;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case GET_OUTLET_ACTIVITY_LIST_FAILURE: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.activityFetching = false;
item.error = action.payload.error;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case SET_ACTIVITY_FLITER: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.activityMore = action.payload.activityMore;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case SET_FLITER: {
let categoryList = state.categoryList.toJS();
let content_code1 = action.payload.content_code;
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.Navfliter = action.payload.value;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
}
case SHOW_TOAST:
return state.set('isShowToast', true).set('toastMessage', action.payload)
case HIDE_TOAST:
return state.set('isShowToast', false).set('toastMessage', '')
}
return state;
}