Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PRODUCT_DETAILS_RESET #161

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/constants/productConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const PRODUCT_LIST_FAIL = 'PRODUCT_LIST_FAIL'
export const PRODUCT_DETAILS_REQUEST = 'PRODUCT_DETAILS_REQUEST'
export const PRODUCT_DETAILS_SUCCESS = 'PRODUCT_DETAILS_SUCCESS'
export const PRODUCT_DETAILS_FAIL = 'PRODUCT_DETAILS_FAIL'
export const PRODUCT_DETAILS_RESET = 'PRODUCT_DETAILS_RESET'

export const PRODUCT_DELETE_REQUEST = 'PRODUCT_DELETE_REQUEST'
export const PRODUCT_DELETE_SUCCESS = 'PRODUCT_DELETE_SUCCESS'
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/reducers/productReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PRODUCT_DETAILS_REQUEST,
PRODUCT_DETAILS_SUCCESS,
PRODUCT_DETAILS_FAIL,
PRODUCT_DETAILS_RESET,
PRODUCT_DELETE_REQUEST,
PRODUCT_DELETE_SUCCESS,
PRODUCT_DELETE_FAIL,
Expand Down Expand Up @@ -54,6 +55,8 @@ export const productDetailsReducer = (
return { loading: false, product: action.payload }
case PRODUCT_DETAILS_FAIL:
return { loading: false, error: action.payload }
case PRODUCT_DETAILS_RESET:
return { product: { reviews: [] } }
default:
return state
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Paginate from '../components/Paginate'
import ProductCarousel from '../components/ProductCarousel'
import Meta from '../components/Meta'
import { listProducts } from '../actions/productActions'
import { PRODUCT_DETAILS_RESET } from '../constants/productConstants'

const HomeScreen = ({ match }) => {
const keyword = match.params.keyword
Expand All @@ -22,6 +23,7 @@ const HomeScreen = ({ match }) => {

useEffect(() => {
dispatch(listProducts(keyword, pageNumber))
dispatch({ type: PRODUCT_DETAILS_RESET })
}, [dispatch, keyword, pageNumber])

return (
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/screens/ProductEditScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Message from '../components/Message'
import Loader from '../components/Loader'
import FormContainer from '../components/FormContainer'
import { listProductDetails, updateProduct } from '../actions/productActions'
import { PRODUCT_UPDATE_RESET } from '../constants/productConstants'
import { PRODUCT_UPDATE_RESET, PRODUCT_DETAILS_RESET } from '../constants/productConstants'

const ProductEditScreen = ({ match, history }) => {
const productId = match.params.id
Expand Down Expand Up @@ -36,6 +36,7 @@ const ProductEditScreen = ({ match, history }) => {
useEffect(() => {
if (successUpdate) {
dispatch({ type: PRODUCT_UPDATE_RESET })
dispatch({ type: PRODUCT_DETAILS_RESET })
history.push('/admin/productlist')
} else {
if (!product.name || product._id !== productId) {
Expand Down