detailReducer.js
1.28 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
'use strict';
import InitialState from './detailInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_ORDER_CODE,
GET_DETAIL_REQUEST,
GET_DETAIL_SUCCESS,
GET_DETAIL_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function detailReducer(state=initialState, action) {
switch(action.type) {
case SET_ORDER_CODE: {
return state.set('order_code', action.payload);
}
case GET_DETAIL_REQUEST: {
return state.setIn(['detail', 'isFetching'], true);
}
case GET_DETAIL_SUCCESS: {
let {
firstProductSKN,
expressType,
expressName,
acceptTime,
accept_address,
} = action.payload;
if (!firstProductSKN) {
firstProductSKN = '';
}
return state.setIn(['detail', 'isFetching'], false)
.setIn(['detail', 'data'], Immutable.fromJS(action.payload))
.set('firstProductSKN', firstProductSKN)
.set('expressType', expressType)
.set('expressName', expressName)
.set('acceptTime', acceptTime)
.set('accept_address', accept_address)
.setIn(['detail', 'error'], null);
}
case GET_DETAIL_FAILURE: {
return state.setIn(['detail', 'isFetching'], false)
.setIn(['detail', 'error'], action.payload);
}
}
return state;
}