export const setProductBySlug = slug => {
return async dispatch => {
dispatch({ type: SET_PRODUCT_BY_SLUG });
axios.get(`/api/products/${slug}`)
.then(data => {
dispatch({ type: SET_PRODUCT_BY_SLUG_SUCCEEDED, payload: data });
}).catch(err => {
dispatch({ type: SET_PRODUCT_BY_SLUG_FAILED, payload: err });
});
/*try {
const { data } = await axios.get(`/api/products/${slug}`);
dispatch({ type: SET_PRODUCT_BY_SLUG_SUCCEEDED, payload: data });
} catch (err) {
dispatch({ type: SET_PRODUCT_BY_SLUG_FAILED, payload: mapAxiosError(err) });
}*/
};
}
axios.get(`/api/product-comments/${productSlug}`).then(data => {setProductComments(data.data);});
{
userName: (USER_ID === 11) ? '' : users[USER_ID]['name'],
userEmail: users[USER_ID]['email'],
userLogo: users[USER_ID]['logo'],
commentsLength: allComments.length ? allComments.length : 0,
productSlug: this.props.productSlug,
productID: this.props.productID,
}
const mapDispatchToProps = dispatch => ({
setProductComments: comments => dispatch(setProductComments(comments))
});
const mapDispatchToProps = dispatch => ({
setProductComments
});