fix: replace desktop and mobile onClick navigation handlers with standard next/link components in Header.tsx

This commit is contained in:
parsa aghaei committed 2026-07-15 13:30:27 +03:30
1 parent 565ef70840
commit 7d93a8d7c2
1 file changed
+52 -64
+52 -64
View File
@@ -2,6 +2,7 @@
import React, { useState, useRef, useEffect } from "react"; 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 { 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 { motion, AnimatePresence } from "motion/react";
import Link from "next/link";
import { useCartStore } from "../lib/store/cartStore"; import { useCartStore } from "../lib/store/cartStore";
import { usePetStore } from "../lib/store/usePetStore"; import { usePetStore } from "../lib/store/usePetStore";
import { useUserStore } from "../lib/store/userStore"; import { useUserStore } from "../lib/store/userStore";
@@ -110,19 +111,17 @@ export default function Header({
</button> </button>
{/* Logo Section */} {/* Logo Section */}
<div <Link
href="/"
className="flex-shrink-0 flex items-center gap-3 cursor-pointer group" className="flex-shrink-0 flex items-center gap-3 cursor-pointer group"
onClick={() => { onClick={() => setIsMobileMenuOpen(false)}
onNavigate("home");
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="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"> <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-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> <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>
</div> </Link>
</div> </div>
{/* Navigation Items */} {/* 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" 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) => ( {MENU_ITEMS.map((item, idx) => (
<div <div key={idx} className="group/item">
key={idx} <Link
className="group/item cursor-pointer" href={`/shop?category=${item.id}`}
onClick={() => { onClick={() => setIsMegaMenuOpen(false)}
onShopNavigate(item.id); className="flex items-center gap-4 mb-4 cursor-pointer block"
setIsMegaMenuOpen(false); >
}}
>
<div className="flex items-center gap-4 mb-4">
<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"> <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} {item.icon}
</div> </div>
<h4 className="font-black text-medical-gray-900 text-sm font-vazir whitespace-nowrap">{item.title}</h4> <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"> <ul className="space-y-2.5 border-r-2 border-medical-gray-50 pr-4">
{item.solutions.map((sol, sIdx) => ( {item.solutions.map((sol, sIdx) => (
<li <li key={sIdx}>
key={sIdx} <Link
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" href={`/shop?category=${item.id}&search=${sol}`}
onClick={(e) => { 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"
e.stopPropagation(); onClick={() => setIsMegaMenuOpen(false)}
onShopNavigate(item.id, sol); >
setIsMegaMenuOpen(false); {sol}
}} </Link>
>
{sol}
</li> </li>
))} ))}
</ul> </ul>
@@ -183,18 +177,18 @@ export default function Header({
</div> </div>
{[ {[
{ id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), action: () => onShopNavigate() }, { id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), href: '/shop' },
{ id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), action: () => onNavigate('wiki') }, { id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), href: '/wiki' },
{ id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), action: () => onNavigate('blog') }, { id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), href: '/blog' },
{ id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پتها'), action: () => onNavigate({ view: 'profile', subview: 'index' }) } { id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پت‌ها'), href: '/profile' }
].map((item) => ( ].map((item) => (
<button <Link
key={item.id} key={item.id}
onClick={item.action} 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] ${currentView === item.id ? 'bg-canina-blue/5 text-canina-blue' : 'text-medical-gray-600 hover:bg-medical-gray-50 hover:text-canina-blue'}`} 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} {item.label}
</button> </Link>
))} ))}
</nav> </nav>
@@ -405,10 +399,10 @@ export default function Header({
dir="rtl" dir="rtl"
> >
<div className="flex items-center justify-between border-b border-medical-gray-100 pb-4"> <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> <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> <span className="text-canina-blue font-black text-xl italic font-sans">Canina</span>
</div> </Link>
<button <button
onClick={() => setIsMobileMenuOpen(false)} onClick={() => setIsMobileMenuOpen(false)}
className="p-2 rounded-xl hover:bg-medical-gray-50 text-medical-gray-600 transition-all" 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) => ( {MENU_ITEMS.map((item, idx) => (
<div key={idx} className="py-1"> <div key={idx} className="py-1">
<div <Link
className="text-[13px] font-bold text-medical-gray-800 font-vazir hover:text-canina-blue cursor-pointer flex items-center gap-2" href={`/shop?category=${item.id}`}
onClick={() => { onClick={() => setIsMobileMenuOpen(false)}
onShopNavigate(item.id); className="text-[13px] font-bold text-medical-gray-800 font-vazir hover:text-canina-blue cursor-pointer flex items-center gap-2 block"
setIsMobileMenuOpen(false);
}}
> >
<span className="text-canina-blue/80">{item.icon}</span> <span className="text-canina-blue/80">{item.icon}</span>
<span>{item.title}</span> <span>{item.title}</span>
</div> </Link>
<ul className="mt-1 space-y-1 mr-6"> <ul className="mt-1 space-y-1 mr-6">
{item.solutions.map((sol, sIdx) => ( {item.solutions.map((sol, sIdx) => (
<li <li key={sIdx}>
key={sIdx} <Link
className="text-[11px] text-medical-gray-500 hover:text-canina-blue cursor-pointer py-1 font-vazir" href={`/shop?category=${item.id}&search=${sol}`}
onClick={(e) => { className="text-[11px] text-medical-gray-500 hover:text-canina-blue cursor-pointer py-1 font-vazir block"
e.stopPropagation(); onClick={() => setIsMobileMenuOpen(false)}
onShopNavigate(item.id, sol); >
setIsMobileMenuOpen(false); {sol}
}} </Link>
>
{sol}
</li> </li>
))} ))}
</ul> </ul>
@@ -471,24 +461,22 @@ export default function Header({
</div> </div>
{[ {[
{ id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), action: () => onShopNavigate() }, { id: 'shop', label: getText('nav_products', 'محصولات تخصصی'), href: '/shop' },
{ id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), action: () => onNavigate('wiki') }, { id: 'wiki', label: getText('nav_wiki', 'دانشنامه علمی'), href: '/wiki' },
{ id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), action: () => onNavigate('blog') }, { id: 'blog', label: getText('nav_blog', 'مجله سلامت پت'), href: '/blog' },
{ id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پتها'), action: () => onNavigate({ view: 'profile', subview: 'index' }) } { id: 'profile', label: getText('nav_pet_profiles', 'شناسنامه پت‌ها'), href: '/profile' }
].map((item) => ( ].map((item) => (
<button <Link
key={item.id} key={item.id}
onClick={() => { href={item.href}
item.action(); onClick={() => setIsMobileMenuOpen(false)}
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
}}
className={`w-full 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' ? 'bg-canina-blue/5 text-canina-blue'
: 'text-medical-gray-600 hover:bg-medical-gray-50' : 'text-medical-gray-600 hover:bg-medical-gray-50'
}`} }`}
> >
{item.label} {item.label}
</button> </Link>
))} ))}
</nav> </nav>
</motion.div> </motion.div>