detailReducer.js
937 Bytes
'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: {
return state.setIn(['detail', 'isFetching'], false)
.setIn(['detail', 'data'], Immutable.fromJS(action.payload))
.setIn(['detail', 'error'], null);
}
case GET_DETAIL_FAILURE: {
return state.setIn(['detail', 'isFetching'], false)
.setIn(['detail', 'error'], action.payload);
}
}
return state;
}