|
1 | 1 | import { useState, useRef } from 'react'; |
2 | | -import { Link } from 'react-router-dom'; |
3 | | -import { X } from 'lucide-react'; |
| 2 | +import { Link, useNavigate } from 'react-router-dom'; |
| 3 | +import { X, Heart, User } from 'lucide-react'; |
| 4 | +import { useSelector } from 'react-redux'; |
4 | 5 | import MobileShopMenu from './MobileShopMenu'; |
| 6 | +import CartIcon from '../CartComponent/CartIcon'; |
5 | 7 |
|
6 | | -const MobileMenu = ({ mobileOpen, setMobileOpen, mobileMenuRef }) => { |
| 8 | +const MobileMenu = ({ |
| 9 | + mobileOpen, |
| 10 | + setMobileOpen, |
| 11 | + mobileMenuRef, |
| 12 | + setCartOpen, |
| 13 | + setWishListOpen, |
| 14 | +}) => { |
7 | 15 | const [isInShopNavigation, setIsInShopNavigation] = useState(false); |
8 | 16 | const shopMenuRef = useRef(null); |
| 17 | + const navigate = useNavigate(); |
| 18 | + const isAuthenticated = useSelector((state) => state.auth.isAuthenticated); |
| 19 | + const wishListData = useSelector((state) => state.wishList); |
9 | 20 |
|
10 | 21 | const handleCloseMenu = () => { |
11 | 22 | setMobileOpen(false); |
@@ -85,20 +96,47 @@ const MobileMenu = ({ mobileOpen, setMobileOpen, mobileMenuRef }) => { |
85 | 96 | {/* Mobile Menu Icons */} |
86 | 97 | <div className="px-6 py-4 border-t border-gray-200"> |
87 | 98 | <div className="flex flex-col space-y-4"> |
88 | | - <Link |
89 | | - to="/wishlist" |
| 99 | + <button |
90 | 100 | className="flex items-center space-x-2 text-gray-700 hover:text-black cursor-pointer" |
91 | | - onClick={handleCloseMenu} |
| 101 | + onClick={() => { |
| 102 | + handleCloseMenu(); |
| 103 | + setWishListOpen(true); |
| 104 | + }} |
92 | 105 | > |
| 106 | + <div className="relative"> |
| 107 | + <Heart className="h-5 w-5" /> |
| 108 | + {wishListData?.items?.length > 0 && ( |
| 109 | + <span className="absolute -top-2 -right-2 bg-red-500 text-white text-xs font-bold rounded-full h-4 w-4 flex items-center justify-center"> |
| 110 | + {wishListData?.items?.length} |
| 111 | + </span> |
| 112 | + )} |
| 113 | + </div> |
93 | 114 | <span>Wishlist</span> |
94 | | - </Link> |
95 | | - <Link |
96 | | - to="/account" |
| 115 | + </button> |
| 116 | + <button |
97 | 117 | className="flex items-center space-x-2 text-gray-700 hover:text-black cursor-pointer" |
98 | | - onClick={handleCloseMenu} |
| 118 | + onClick={() => { |
| 119 | + handleCloseMenu(); |
| 120 | + if (!isAuthenticated) { |
| 121 | + navigate('/login'); |
| 122 | + } else { |
| 123 | + navigate('/profile'); |
| 124 | + } |
| 125 | + }} |
99 | 126 | > |
| 127 | + <User className="h-5 w-5" /> |
100 | 128 | <span>Account</span> |
101 | | - </Link> |
| 129 | + </button> |
| 130 | + <button |
| 131 | + className="flex items-center space-x-2 text-gray-700 hover:text-black cursor-pointer" |
| 132 | + onClick={() => { |
| 133 | + handleCloseMenu(); |
| 134 | + setCartOpen(true); |
| 135 | + }} |
| 136 | + > |
| 137 | + <CartIcon /> |
| 138 | + <span>Cart</span> |
| 139 | + </button> |
102 | 140 | </div> |
103 | 141 | </div> |
104 | 142 | </div> |
|
0 commit comments