From 0cb119629c27436ab5d8f370596ec1a3408222ea Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 26 Jul 2026 14:40:33 +0330 Subject: [PATCH] badge and show ai button --- src/app/[name]/(Main)/about/types/Types.ts | 1 + src/app/[name]/(Main)/ai/AiPage.tsx | 2 +- src/components/listview/MenuItem.tsx | 76 +++++----------------- src/components/menu/SideMenu.tsx | 7 +- src/components/menu/SideMenuItem.tsx | 45 +++++++------ src/locales/fa/common.json | 1 + 6 files changed, 49 insertions(+), 83 deletions(-) diff --git a/src/app/[name]/(Main)/about/types/Types.ts b/src/app/[name]/(Main)/about/types/Types.ts index 7382c87..9539c4f 100644 --- a/src/app/[name]/(Main)/about/types/Types.ts +++ b/src/app/[name]/(Main)/about/types/Types.ts @@ -46,6 +46,7 @@ export interface Restaurant { domain: string; score: Score; plan: "base" | "premium"; + enableAiChat?: boolean; bgType?: "pattern" | "custom" | "color"; bgBlur?: number; bgOpacity?: number; diff --git a/src/app/[name]/(Main)/ai/AiPage.tsx b/src/app/[name]/(Main)/ai/AiPage.tsx index 92dcad8..9cd2df8 100644 --- a/src/app/[name]/(Main)/ai/AiPage.tsx +++ b/src/app/[name]/(Main)/ai/AiPage.tsx @@ -161,7 +161,7 @@ function AiPage() { key={labelKey} type="button" disabled={isPending} - onClick={() => setInput(t(labelKey))} + onClick={() => sendMessage(t(labelKey))} className={glassSurfaceFlat("inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 transition-[filter] active:brightness-95 disabled:opacity-50")} > diff --git a/src/components/listview/MenuItem.tsx b/src/components/listview/MenuItem.tsx index 240b78d..fb7c200 100644 --- a/src/components/listview/MenuItem.tsx +++ b/src/components/listview/MenuItem.tsx @@ -51,9 +51,7 @@ const MenuItem = ({ food }: MenuItemProps) => { if (!content) return ""; if (Array.isArray(content)) { - return content - .filter((item) => item && typeof item === "string") - .join("، "); + return content.filter((item) => item && typeof item === "string").join("، "); } return ""; @@ -74,15 +72,9 @@ const MenuItem = ({ food }: MenuItemProps) => { return basePrice; }, [food.price, food.discount]); - const formattedPrice = useMemo( - () => (finalPrice ? finalPrice.toLocaleString("fa-IR") : "0"), - [finalPrice], - ); + const formattedPrice = useMemo(() => (finalPrice ? finalPrice.toLocaleString("fa-IR") : "0"), [finalPrice]); - const formattedOriginalPrice = useMemo( - () => (food.price ? food.price.toLocaleString("fa-IR") : "0"), - [food.price], - ); + const formattedOriginalPrice = useMemo(() => (food.price ? food.price.toLocaleString("fa-IR") : "0"), [food.price]); const hasDiscount = useMemo(() => (food.discount || 0) > 0, [food.discount]); @@ -102,63 +94,34 @@ const MenuItem = ({ food }: MenuItemProps) => { return (
- {foodName} setImageSrc(fallbackImage)} - /> + {foodName} setImageSrc(fallbackImage)} />
-
- {foodName} -
- {(foodContent || foodDescription) && ( -
- {foodContent || foodDescription} -
- )} +
{foodName}
+ {(foodContent || foodDescription) &&
{foodContent || foodDescription}
}
-
+
{hasDiscount ? ( <> - - {formattedOriginalPrice} T - - - {formattedPrice} T - + {formattedOriginalPrice} T + {formattedPrice} T ) : ( - - {formattedPrice} T - + {formattedPrice} T )}
{quantity <= 0 ? ( - ) : ( <> @@ -169,19 +132,10 @@ const MenuItem = ({ food }: MenuItemProps) => { > - + {quantity} - diff --git a/src/components/menu/SideMenu.tsx b/src/components/menu/SideMenu.tsx index 75e5eca..21df320 100644 --- a/src/components/menu/SideMenu.tsx +++ b/src/components/menu/SideMenu.tsx @@ -44,6 +44,7 @@ type MenuItemType = { href: string | undefined; title: string; icon: Icon; + badge?: string; auth?: boolean; guestOnly?: boolean; premiumOnly?: boolean; @@ -57,7 +58,7 @@ const menuItems: Array> = [ { href: "order/history", title: "Orders", icon: CalendarSearch, premiumOnly: true }, { href: "transactions", title: "Transactions", icon: Receipt1, premiumOnly: true }, { href: "game", title: "Games", icon: Game }, - { href: "ai", title: "AI", icon: MessageProgramming }, + { href: "ai", title: "AI", icon: MessageProgramming, badge: "AIBadge" }, { href: "?share", title: "ShareWithFriends", icon: Like1 }, { href: "report", title: "ReportProblem", icon: NoteBoardIcon }, { href: "?installpwa", title: "InstallApp", icon: DirectboxReceive }, @@ -251,17 +252,19 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS if (item.guestOnly && isSuccess) return false; if (item.href === "?installpwa" && isPWAInstalled) return false; if (item.premiumOnly && !isPremium) return false; + if (item.href === "ai" && !aboutData?.data?.enableAiChat) return false; return true; }) .map(({ icon: Icon, ...item }, index) => { const href = `/${name}/${item.href}`; const isActive = pathname === href; return ( -
  • +
  • i.href === item.href)?.handler : undefined} icon={ + icon: React.ReactElement; + title: string; + badge?: string; +} & LinkProps & + React.AnchorHTMLAttributes; -export default function SideMenuItem({ href, title, icon, className, children, ...restProps }: Props) { - return ( - - {children} - {icon} - {title} - - ) -} \ No newline at end of file + > + {children} + {icon} + + {badge && ( + {badge} + )} + {title} + + + ); +} diff --git a/src/locales/fa/common.json b/src/locales/fa/common.json index f479793..3ba00d2 100644 --- a/src/locales/fa/common.json +++ b/src/locales/fa/common.json @@ -16,6 +16,7 @@ "Transactions": "لیست تراکنش ها", "Games": "بازی و سرگرمی ها", "AI": "چی بخورم؟", + "AIBadge": "هوش مصنوعی", "ShareWithFriends": "معرفی به دوستان", "ReportProblem": "گزارش اشکال", "InstallApp": "نصب اپلیکیشن",