From 1d9b699d619cb9936fc97f1995952262b94290bb Mon Sep 17 00:00:00 2001 From: parsa aghaei Date: Wed, 15 Jul 2026 13:53:23 +0330 Subject: [PATCH] feat: implement dynamic category solutions in MegaMenu navigation and convert static footer buttons to Next.js links --- backend/src/products/products.controller.ts | 19 ++++++ backend/src/products/products.service.ts | 35 ++++++++++ frontend/application/components/Footer.tsx | 6 +- frontend/application/components/Header.tsx | 65 ++++++++++--------- .../lib/services/productService.ts | 15 +++++ 5 files changed, 107 insertions(+), 33 deletions(-) diff --git a/backend/src/products/products.controller.ts b/backend/src/products/products.controller.ts index 8d9eac02..cdc503f6 100644 --- a/backend/src/products/products.controller.ts +++ b/backend/src/products/products.controller.ts @@ -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({ diff --git a/backend/src/products/products.service.ts b/backend/src/products/products.service.ts index 41c9dd9b..3f92ba5c 100644 --- a/backend/src/products/products.service.ts +++ b/backend/src/products/products.service.ts @@ -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(); + 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) + }; + }); + } } diff --git a/frontend/application/components/Footer.tsx b/frontend/application/components/Footer.tsx index 846c81f1..31878ba0 100644 --- a/frontend/application/components/Footer.tsx +++ b/frontend/application/components/Footer.tsx @@ -126,9 +126,9 @@ export default function Footer({ onNavigate, onShopNavigate, onB2BOpen }: {
{getText('footer_copyright', "© ۲۰۲۶ کانینا ایران. تمامی حقوق محفوظ است.")}
- - - + {getText('footer_about', "درباره ما")} + {getText('footer_contact', "تماس با ما")} + {getText('footer_privacy', "حریم خصوصی")}
diff --git a/frontend/application/components/Header.tsx b/frontend/application/components/Header.tsx index 2b5d140f..d38bd165 100644 --- a/frontend/application/components/Header.tsx +++ b/frontend/application/components/Header.tsx @@ -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: , - solutions: ["آرتروز سگ‌های پیر", "رشد استخوانی توله‌سگ", "تقویت رباط و تاندون"] - }, - { - id: "immune", - title: "تقویت سیستم ایمنی و گوارش", - icon: , - solutions: ["پیشگیری از بیماری", "رفع اسهال و یبوست", "پروبیوتیک‌ها"] - }, - { - id: "energy", - title: "ویتامین‌ها و انرژی‌بخش‌ها", - icon: , - solutions: ["مکمل‌های مولتی‌ویتامین", "افزایش اشتها", "رشد و بلوغ"] - }, - { - id: "special-care", - title: "مراقبت‌های ویژه (پوست، دندان و چشم)", - icon: , - solutions: ["سلامت پوست و مفاصل", "رفع جرم دندان", "شستشوی چشم"] - } -]; +const MENU_ICONS: Record = { + joints: , + immune: , + energy: , + "special-care": , +}; 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(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] || , + 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) => (
(
  • 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) => (
    (
  • setIsMobileMenuOpen(false)} > diff --git a/frontend/application/lib/services/productService.ts b/frontend/application/lib/services/productService.ts index 8a1bd613..78d1fa90 100644 --- a/frontend/application/lib/services/productService.ts +++ b/frontend/application/lib/services/productService.ts @@ -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();