Created
May 6, 2018 15:25
-
-
Save kwekuboateng/d2ebdeba9ae1443b868b3bc6a124ec95 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: {}, | |
newImage: {}, | |
productIsFetching: false | |
}; | |
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.FETCHING_PRODUCT: | |
return ({ | |
...state, | |
productIsFetching: action.payload | |
}) | |
case actionType.NEW_IMAGE: | |
return({ | |
...state, | |
newImage: action.payload | |
}) | |
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