Skip to content

Commit

Permalink
Fix-Create-Review-Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
basir committed Oct 28, 2020
1 parent 4f47ea7 commit e9f5a2a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions frontend/src/screens/ProductScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ const ProductScreen = ({ history, match }) => {
const productReviewCreate = useSelector((state) => state.productReviewCreate)
const {
success: successProductReview,
loading: loadingProductReview,
error: errorProductReview,
} = productReviewCreate

useEffect(() => {
if (successProductReview) {
alert('Review Submitted!')
setRating(0)
setComment('')
}
if (!product._id || product._id !== match.params.id) {
dispatch(listProductDetails(match.params.id))
dispatch({ type: PRODUCT_CREATE_REVIEW_RESET })
}
dispatch(listProductDetails(match.params.id))
}, [dispatch, match, successProductReview])

const addToCartHandler = () => {
Expand Down Expand Up @@ -161,6 +163,12 @@ const ProductScreen = ({ history, match }) => {
))}
<ListGroup.Item>
<h2>Write a Customer Review</h2>
{successProductReview && (
<Message variant='success'>
Review submitted successfully
</Message>
)}
{loadingProductReview && <Loader />}
{errorProductReview && (
<Message variant='danger'>{errorProductReview}</Message>
)}
Expand Down Expand Up @@ -190,7 +198,11 @@ const ProductScreen = ({ history, match }) => {
onChange={(e) => setComment(e.target.value)}
></Form.Control>
</Form.Group>
<Button type='submit' variant='primary'>
<Button
disabled={loadingProductReview}
type='submit'
variant='primary'
>
Submit
</Button>
</Form>
Expand Down

0 comments on commit e9f5a2a

Please sign in to comment.