fix: replace desktop and mobile onClick navigation handlers with standard next/link components in Header.tsx
This commit is contained in:
1 parent
565ef70840
commit
7d93a8d7c2
1 file changed
+52
-64
@@ -2,6 +2,7 @@
|
||||
import React, { useState, useRef, useEffect } from "react";
|
||||
import { Search, ChevronDown, Menu, X, Pill, ShieldCheck, HeartPulse, Sparkles, ShoppingBag, User, PlusCircle, Check, Building2, LogIn, Wallet, LogOut, MapPin, FileHeart, Dog, Cat } from "lucide-react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import Link from "next/link";
|
||||
import { useCartStore } from "../lib/store/cartStore";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
@@ -110,19 +111,17 @@ export default function Header({
|
||||
</button>
|
||||
|
||||
{/* Logo Section */}
|
||||
<div
|
||||
<Link
|
||||
href="/"
|
||||
className="flex-shrink-0 flex items-center gap-3 cursor-pointer group"
|
||||
onClick={() => {
|
||||
onNavigate("home");
|
||||
setIsMobileMenuOpen(false);
|
||||
}}
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
>
|
||||
<div className="w-12 h-12 bg-canina-blue rounded-2xl flex items-center justify-center text-white font-bold text-2xl group-hover:bg-medical-gray-900 transition-all shadow-xl shadow-canina-blue/20 italic">C</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-canina-blue font-black text-2xl tracking-tighter leading-none italic font-sans">Canina <span className="text-sm not-italic font-medium border-l-2 border-medical-gray-100 pl-2 ml-2 font-vazir">{getText('brand_name_fa', "ایران")}</span></span>
|
||||
<span className="text-[10px] text-medical-gray-400 font-bold uppercase tracking-widest leading-none mt-1.5 font-vazir">{getText('brand_subtitle', "نماینده رسمی Canina Pharma GmbH آلمان")}</span>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Navigation Items */}
|
||||
@@ -146,32 +145,27 @@ export default function Header({
|
||||
className="absolute top-[80%] right-0 w-[640px] bg-white border border-medical-gray-100 shadow-2xl rounded-[2.5rem] p-10 grid grid-cols-2 gap-10 z-50 pointer-events-auto"
|
||||
>
|
||||
{MENU_ITEMS.map((item, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="group/item cursor-pointer"
|
||||
onClick={() => {
|
||||
onShopNavigate(item.id);
|
||||
setIsMegaMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center gap-4 mb-4">
|
||||
<div key={idx} className="group/item">
|
||||
<Link
|
||||
href={`/shop?category=${item.id}`}
|
||||
onClick={() => setIsMegaMenuOpen(false)}
|
||||
className="flex items-center gap-4 mb-4 cursor-pointer block"
|
||||
>
|
||||
<div className="p-3 bg-medical-gray-50 rounded-2xl text-canina-blue group-hover/item:bg-canina-blue group-hover/item:text-white transition-all shadow-sm">
|
||||
{item.icon}
|
||||
</div>
|
||||
<h4 className="font-black text-medical-gray-900 text-sm font-vazir whitespace-nowrap">{item.title}</h4>
|
||||
</div>
|
||||
</Link>
|
||||
<ul className="space-y-2.5 border-r-2 border-medical-gray-50 pr-4">
|
||||
{item.solutions.map((sol, sIdx) => (
|
||||
<li
|
||||
key={sIdx}
|
||||
className="text-[12px] text-medical-gray-400 hover:text-canina-blue hover:translate-x-[-4px] transition-all font-bold cursor-pointer font-vazir whitespace-nowrap"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onShopNavigate(item.id, sol);
|
||||
setIsMegaMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
{sol}
|
||||
<li key={sIdx}>
|
||||
<Link
|
||||
href={`/shop?category=${item.id}&search=${sol}`}
|
||||
className="text-[12px] text-medical-gray-400 hover:text-canina-blue hover:translate-x-[-4px] transition-all font-bold cursor-pointer font-vazir whitespace-nowrap block"
|
||||
onClick={() => setIsMegaMenuOpen(false)}
|
||||
>
|
||||
{sol}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -183,18 +177,18 @@ export default function Header({
|
||||
</div>
|
||||
|
||||
{[
|
||||
{ id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), action: () => onShopNavigate() },
|
||||
{ id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), action: () => onNavigate('wiki') },
|
||||
{ id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), action: () => onNavigate('blog') },
|
||||
{ id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پتها'), action: () => onNavigate({ view: 'profile', subview: 'index' }) }
|
||||
{ id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), href: '/shop' },
|
||||
{ id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), href: '/wiki' },
|
||||
{ id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), href: '/blog' },
|
||||
{ id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پتها'), href: '/profile' }
|
||||
].map((item) => (
|
||||
<button
|
||||
<Link
|
||||
key={item.id}
|
||||
onClick={item.action}
|
||||
className={`px-4 py-3 rounded-xl text-sm font-black transition-all font-vazir whitespace-nowrap focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none min-h-[48px] ${currentView === item.id ? 'bg-canina-blue/5 text-canina-blue' : 'text-medical-gray-600 hover:bg-medical-gray-50 hover:text-canina-blue'}`}
|
||||
href={item.href}
|
||||
className={`px-4 py-3 rounded-xl text-sm font-black transition-all font-vazir whitespace-nowrap focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none min-h-[48px] flex items-center justify-center ${currentView === item.id ? 'bg-canina-blue/5 text-canina-blue' : 'text-medical-gray-600 hover:bg-medical-gray-50 hover:text-canina-blue'}`}
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
@@ -405,10 +399,10 @@ export default function Header({
|
||||
dir="rtl"
|
||||
>
|
||||
<div className="flex items-center justify-between border-b border-medical-gray-100 pb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href="/" className="flex items-center gap-3" onClick={() => setIsMobileMenuOpen(false)}>
|
||||
<div className="w-10 h-10 bg-canina-blue rounded-xl flex items-center justify-center text-white font-bold text-xl italic">C</div>
|
||||
<span className="text-canina-blue font-black text-xl italic font-sans">Canina</span>
|
||||
</div>
|
||||
</Link>
|
||||
<button
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
className="p-2 rounded-xl hover:bg-medical-gray-50 text-medical-gray-600 transition-all"
|
||||
@@ -438,28 +432,24 @@ export default function Header({
|
||||
>
|
||||
{MENU_ITEMS.map((item, idx) => (
|
||||
<div key={idx} className="py-1">
|
||||
<div
|
||||
className="text-[13px] font-bold text-medical-gray-800 font-vazir hover:text-canina-blue cursor-pointer flex items-center gap-2"
|
||||
onClick={() => {
|
||||
onShopNavigate(item.id);
|
||||
setIsMobileMenuOpen(false);
|
||||
}}
|
||||
<Link
|
||||
href={`/shop?category=${item.id}`}
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
className="text-[13px] font-bold text-medical-gray-800 font-vazir hover:text-canina-blue cursor-pointer flex items-center gap-2 block"
|
||||
>
|
||||
<span className="text-canina-blue/80">{item.icon}</span>
|
||||
<span>{item.title}</span>
|
||||
</div>
|
||||
</Link>
|
||||
<ul className="mt-1 space-y-1 mr-6">
|
||||
{item.solutions.map((sol, sIdx) => (
|
||||
<li
|
||||
key={sIdx}
|
||||
className="text-[11px] text-medical-gray-500 hover:text-canina-blue cursor-pointer py-1 font-vazir"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onShopNavigate(item.id, sol);
|
||||
setIsMobileMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
{sol}
|
||||
<li key={sIdx}>
|
||||
<Link
|
||||
href={`/shop?category=${item.id}&search=${sol}`}
|
||||
className="text-[11px] text-medical-gray-500 hover:text-canina-blue cursor-pointer py-1 font-vazir block"
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
>
|
||||
{sol}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -471,24 +461,22 @@ export default function Header({
|
||||
</div>
|
||||
|
||||
{[
|
||||
{ id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), action: () => onShopNavigate() },
|
||||
{ id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), action: () => onNavigate('wiki') },
|
||||
{ id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), action: () => onNavigate('blog') },
|
||||
{ id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پتها'), action: () => onNavigate({ view: 'profile', subview: 'index' }) }
|
||||
{ id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), href: '/shop' },
|
||||
{ id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), href: '/wiki' },
|
||||
{ id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), href: '/blog' },
|
||||
{ id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پتها'), href: '/profile' }
|
||||
].map((item) => (
|
||||
<button
|
||||
<Link
|
||||
key={item.id}
|
||||
onClick={() => {
|
||||
item.action();
|
||||
setIsMobileMenuOpen(false);
|
||||
}}
|
||||
className={`w-full text-right px-4 py-3 rounded-xl text-sm font-black transition-all font-vazir ${currentView === item.id
|
||||
href={item.href}
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
className={`w-full block text-right px-4 py-3 rounded-xl text-sm font-black transition-all font-vazir ${currentView === item.id
|
||||
? 'bg-canina-blue/5 text-canina-blue'
|
||||
: 'text-medical-gray-600 hover:bg-medical-gray-50'
|
||||
}`}
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
</motion.div>
|
||||
|
||||
Reference in new issue
Block a user