feat: implement dynamic category solutions in MegaMenu navigation and convert static footer buttons to Next.js links
This commit is contained in:
1 parent
0ccf37f922
commit
1d9b699d61
5 files changed
+107
-33
No files matched your search
@@ -11,33 +11,14 @@ import { toast } from "sonner";
|
||||
import HeaderButton from "./HeaderButton";
|
||||
import AuthModal from "./AuthModal";
|
||||
import { cn } from "../lib/utils";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
const MENU_ITEMS = [
|
||||
{
|
||||
id: "joints",
|
||||
title: "مفاصل و استخوان",
|
||||
icon: <Pill className="w-5 h-5" />,
|
||||
solutions: ["آرتروز سگهای پیر", "رشد استخوانی تولهسگ", "تقویت رباط و تاندون"]
|
||||
},
|
||||
{
|
||||
id: "immune",
|
||||
title: "تقویت سیستم ایمنی و گوارش",
|
||||
icon: <ShieldCheck className="w-5 h-5" />,
|
||||
solutions: ["پیشگیری از بیماری", "رفع اسهال و یبوست", "پروبیوتیکها"]
|
||||
},
|
||||
{
|
||||
id: "energy",
|
||||
title: "ویتامینها و انرژیبخشها",
|
||||
icon: <HeartPulse className="w-5 h-5" />,
|
||||
solutions: ["مکملهای مولتیویتامین", "افزایش اشتها", "رشد و بلوغ"]
|
||||
},
|
||||
{
|
||||
id: "special-care",
|
||||
title: "مراقبتهای ویژه (پوست، دندان و چشم)",
|
||||
icon: <Sparkles className="w-5 h-5" />,
|
||||
solutions: ["سلامت پوست و مفاصل", "رفع جرم دندان", "شستشوی چشم"]
|
||||
}
|
||||
];
|
||||
const MENU_ICONS: Record<string, React.ReactNode> = {
|
||||
joints: <Pill className="w-5 h-5" />,
|
||||
immune: <ShieldCheck className="w-5 h-5" />,
|
||||
energy: <HeartPulse className="w-5 h-5" />,
|
||||
"special-care": <Sparkles className="w-5 h-5" />,
|
||||
};
|
||||
|
||||
export default function Header({
|
||||
onNavigate,
|
||||
@@ -61,6 +42,12 @@ export default function Header({
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
const [isMobileSolutionsOpen, setIsMobileSolutionsOpen] = useState(false);
|
||||
const [menuItems, setMenuItems] = useState<{
|
||||
id: string;
|
||||
title: string;
|
||||
icon: React.ReactNode;
|
||||
solutions: string[];
|
||||
}[]>([]);
|
||||
|
||||
const petMenuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
@@ -70,6 +57,24 @@ export default function Header({
|
||||
const activePet = getActivePet();
|
||||
const getText = useSettingsStore(state => state.getText);
|
||||
|
||||
useEffect(() => {
|
||||
const loadNavFilters = async () => {
|
||||
try {
|
||||
const data = await productService.getNavigationFilters();
|
||||
const mapped = data.map(item => ({
|
||||
id: item.slug,
|
||||
title: item.name,
|
||||
icon: MENU_ICONS[item.slug] || <Pill className="w-5 h-5" />,
|
||||
solutions: item.symptoms
|
||||
}));
|
||||
setMenuItems(mapped);
|
||||
} catch (e) {
|
||||
console.error("Failed to load navigation filters:", e);
|
||||
}
|
||||
};
|
||||
loadNavFilters();
|
||||
}, []);
|
||||
|
||||
// Click Outside logic
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
@@ -151,7 +156,7 @@ export default function Header({
|
||||
exit={{ opacity: 0, y: 15, scale: 0.98 }}
|
||||
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) => (
|
||||
{menuItems.map((item, idx) => (
|
||||
<div key={idx} className="group/item">
|
||||
<Link
|
||||
href={`/shop?category=${item.id}`}
|
||||
@@ -167,7 +172,7 @@ export default function Header({
|
||||
{item.solutions.map((sol, sIdx) => (
|
||||
<li key={sIdx}>
|
||||
<Link
|
||||
href={`/shop?category=${item.id}&search=${sol}`}
|
||||
href={`/shop?category=${item.id}&symptoms=${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)}
|
||||
>
|
||||
@@ -449,7 +454,7 @@ export default function Header({
|
||||
exit={{ height: 0, opacity: 0 }}
|
||||
className="overflow-hidden mr-4 pr-2 border-r-2 border-medical-gray-100 mt-1 space-y-3"
|
||||
>
|
||||
{MENU_ITEMS.map((item, idx) => (
|
||||
{menuItems.map((item, idx) => (
|
||||
<div key={idx} className="py-1">
|
||||
<Link
|
||||
href={`/shop?category=${item.id}`}
|
||||
@@ -463,7 +468,7 @@ export default function Header({
|
||||
{item.solutions.map((sol, sIdx) => (
|
||||
<li key={sIdx}>
|
||||
<Link
|
||||
href={`/shop?category=${item.id}&search=${sol}`}
|
||||
href={`/shop?category=${item.id}&symptoms=${sol}`}
|
||||
className="text-[11px] text-medical-gray-500 hover:text-canina-blue cursor-pointer py-1 font-vazir block"
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user