feat: implement dynamic category solutions in MegaMenu navigation and convert static footer buttons to Next.js links

This commit is contained in:
parsa aghaei committed 2026-07-15 13:53:23 +03:30
1 parent 0ccf37f922
commit 1d9b699d61
5 files changed
+107 -33

No files matched your search

@@ -77,6 +77,25 @@ export class ProductsController {
return this.productsService.getActiveFilters();
}
@Get('navigation-filters')
@ApiOperation({ summary: 'دریافت فیلترها و راهکارهای ناوبری (دسته با علائم مربوطه)' })
@ApiOkResponse({
description: 'ساختار درختی فیلترها و تگ‌های درمانی واقعی متصل به محصولات',
schema: {
example: [
{
id: '1',
name: 'مفاصل و استخوان',
slug: 'joints',
symptoms: ['درد مفاصل', 'لنگش']
}
]
}
})
getNavigationFilters() {
return this.productsService.getNavigationFilters();
}
@Get(':id')
@ApiOperation({ summary: 'دریافت اطلاعات محصول با شناسه یکتا (ID)' })
@ApiOkResponse({
+35
View File
@@ -98,4 +98,39 @@ export class ProductsService {
petTypes: petTypesDb.map(p => p.suitableFor).filter(Boolean),
};
}
async getNavigationFilters() {
const categories = await this.prisma.category.findMany({
where: {
products: {
some: {}
}
},
include: {
products: {
include: {
symptoms: true
}
}
}
});
return categories.map(cat => {
const symptomSet = new Set<string>();
cat.products.forEach(p => {
p.symptoms.forEach(s => {
if (s.symptom) {
symptomSet.add(s.symptom);
}
});
});
return {
id: cat.id,
name: cat.name,
slug: cat.slug,
symptoms: Array.from(symptomSet)
};
});
}
}
+3 -3
View File
@@ -126,9 +126,9 @@ export default function Footer({ onNavigate, onShopNavigate, onB2BOpen }: {
<div className="pt-12 border-t border-white/5 flex flex-col md:flex-row items-center justify-between gap-6 text-[10px] font-bold uppercase tracking-[0.3em] font-shabnam">
<div className="text-slate-400 font-shabnam">{getText('footer_copyright', "© ۲۰۲۶ کانینا ایران. تمامی حقوق محفوظ است.")}</div>
<div className="flex gap-8 font-shabnam text-slate-400">
<button onClick={() => onNavigate("about")} className="font-extrabold hover:text-white transition-colors">{getText('footer_about', "درباره ما")}</button>
<button onClick={() => onNavigate("contact")} className="font-extrabold hover:text-white transition-colors">{getText('footer_contact', "تماس با ما")}</button>
<button onClick={() => onNavigate("privacy")} className="font-extrabold hover:text-white transition-colors">{getText('footer_privacy', "حریم خصوصی")}</button>
<Link href="/about" className="font-extrabold hover:text-white transition-colors">{getText('footer_about', "درباره ما")}</Link>
<Link href="/contact" className="font-extrabold hover:text-white transition-colors">{getText('footer_contact', "تماس با ما")}</Link>
<Link href="/privacy" className="font-extrabold hover:text-white transition-colors">{getText('footer_privacy', "حریم خصوصی")}</Link>
</div>
</div>
</div>
+35 -30
View File
@@ -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)}
>
@@ -168,6 +168,21 @@ export class ProductService {
return { categories: [], symptoms: [], petTypes: [] };
}
}
public async getNavigationFilters(): Promise<{
id: string;
name: string;
slug: string;
symptoms: string[];
}[]> {
try {
const response = await api.get('/products/navigation-filters');
return response.data;
} catch (error) {
console.error("[ProductService] Failed to fetch navigation filters:", error);
return [];
}
}
}
export const productService = ProductService.getInstance();