From e45c2f8d74f957c4ce40b25a61bd2978ca64fabb Mon Sep 17 00:00:00 2001 From: Sanghyuk Jeong Date: Fri, 14 May 2021 18:00:17 +0900 Subject: [PATCH] Reset productDetails before request --- frontend/src/actions/productActions.js | 2 ++ frontend/src/constants/productConstants.js | 1 + frontend/src/reducers/productReducers.js | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/frontend/src/actions/productActions.js b/frontend/src/actions/productActions.js index 647d59115..5abdfc903 100644 --- a/frontend/src/actions/productActions.js +++ b/frontend/src/actions/productActions.js @@ -7,6 +7,7 @@ import { PRODUCT_DETAILS_REQUEST, PRODUCT_DETAILS_SUCCESS, PRODUCT_DETAILS_FAIL, + PRODUCT_DETAILS_RESET, PRODUCT_DELETE_REQUEST, PRODUCT_DELETE_SUCCESS, @@ -34,6 +35,7 @@ import { export const listProducts = (keyword = '') => async (dispatch) => { try { + dispatch({ type: PRODUCT_DETAILS_RESET}) dispatch({ type: PRODUCT_LIST_REQUEST }) const { data } = await axios.get(`/api/products${keyword}`) diff --git a/frontend/src/constants/productConstants.js b/frontend/src/constants/productConstants.js index 2af5e28b5..b6efb3292 100644 --- a/frontend/src/constants/productConstants.js +++ b/frontend/src/constants/productConstants.js @@ -6,6 +6,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' diff --git a/frontend/src/reducers/productReducers.js b/frontend/src/reducers/productReducers.js index 8cf706084..457e41fcf 100644 --- a/frontend/src/reducers/productReducers.js +++ b/frontend/src/reducers/productReducers.js @@ -6,6 +6,7 @@ import { PRODUCT_DETAILS_REQUEST, PRODUCT_DETAILS_SUCCESS, PRODUCT_DETAILS_FAIL, + PRODUCT_DETAILS_RESET, PRODUCT_DELETE_REQUEST, PRODUCT_DELETE_SUCCESS, @@ -65,6 +66,9 @@ export const productDetailsReducer = (state = { product: { reviews: [] } }, acti case PRODUCT_DETAILS_FAIL: return { loading: false, error: action.payload } + + case PRODUCT_DETAILS_RESET: + return { product: { reviews: [] } } default: return state