Last active
September 26, 2017 18:54
-
-
Save kwekuboateng/4e4337c81b994768939f5007597363fd 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/productActionTypes'; | |
import _ from 'lodash'; | |
const INITIAL_STATE = { | |
products: {}, | |
singleProduct: {}, | |
toggleModal: false, | |
productIsSaving: false, | |
productSaved: false, | |
productEditShow: {} | |
}; | |
const productReducer = ( state = INITIAL_STATE, action) => { | |
switch(action.type) { | |
case actionType.ADD_NEW_PRODUCT: | |
return ({ | |
...state, | |
products: [...state.products, | |
action.payload | |
] | |
}); | |
case actionType.UPDATE_PRODUCT: | |
return ({ | |
...state, | |
}); | |
// case actionType.DELETE_PRODUCT: | |
// return ({ | |
// ...state, | |
// }); | |
case actionType.DELETE_PRODUCT: | |
let remainingProjects = _.omit(state.products, action.payload); | |
return ({ | |
...state, | |
products:{ | |
...remainingProjects | |
} | |
}); | |
case actionType.FETCH_PRODUCT: | |
let productObj = _.mapKeys(action.payload, '_id'); | |
return ({ | |
...state, | |
products: { | |
...productObj | |
} | |
}); | |
case actionType.FETCH_SINGLE_PRODUCT: | |
return ({ | |
...state, | |
singleProduct: action.payload | |
}) | |
case actionType.TOGGLE_CLOSE_MODAL: | |
return ({ | |
...state, | |
toggleModal: action.payload | |
}); | |
case actionType.PRODUCT_IS_SAVING: | |
return({ | |
...state, | |
productIsSaving: action.payload | |
}); | |
case actionType.PRODUCT_IS_SAVED: | |
return({ | |
...state, | |
productSaved: action.payload | |
}) | |
default: | |
return state; | |
} | |
}; | |
export {productReducer}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment