File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import { useSelector } from 'react-redux' ;
2+ import { useSelector , useDispatch } from 'react-redux' ;
33import { Link } from 'react-router-dom' ;
4+ import { showCart } from '../redux/actions/cartActions' ;
45
56const CartTotal = ( ) => {
67 const cart = useSelector ( ( state ) => state . cart ) ;
78 const { cartItems } = cart ;
89 const cartTotal = cartItems . reduce ( ( a , i ) => a + i . qty * i . price , 0 ) . toFixed ( 2 ) ;
10+
11+ const dispatch = useDispatch ( ) ;
12+ const closeCart = ( ) => {
13+ dispatch ( showCart ( false ) )
14+ }
915 return (
1016 < >
1117 < footer >
1218 < h3 className = "cart-total text-slanted" > total : ${ cartTotal } </ h3 >
1319 {
1420 cartItems . length > 0 ?
15- < Link to = "/shipping" > < button className = "cart-checkout btn" > checkout</ button > </ Link >
21+ < Link to = "/shipping" onClick = { closeCart } > < button className = "cart-checkout btn" > checkout</ button > </ Link >
1622 :
1723 ""
1824 }
You can’t perform that action at this time.
0 commit comments