Created
September 18, 2017 10:43
-
-
Save kwekuboateng/34d272733a78309b428f59094b54cc66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as actionType from './../Actions/actionTypes/orderActionTypes'; | |
import _ from 'lodash'; | |
const INITIAL_STATE = { | |
orders: [], | |
orderIsLoading: false, | |
orderFetchSuccess: false, | |
orderStatusChange: false | |
}; | |
const Order = ( state = INITIAL_STATE, action) => { | |
switch(action.type) { | |
case actionType.ORDER_ADD_NEW: | |
return state; | |
case actionType.DELETE_ORDER: | |
let remainingOrders = _.omit(state.orders, action.payload); | |
return ({ | |
...state, | |
orders: { | |
...remainingOrders | |
} | |
}); | |
case actionType.FETCH_ORDER: | |
return ({ | |
...state, | |
orders: [ | |
...state.orders, | |
...action.payload | |
] | |
}); | |
case actionType.ORDER_STATUS_CHANGE: | |
return({ | |
...state, | |
orderStatusChange: action.payload | |
}) | |
case actionType.ORDER_IS_LOADING: | |
return({ | |
...state, | |
orderIsLoading: action.payload | |
}) | |
case actionType.ORDER_FETCH_SUCCESS: | |
return({ | |
...state, | |
orderFetchSuccess: action.payload | |
}) | |
case actionType.EDIT_ORDER: | |
return ({ | |
...state, | |
...action.payload | |
}); | |
default: | |
return state; | |
} | |
}; | |
export default Order; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment