birthReducer.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
49
'use strict';
import InitialState from './birthInitialState';
import Immutable, {Map} from 'immutable';
const {
GET_BIRTH_PRODUCT_REQUEST,
GET_BIRTH_PRODUCT_SUCCESS,
GET_BIRTH_PRODUCT_FAILURE,
SET_SHOW_ALERT_STATUS,
SET_BIRTH_COUPON_NOT_SUPPORT,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function birthReducer(state=initialState, action) {
switch(action.type) {
case GET_BIRTH_PRODUCT_REQUEST: {
return state.set('isFetching', true);
}
case GET_BIRTH_PRODUCT_SUCCESS:{
let json = action.payload;
return state.set('isFetching', false)
.set('list', Immutable.fromJS(json.list))
.set('currentPage', json.currentPage)
.set('pageCount', json.pageCount)
.set('total', json.total)
.set('endReached', json.endReached);
}
case GET_BIRTH_PRODUCT_FAILURE: {
return state.set('isFetching', false);
}
case SET_SHOW_ALERT_STATUS: {
return state.set('showAlert', action.payload);
}
case SET_BIRTH_COUPON_NOT_SUPPORT: {
return state.set('showAlert', true)
.set('notSupportReasons', action.payload.not_support_reasons)
.set('notSupportReasonsTitle', action.payload.not_support_reasons_title)
.set('notSupportReasonsMessage', action.payload.not_support_reasons_message);
}
}
return state;
}