From 468170349d3ca6e21b09bdcbccd78dbf31650f88 Mon Sep 17 00:00:00 2001 From: devops Date: Sun, 18 Oct 2026 12:51:04 +0000 Subject: [PATCH] feat(ux-fix): resolve wiki fallback 404, responsive B2B modal, clean badges, aligned bullets, mobile bottom nav on PDP and admin Rx/symptoms management --- backend/src/admin/admin.controller.ts | 15 +++++ backend/src/admin/admin.service.ts | 61 +++++++++++++++++++ frontend/admin-panel/src/pages/Orders.tsx | 25 ++++++++ frontend/application/app/wiki/[slug]/page.tsx | 31 ++++++++-- .../application/components/ArchivePage.tsx | 19 +++--- frontend/application/components/B2BPortal.tsx | 9 +-- .../components/MobileBottomNav.tsx | 6 +- .../application/components/ProductPage.tsx | 56 ++++++++--------- 8 files changed, 168 insertions(+), 54 deletions(-) diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts index d8687ba3..7557326a 100644 --- a/backend/src/admin/admin.controller.ts +++ b/backend/src/admin/admin.controller.ts @@ -354,4 +354,19 @@ export class AdminController { await this.settingsService.updateBulkUiTexts(body); return { success: true, data: body }; } + + @Get("symptoms") + @ApiOperation({ summary: "لیست کامل علائم درمانی به همراه تعداد محصولات متصل" }) + async getAllSymptoms() { + const data = await this.adminService.getAllSymptoms(); + return { success: true, data }; + } + + @Put("symptoms/rename") + @ApiOperation({ summary: "تغییر نام یکپارچه یک علامت در سراسر محصولات و دیتابیس" }) + async renameSymptom(@Body() body: { oldName: string; newName: string }) { + const result = await this.adminService.renameSymptom(body.oldName, body.newName); + return { success: true, ...result }; + } + } diff --git a/backend/src/admin/admin.service.ts b/backend/src/admin/admin.service.ts index 706629b1..ed2af0ae 100644 --- a/backend/src/admin/admin.service.ts +++ b/backend/src/admin/admin.service.ts @@ -1869,4 +1869,65 @@ export class AdminService { }; }); } + + async getAllSymptoms() { + const rawSymptoms = await this.prisma.productSymptom.groupBy({ + by: ['symptom'], + _count: { + productId: true, + }, + orderBy: { + symptom: 'asc', + }, + }); + + return rawSymptoms.map((s) => ({ + name: s.symptom, + productsCount: s._count.productId, + })); + } + + async renameSymptom(oldName: string, newName: string) { + if (!oldName?.trim() || !newName?.trim()) { + throw new BadRequestException('نام قبلی و جدید علامت الزامی است'); + } + const cleanOld = oldName.trim(); + const cleanNew = newName.trim(); + + return await this.prisma.(async (tx) => { + // 1. Rename in product_symptoms join table + const updatedJoin = await tx.` + UPDATE product_symptoms + SET symptom = ${cleanNew} + WHERE symptom = ${cleanOld}; + `; + + // 2. Cascade rename in products.dosage_config->'symptoms' jsonb array + await tx.` + UPDATE products + SET dosage_config = jsonb_set( + dosage_config, + '{symptoms}', + ( + SELECT jsonb_agg( + CASE + WHEN elem::text = to_jsonb(${cleanOld}::text)::text THEN to_jsonb(${cleanNew}::text) + ELSE elem + END + ) + FROM jsonb_array_elements(dosage_config->'symptoms') AS elem + ) + ) + WHERE dosage_config ? 'symptoms' + AND dosage_config->'symptoms' @> to_jsonb(${cleanOld}::text); + `; + + return { + success: true, + message: \`علامت «${cleanOld}» با موفقیت به «${cleanNew}» در سراسر سیستم تغییر یافت\`, + updatedCount: updatedJoin, + }; + }); + } + } diff --git a/frontend/admin-panel/src/pages/Orders.tsx b/frontend/admin-panel/src/pages/Orders.tsx index 0cd0189f..c2e322e7 100644 --- a/frontend/admin-panel/src/pages/Orders.tsx +++ b/frontend/admin-panel/src/pages/Orders.tsx @@ -31,6 +31,7 @@ import api from '../services/api'; export interface OrderItem { + requiresRx?: boolean; id?: string; name?: string; priceValue?: number; @@ -758,6 +759,12 @@ export default function Orders() { سفارش جدید )} + {(order.orderItems || order.items || []).some(it => it.product?.requiresRx) && ( + + Rx + هماهنگی نسخه + + )}
@@ -911,6 +918,24 @@ export default function Orders() { >
+ {/* Rx Warning Notice for Admin */} + {(selectedOrder.orderItems || selectedOrder.items || []).some(it => it.requiresRx || it.product?.requiresRx) && ( +
+
+ Rx +
+

این سفارش شامل داروی نیازمند نسخه و نظارت دامپزشکی است

+

ارسال سفارش تنها پس از تماس تلفنی کارشناس پشتیبانی و تایید نسخه معتبر انجام شود.

+
+
+ + تماس با مشتری + +
+ )} {/* Status & Timing Banner */}
diff --git a/frontend/application/app/wiki/[slug]/page.tsx b/frontend/application/app/wiki/[slug]/page.tsx index a2d5c530..64b259be 100644 --- a/frontend/application/app/wiki/[slug]/page.tsx +++ b/frontend/application/app/wiki/[slug]/page.tsx @@ -12,15 +12,38 @@ const apiBase = API_URL.endsWith('/api') ? API_URL : `${API_URL.replace(/\/$/, ' async function getWikiTerm(key: string) { try { + // 1. Try scientific terms endpoint const res = await fetch(`${apiBase}/wiki/${encodeURIComponent(key)}`, { next: { revalidate: 3600, tags: ['wiki', `wiki-${key}`] } }); - if (!res.ok) return null; - return await res.json(); + if (res.ok) { + return await res.json(); + } } catch (error) { - console.error('[Wiki] Error fetching term:', error); - return null; + console.warn('[Wiki] /wiki/:key failed, trying /ingredients fallback:', error); } + + try { + // 2. Fallback to ingredients endpoint if slug is an ingredient slug + const ingRes = await fetch(`${apiBase}/ingredients/${encodeURIComponent(key)}`, { + next: { revalidate: 3600, tags: ['ingredients', `ing-${key}`] } + }); + if (ingRes.ok) { + const ing = await ingRes.json(); + return { + key: ing.slug, + term: ing.nameFa || ing.nameEn || ing.slug, + definition: ing.description || `بررسی تخصصی ترکیب دارویی و خواص ${ing.nameFa || ing.nameEn} در کاتالوگ مکمل‌های کنینا آلمان.`, + metaTitle: `خواص دارویی ${ing.nameFa || ing.nameEn} | دانشنامه کنینا ایران`, + metaDescription: (ing.description || '').slice(0, 155), + wikiId: ing.slug, + }; + } + } catch (error) { + console.error('[Wiki] Error fetching ingredient fallback:', error); + } + + return null; } async function getRelatedProducts(termName: string) { diff --git a/frontend/application/components/ArchivePage.tsx b/frontend/application/components/ArchivePage.tsx index 04e11913..2bd51ded 100644 --- a/frontend/application/components/ArchivePage.tsx +++ b/frontend/application/components/ArchivePage.tsx @@ -129,11 +129,7 @@ export const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) href={productUrl} className="group bg-white rounded-[2.5rem] border border-medical-gray-200 overflow-hidden hover:shadow-2xl transition-all flex flex-col h-full relative" > - {product.specialBadge && ( -
- {product.specialBadge} -
- )} + {/* SpecialBadge moved below image to avoid covering product photo */} {compatibility && (
= ({ product })
+ {product.specialBadge && ( +
+ + {product.specialBadge} + +
+ )}
{product.category}

@@ -325,11 +328,7 @@ const ArchiveProductListItem: React.FC<{ product: Product }> = ({ product }) => className="w-full h-full group-hover:scale-105 transition-transform duration-500" imgClassName="w-full h-full object-contain" /> - {product.specialBadge && ( -
- {product.specialBadge} -
- )} + {/* List specialBadge moved below */}
{forDog && (
diff --git a/frontend/application/components/B2BPortal.tsx b/frontend/application/components/B2BPortal.tsx index 59dd5a00..6ed8ad71 100644 --- a/frontend/application/components/B2BPortal.tsx +++ b/frontend/application/components/B2BPortal.tsx @@ -89,23 +89,24 @@ export default function B2BPortal({ onClose }: { onClose: () => void }) { initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} - className="fixed inset-0 z-[100] bg-medical-gray-900/60 backdrop-blur-md flex items-center justify-center p-4 md:p-10 font-vazir" + className="fixed inset-0 z-[100] bg-medical-gray-900/70 backdrop-blur-md flex items-center justify-center p-2 sm:p-4 md:p-8 font-vazir" dir="rtl" > {/* Sidebar Info */} -
+
diff --git a/frontend/application/components/MobileBottomNav.tsx b/frontend/application/components/MobileBottomNav.tsx index 9c5014b4..38a0b9b2 100644 --- a/frontend/application/components/MobileBottomNav.tsx +++ b/frontend/application/components/MobileBottomNav.tsx @@ -183,10 +183,8 @@ export default function MobileBottomNav({ } }; - const isProductDetailPage = pathname.startsWith("/shop/") && pathname !== "/shop"; - if (isProductDetailPage) { - return null; - } + // Retain MobileBottomNav across all routes including PDP so user never loses Menu & Home navigation + const isProductDetailPage = false; const totalCartItems = isMounted ? getTotalItems() : 0; const isHomeActive = pathname === "/"; diff --git a/frontend/application/components/ProductPage.tsx b/frontend/application/components/ProductPage.tsx index 31fd0e85..8b0b3781 100644 --- a/frontend/application/components/ProductPage.tsx +++ b/frontend/application/components/ProductPage.tsx @@ -498,27 +498,7 @@ export default function ProductPage({ }} className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[280px] sm:h-[390px] flex items-center justify-center p-2 sm:p-4 select-none touch-pan-y cursor-grab active:cursor-grabbing" > - {/* Top Floating Badges */} -
- {product.specialBadge && ( -
- {product.specialBadge} -
- )} - {isOutOfStock ? ( -
- ناموجود در انبار -
- ) : ( -
- - موجود در انبار -
- )} -
- گرید دارویی اختصاصی -
-
+ {/* Floating Badges over photo removed to prevent blocking product visual */} {/* Species Suitable Badges (Dog / Cat) */}
@@ -695,15 +675,27 @@ export default function ProductPage({
-
- استاندارد صنعتی آلمان -
-
- - کاتالوگ رسمی Canina + {/* 1. First Priority: Stock Status */} + {isOutOfStock ? ( +
+ + ناموجود در انبار مرکزی +
+ ) : ( +
+ + موجود در انبار مرکزی +
+ )} + + {/* 2. Pharmaceutical Grade */} +
+ گرید دارویی اختصاصی Canina
+ + {/* 3. Special Badge if exists */} {product.specialBadge && ( -
+
{product.specialBadge}
)} @@ -745,9 +737,9 @@ export default function ProductPage({

)} {product.scientificTagline && ( -
- - {product.scientificTagline} +
+ + {product.scientificTagline}
)}
@@ -1060,7 +1052,7 @@ export default function ProductPage({ {cardSlug ? (