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 1
1
import React from 'react' ;
2
- import { useSelector } from 'react-redux' ;
2
+ import { useSelector , useDispatch } from 'react-redux' ;
3
3
import { Link } from 'react-router-dom' ;
4
+ import { showCart } from '../redux/actions/cartActions' ;
4
5
5
6
const CartTotal = ( ) => {
6
7
const cart = useSelector ( ( state ) => state . cart ) ;
7
8
const { cartItems } = cart ;
8
9
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
+ }
9
15
return (
10
16
< >
11
17
< footer >
12
18
< h3 className = "cart-total text-slanted" > total : ${ cartTotal } </ h3 >
13
19
{
14
20
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 >
16
22
:
17
23
""
18
24
}
You can’t perform that action at this time.
0 commit comments