Skip to content

Commit b1bb669

Browse files
author
WebDeveloperGuide
committed
Shopping Cart > Checkout > Close car slide when redirect to login page.
1 parent 7753379 commit b1bb669

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

web_panel/src/components/CartTotal.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import React from 'react';
2-
import {useSelector} from 'react-redux';
2+
import {useSelector, useDispatch} from 'react-redux';
33
import {Link} from 'react-router-dom';
4+
import {showCart} from '../redux/actions/cartActions';
45

56
const 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
}

0 commit comments

Comments
 (0)