cardDetailReducer.js
1.61 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
'use strict';
import InitialState from './cardDetailInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_ERROR,
SET_TIP_MESSAGE,
SET_CARD_ID_NO,
GET_CARD_DETAIL_REQUEST,
GET_CARD_DETAIL_FAILURE,
GET_CARD_DETAIL_SUCCESS,
UNBIND_CARD_SUCCESS,
TOGGLE_CARD_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 SET_CARD_ID_NO:
return state.set('cardIdNo', action.payload);
case GET_CARD_DETAIL_REQUEST:
return state.set('isFetching', true)
.set('error', null);
case GET_CARD_DETAIL_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case GET_CARD_DETAIL_SUCCESS:
return state.set('isFetching', false)
.set('error', null)
.set('cardInfo', Immutable.fromJS(action.payload));
case UNBIND_CARD_SUCCESS:
return state.set('showToast', true)
.set('showToastText', "解除成功!");
case TOGGLE_CARD_SUCCESS:
return state.set('showToast', true)
.setIn(['cardInfo', "masterType"], "1")
.set('showToastText', "切换成功!");
}
return state;
}