change food item type
This commit is contained in:
@@ -51,7 +51,7 @@ export const useIncrementCart = () => {
|
|||||||
if (food) {
|
if (food) {
|
||||||
const newItem: CartItem = {
|
const newItem: CartItem = {
|
||||||
foodId: String(id),
|
foodId: String(id),
|
||||||
foodTitle: food.title || food.name || "",
|
foodTitle: food.title,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
price: food.price,
|
price: food.price,
|
||||||
discount: food.discount || 0,
|
discount: food.discount || 0,
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import MinusIcon from '@/components/icons/MinusIcon'
|
import { useCart } from "@/app/[name]/(Dialogs)/cart/hook/useCart";
|
||||||
import PlusIcon from '@/components/icons/PlusIcon'
|
import MinusIcon from "@/components/icons/MinusIcon";
|
||||||
import { ef } from '@/lib/helpers/utfNumbers'
|
import PlusIcon from "@/components/icons/PlusIcon";
|
||||||
import { useCart } from '@/app/[name]/(Dialogs)/cart/hook/useCart'
|
import { toast } from "@/components/Toast";
|
||||||
import { motion } from 'framer-motion'
|
import { getToken } from "@/lib/api/func";
|
||||||
import { ArrowLeft, Clock, Cup, Heart, TruckTick } from 'iconsax-react'
|
import { ef } from "@/lib/helpers/utfNumbers";
|
||||||
import Image from 'next/image'
|
import { motion } from "framer-motion";
|
||||||
import { useParams, useRouter } from 'next/navigation'
|
import { ArrowLeft, Clock, Cup, Heart, TruckTick } from "iconsax-react";
|
||||||
import React, { useEffect, useMemo, useState } from 'react'
|
import Image from "next/image";
|
||||||
import { useGetFood, useToggleFavorite } from './hooks/useFoodData'
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useGetAbout } from '../about/hooks/useAboutData'
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useGetProfile } from '../../(Profile)/profile/hooks/userProfileData'
|
import { useGetProfile } from "../../(Profile)/profile/hooks/userProfileData";
|
||||||
import { toast } from '@/components/Toast'
|
import { useGetAbout } from "../about/hooks/useAboutData";
|
||||||
import { getToken } from '@/lib/api/func'
|
import { useGetFood, useToggleFavorite } from "./hooks/useFoodData";
|
||||||
|
|
||||||
type Props = object
|
type Props = object;
|
||||||
|
|
||||||
function FoodPage({ }: Props) {
|
|
||||||
|
|
||||||
|
function FoodPage({}: Props) {
|
||||||
const { id, name } = useParams();
|
const { id, name } = useParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { isSuccess } = useGetProfile();
|
const { isSuccess } = useGetProfile();
|
||||||
@@ -28,10 +27,10 @@ function FoodPage({ }: Props) {
|
|||||||
const [isFavorite, setIsFavorite] = useState<boolean>(false);
|
const [isFavorite, setIsFavorite] = useState<boolean>(false);
|
||||||
const { mutate: toggleFavorite } = useToggleFavorite();
|
const { mutate: toggleFavorite } = useToggleFavorite();
|
||||||
|
|
||||||
const foodId = food?.data?.id || id as string;
|
const foodId = food?.data?.id || (id as string);
|
||||||
const quantity = useMemo(() => {
|
const quantity = useMemo(() => {
|
||||||
const item = items?.[foodId];
|
const item = items?.[foodId];
|
||||||
if (item && typeof item === 'object' && 'quantity' in item) {
|
if (item && typeof item === "object" && "quantity" in item) {
|
||||||
return item.quantity || 0;
|
return item.quantity || 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -54,7 +53,7 @@ function FoodPage({ }: Props) {
|
|||||||
|
|
||||||
const token = await getToken();
|
const token = await getToken();
|
||||||
if (!token || !isSuccess) {
|
if (!token || !isSuccess) {
|
||||||
toast('ابتدا لاگین کنید', 'error');
|
toast("ابتدا لاگین کنید", "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +68,7 @@ function FoodPage({ }: Props) {
|
|||||||
onError: () => {
|
onError: () => {
|
||||||
// بازگرداندن به حالت قبلی در صورت خطا
|
// بازگرداندن به حالت قبلی در صورت خطا
|
||||||
setIsFavorite(previousFavorite);
|
setIsFavorite(previousFavorite);
|
||||||
toast('خطا در تغییر وضعیت علاقهمندی', 'error');
|
toast("خطا در تغییر وضعیت علاقهمندی", "error");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -84,41 +83,44 @@ function FoodPage({ }: Props) {
|
|||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center justify-center min-h-[400px]'>
|
<div className="flex items-center justify-center min-h-[400px]">
|
||||||
<p className='text-disabled-text'>در حال بارگذاری...</p>
|
<p className="text-disabled-text">در حال بارگذاری...</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!food?.data) {
|
if (!food?.data) {
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center justify-center min-h-[400px]'>
|
<div className="flex items-center justify-center min-h-[400px]">
|
||||||
<p className='text-disabled-text'>غذا یافت نشد</p>
|
<p className="text-disabled-text">غذا یافت نشد</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const foodData = food.data;
|
const foodData = food.data;
|
||||||
const foodName = foodData.title || foodData.name || foodData.foodName || '';
|
const foodName = foodData.title || foodData.name || foodData.foodName || "";
|
||||||
const foodImage = typeof foodData.image === 'string'
|
const foodImage =
|
||||||
|
typeof foodData.image === "string"
|
||||||
? foodData.image
|
? foodData.image
|
||||||
: Array.isArray(foodData.images) && foodData.images.length > 0
|
: Array.isArray(foodData.images) && foodData.images.length > 0
|
||||||
? typeof foodData.images[0] === 'string'
|
? typeof foodData.images[0] === "string"
|
||||||
? foodData.images[0]
|
? foodData.images[0]
|
||||||
: typeof foodData.images[0] === 'object' && foodData.images[0] !== null && 'url' in foodData.images[0]
|
: typeof foodData.images[0] === "object" &&
|
||||||
|
foodData.images[0] !== null &&
|
||||||
|
"url" in foodData.images[0]
|
||||||
? (foodData.images[0] as { url: string }).url
|
? (foodData.images[0] as { url: string }).url
|
||||||
: '/assets/images/no-image.png'
|
: "/assets/images/no-image.png"
|
||||||
: '/assets/images/no-image.png';
|
: "/assets/images/no-image.png";
|
||||||
const categoryName = foodData.category?.title;
|
const categoryName = foodData.category?.title;
|
||||||
const prepareTime = foodData.prepareTime || 0;
|
const prepareTime = foodData.prepareTime || 0;
|
||||||
const price = foodData.price || 0;
|
const price = foodData.price || 0;
|
||||||
const content = Array.isArray(foodData.content)
|
const content = Array.isArray(foodData.content)
|
||||||
? foodData.content.join('، ')
|
? foodData.content.join("، ")
|
||||||
: foodData.content || foodData.desc || '';
|
: foodData.content || foodData.desc || "";
|
||||||
|
|
||||||
const handleBackToMenu = () => {
|
const handleBackToMenu = () => {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const categoryParam = urlParams.get('category') || foodData.category?.id;
|
const categoryParam = urlParams.get("category") || foodData.category?.id;
|
||||||
if (categoryParam) {
|
if (categoryParam) {
|
||||||
router.push(`/${name}?category=${categoryParam}`);
|
router.push(`/${name}?category=${categoryParam}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -127,10 +129,10 @@ function FoodPage({ }: Props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='lg:absolute lg:top-1/2 not-lg:max-w-lg not-lg:place-self-center lg:-translate-y-1/2 xl:right-[285px] lg:left-5 lg:right-4 lg:bottom-4 not-lg:w-full not-md:-translate-y-2 pt-6 flex flex-col lg:grid grid-cols-2 bottom-10'>
|
<div className="lg:absolute lg:top-1/2 not-lg:max-w-lg not-lg:place-self-center lg:-translate-y-1/2 xl:right-[285px] lg:left-5 lg:right-4 lg:bottom-4 not-lg:w-full not-md:-translate-y-2 pt-6 flex flex-col lg:grid grid-cols-2 bottom-10">
|
||||||
<div className="relative w-full h-full not-lg:bg-container rounded-2xl overflow-hidden lg:rounded-r-none lg:order-1">
|
<div className="relative w-full h-full not-lg:bg-container rounded-2xl overflow-hidden lg:rounded-r-none lg:order-1">
|
||||||
<Image
|
<Image
|
||||||
className='w-full object-cover bg-[#F2F2F9] h-full'
|
className="w-full object-cover bg-[#F2F2F9] h-full"
|
||||||
src={foodImage}
|
src={foodImage}
|
||||||
alt={foodName}
|
alt={foodName}
|
||||||
height={100}
|
height={100}
|
||||||
@@ -140,55 +142,62 @@ function FoodPage({ }: Props) {
|
|||||||
/>
|
/>
|
||||||
<div className="absolute top-4 left-0 pe-5.5 ps-7 w-full inline-flex justify-between items-center">
|
<div className="absolute top-4 left-0 pe-5.5 ps-7 w-full inline-flex justify-between items-center">
|
||||||
<div className="bg-container whitespace-nowrap rounded-[34px] py-1.5 px-4 w-min text-xs text-disabled2 dark:text-disabled-text font-bold">
|
<div className="bg-container whitespace-nowrap rounded-[34px] py-1.5 px-4 w-min text-xs text-disabled2 dark:text-disabled-text font-bold">
|
||||||
{categoryName || '-'}
|
{categoryName || "-"}
|
||||||
</div>
|
</div>
|
||||||
<button onClick={handleBackToMenu} className='p-2 rounded-full bg-container/40'>
|
<button
|
||||||
<ArrowLeft size={18} className='stroke-primary dark:stroke-foreground' />
|
onClick={handleBackToMenu}
|
||||||
|
className="p-2 rounded-full bg-container/40"
|
||||||
|
>
|
||||||
|
<ArrowLeft
|
||||||
|
size={18}
|
||||||
|
className="stroke-primary dark:stroke-foreground"
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative px-6 pt-6 pb-7.5 lg:flex lg:flex-col lg:justify-center bg-container w-full rounded-3xl overflow-hidden not-lg:-translate-y-6 lg:rounded-l-none">
|
<div className="relative px-6 pt-6 pb-7.5 lg:flex lg:flex-col lg:justify-center bg-container w-full rounded-3xl overflow-hidden not-lg:-translate-y-6 lg:rounded-l-none">
|
||||||
<div className="w-full inline-flex justify-between items-center">
|
<div className="w-full inline-flex justify-between items-center">
|
||||||
<h5 className="text-base font-bold">
|
<h5 className="text-base font-bold">{foodName}</h5>
|
||||||
{foodName}
|
|
||||||
</h5>
|
|
||||||
<button
|
<button
|
||||||
onClick={handleToggleFavorite}
|
onClick={handleToggleFavorite}
|
||||||
className='p-2 bg-[#EAECF0] dark:bg-neutral-600 rounded-lg'
|
className="p-2 bg-[#EAECF0] dark:bg-neutral-600 rounded-lg"
|
||||||
>
|
>
|
||||||
<Heart
|
<Heart
|
||||||
variant={isFavorite ? 'Bold' : 'Outline'}
|
variant={isFavorite ? "Bold" : "Outline"}
|
||||||
size={24}
|
size={24}
|
||||||
color='currentColor'
|
color="currentColor"
|
||||||
className={isFavorite ? 'fill-primary dark:fill-foreground' : ''}
|
className={isFavorite ? "fill-primary dark:fill-foreground" : ""}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 text-xs">
|
<div className="mt-4 text-xs">
|
||||||
<div className='flex items-center gap-1'>
|
<div className="flex items-center gap-1">
|
||||||
<Clock size={14} className='stroke-disabled-text' />
|
<Clock size={14} className="stroke-disabled-text" />
|
||||||
<span className='text-disabled-text'>
|
<span className="text-disabled-text">
|
||||||
زمان پخت و آماده سازی: {prepareTime > 0 ? `${ef(String(prepareTime))} دقیقه` : '-'}
|
زمان پخت و آماده سازی:{" "}
|
||||||
|
{prepareTime > 0 ? `${ef(String(prepareTime))} دقیقه` : "-"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center gap-2 mt-2'>
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<Cup size={14} className='stroke-disabled-text' />
|
<Cup size={14} className="stroke-disabled-text" />
|
||||||
<span className='text-disabled-text flex gap-1'>
|
<span className="text-disabled-text flex gap-1">
|
||||||
{about?.data?.plan === 'base' ? (
|
{about?.data?.plan === "base" ? (
|
||||||
<>
|
<>
|
||||||
<div>۰</div>
|
<div>۰</div>
|
||||||
<span>امتیاز برای هر بار خرید</span>
|
<span>امتیاز برای هر بار خرید</span>
|
||||||
</>
|
</>
|
||||||
) : about?.data?.score?.purchaseScore && about?.data?.score?.purchaseAmount ? (
|
) : about?.data?.score?.purchaseScore &&
|
||||||
|
about?.data?.score?.purchaseAmount ? (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{ef(
|
{ef(
|
||||||
Math.round(
|
Math.round(
|
||||||
foodData?.price *
|
foodData?.price *
|
||||||
(Number(about.data.score.purchaseScore) / Number(about.data.score.purchaseAmount))
|
(Number(about.data.score.purchaseScore) /
|
||||||
).toLocaleString('en-US')
|
Number(about.data.score.purchaseAmount)),
|
||||||
|
).toLocaleString("en-US"),
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span>امتیاز برای هر بار خرید</span>
|
<span>امتیاز برای هر بار خرید</span>
|
||||||
@@ -198,21 +207,21 @@ function FoodPage({ }: Props) {
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex items-center gap-2 mt-2'>
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<TruckTick size={14} className='stroke-disabled-text' />
|
<TruckTick size={14} className="stroke-disabled-text" />
|
||||||
<span className='text-disabled-text'>
|
<span className="text-disabled-text">
|
||||||
{foodData.pickupServe ? 'ارسال با پیک' : '-'}
|
{foodData.pickupServe ? "ارسال با پیک" : "-"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-7 text-xs">
|
<div className="mt-7 text-xs">
|
||||||
<p className='font-bold'>محتویات:</p>
|
<p className="font-bold">محتویات:</p>
|
||||||
<p className='mt-2 leading-6'>{content || '-'}</p>
|
<p className="mt-2 leading-6">{content || "-"}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mt-12 flex justify-between items-center'>
|
<div className="mt-12 flex justify-between items-center">
|
||||||
<span dir='ltr'>{ef(price.toLocaleString('en-US'))} T</span>
|
<span dir="ltr">{ef(price.toLocaleString("en-US"))} T</span>
|
||||||
<motion.div
|
<motion.div
|
||||||
whileTap={{ scale: 1.05 }}
|
whileTap={{ scale: 1.05 }}
|
||||||
className="bg-background active:drop-shadow-xs max-w-[115px] rounded-md w-full h-8 inline-flex p-1 justify-between items-center gap-2 relative overflow-hidden"
|
className="bg-background active:drop-shadow-xs max-w-[115px] rounded-md w-full h-8 inline-flex p-1 justify-between items-center gap-2 relative overflow-hidden"
|
||||||
@@ -256,7 +265,7 @@ function FoodPage({ }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FoodPage
|
export default FoodPage;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { usePathname } from "next/navigation";
|
import { Category } from "@/app/[name]/(Main)/types/Types";
|
||||||
import Image from "next/image";
|
|
||||||
import clsx from "clsx";
|
|
||||||
import HorizontalScrollView from "@/components/listview/HorizontalScrollView";
|
|
||||||
import CategoryItemRenderer from "@/components/listview/CategoryItemRenderer";
|
import CategoryItemRenderer from "@/components/listview/CategoryItemRenderer";
|
||||||
import CategorySmallItemRenderer from "@/components/listview/CategorySmallItemRenderer";
|
import CategorySmallItemRenderer from "@/components/listview/CategorySmallItemRenderer";
|
||||||
import { Category } from "@/app/[name]/(Main)/types/Types";
|
import HorizontalScrollView from "@/components/listview/HorizontalScrollView";
|
||||||
|
import clsx from "clsx";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
const SVG_MASK_STYLE = {
|
const SVG_MASK_STYLE = {
|
||||||
maskSize: "contain",
|
maskSize: "contain",
|
||||||
@@ -71,9 +70,7 @@ function CategoryImage({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <img src={src} width={size} height={size} alt={alt} loading="lazy" />;
|
||||||
<Image priority src={src} width={size} height={size} alt={alt} />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Variant = "large" | "small";
|
type Variant = "large" | "small";
|
||||||
@@ -121,7 +118,7 @@ const CategoryScroll = ({
|
|||||||
className={clsx(
|
className={clsx(
|
||||||
"w-full noscrollbar py-4!",
|
"w-full noscrollbar py-4!",
|
||||||
variant === "large" && "mt-4!",
|
variant === "large" && "mt-4!",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* <Renderer
|
{/* <Renderer
|
||||||
@@ -153,7 +150,9 @@ const CategoryScroll = ({
|
|||||||
alt="category image"
|
alt="category image"
|
||||||
proxyBase={proxyBase}
|
proxyBase={proxyBase}
|
||||||
/>
|
/>
|
||||||
<span className="text-xs text-foreground text-center">{item.title}</span>
|
<span className="text-xs text-foreground text-center">
|
||||||
|
{item.title}
|
||||||
|
</span>
|
||||||
</Renderer>
|
</Renderer>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -162,4 +161,3 @@ const CategoryScroll = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default CategoryScroll;
|
export default CategoryScroll;
|
||||||
|
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ const MenuIndex = () => {
|
|||||||
const selectedCatId = selectedCategory === '0' ? null : selectedCategory;
|
const selectedCatId = selectedCategory === '0' ? null : selectedCategory;
|
||||||
|
|
||||||
const filtered = foods.filter((item) => {
|
const filtered = foods.filter((item) => {
|
||||||
const matchesCategory = !selectedCatId || item.category?.id === selectedCatId;
|
const matchesCategory = !selectedCatId || item.category === selectedCatId;
|
||||||
const itemName = item.name || item.title || item.foodName || "";
|
const itemName = item.title;
|
||||||
const matchesSearch =
|
const matchesSearch =
|
||||||
!search || itemName.toLowerCase().includes(lowerSearch);
|
!search || itemName.toLowerCase().includes(lowerSearch);
|
||||||
|
|
||||||
@@ -134,9 +134,7 @@ const MenuIndex = () => {
|
|||||||
content.toLowerCase().includes(lowerIngredients)
|
content.toLowerCase().includes(lowerIngredients)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// اگر محتویات وجود نداشت یا خالی بود، در توضیحات جستجو میکنیم
|
return item.desc.toLowerCase().includes(lowerIngredients);
|
||||||
const description = item.description || item.desc || "";
|
|
||||||
return description.toLowerCase().includes(lowerIngredients);
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const matchesDelivery = selectedDeliveryId === "0" ||
|
const matchesDelivery = selectedDeliveryId === "0" ||
|
||||||
@@ -151,9 +149,8 @@ const MenuIndex = () => {
|
|||||||
return [...filtered].sort((a, b) => {
|
return [...filtered].sort((a, b) => {
|
||||||
switch (sortingKey) {
|
switch (sortingKey) {
|
||||||
case "PopularityDescending":
|
case "PopularityDescending":
|
||||||
return (b.points ?? 0) - (a.points ?? 0);
|
|
||||||
case "RateDescending":
|
case "RateDescending":
|
||||||
return (b.rate ?? 0) - (a.rate ?? 0);
|
return 0;
|
||||||
case "PriceAscending":
|
case "PriceAscending":
|
||||||
return (a.price ?? 0) - (b.price ?? 0);
|
return (a.price ?? 0) - (b.price ?? 0);
|
||||||
case "PriceDescending":
|
case "PriceDescending":
|
||||||
|
|||||||
@@ -30,7 +30,25 @@ export interface InventoryRef {
|
|||||||
|
|
||||||
export type MealType = "breakfast" | "lunch" | "dinner" | "snack";
|
export type MealType = "breakfast" | "lunch" | "dinner" | "snack";
|
||||||
|
|
||||||
|
/** آیتم منو در لیست غذاهای رستوران */
|
||||||
export interface Food {
|
export interface Food {
|
||||||
|
id: string;
|
||||||
|
category: string;
|
||||||
|
title: string;
|
||||||
|
desc: string;
|
||||||
|
content: string[];
|
||||||
|
price: number;
|
||||||
|
prepareTime: number;
|
||||||
|
isActive: boolean;
|
||||||
|
images: string[];
|
||||||
|
inPlaceServe: boolean;
|
||||||
|
pickupServe: boolean;
|
||||||
|
discount: number;
|
||||||
|
isSpecialOffer: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** جزئیات کامل یک غذا (endpoint تکی) */
|
||||||
|
export interface FoodDetail {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
@@ -75,7 +93,7 @@ export interface Food {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type FoodsResponse = BaseResponse<Food[]>;
|
export type FoodsResponse = BaseResponse<Food[]>;
|
||||||
export type FoodResponse = BaseResponse<Food>;
|
export type FoodResponse = BaseResponse<FoodDetail>;
|
||||||
|
|
||||||
export interface NotificationsCountData {
|
export interface NotificationsCountData {
|
||||||
count: number;
|
count: number;
|
||||||
|
|||||||
@@ -24,32 +24,18 @@ function FavoritePage() {
|
|||||||
// تبدیل FavoriteFood به Food برای استفاده در MenuItem
|
// تبدیل FavoriteFood به Food برای استفاده در MenuItem
|
||||||
const food: Food = {
|
const food: Food = {
|
||||||
id: favoriteFood.id,
|
id: favoriteFood.id,
|
||||||
createdAt: favoriteFood.createdAt,
|
category: favoriteFood.category,
|
||||||
updatedAt: favoriteFood.updatedAt,
|
|
||||||
deletedAt: favoriteFood.deletedAt,
|
|
||||||
restaurant: favoriteFood.restaurant as unknown as Food['restaurant'],
|
|
||||||
category: favoriteFood.category as unknown as Food['category'],
|
|
||||||
inventory: {} as Food['inventory'],
|
|
||||||
title: favoriteFood.title,
|
title: favoriteFood.title,
|
||||||
desc: favoriteFood.desc,
|
desc: favoriteFood.desc,
|
||||||
content: favoriteFood.content,
|
content: favoriteFood.content,
|
||||||
price: favoriteFood.price,
|
price: favoriteFood.price,
|
||||||
order: favoriteFood.order,
|
prepareTime: favoriteFood.prepareTime ?? 0,
|
||||||
prepareTime: favoriteFood.prepareTime,
|
|
||||||
weekDays: favoriteFood.weekDays,
|
|
||||||
mealTypes: favoriteFood.mealTypes,
|
|
||||||
isActive: favoriteFood.isActive,
|
isActive: favoriteFood.isActive,
|
||||||
images: favoriteFood.images,
|
images: favoriteFood.images,
|
||||||
inPlaceServe: favoriteFood.inPlaceServe,
|
inPlaceServe: favoriteFood.inPlaceServe,
|
||||||
pickupServe: favoriteFood.pickupServe,
|
pickupServe: favoriteFood.pickupServe,
|
||||||
score: favoriteFood.score,
|
|
||||||
discount: favoriteFood.discount,
|
discount: favoriteFood.discount,
|
||||||
isSpecialOffer: favoriteFood.isSpecialOffer,
|
isSpecialOffer: favoriteFood.isSpecialOffer,
|
||||||
reviews: [],
|
|
||||||
favorites: [],
|
|
||||||
isFavorite: true,
|
|
||||||
name: favoriteFood.title,
|
|
||||||
description: favoriteFood.desc,
|
|
||||||
}
|
}
|
||||||
return food
|
return food
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { memo, useMemo } from "react";
|
import { useCart } from "@/app/[name]/(Dialogs)/cart/hook/useCart";
|
||||||
|
import type { Food, FoodImage } from "@/app/[name]/(Main)/types/Types";
|
||||||
|
import MinusIcon from "@/components/icons/MinusIcon";
|
||||||
|
import PlusIcon from "@/components/icons/PlusIcon";
|
||||||
|
import { motion } from "framer-motion";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import PlusIcon from "@/components/icons/PlusIcon";
|
import { memo, useMemo } from "react";
|
||||||
import MinusIcon from "@/components/icons/MinusIcon";
|
|
||||||
import { useCart } from "@/app/[name]/(Dialogs)/cart/hook/useCart";
|
|
||||||
import { motion } from "framer-motion";
|
|
||||||
import type { Food, FoodImage } from "@/app/[name]/(Main)/types/Types";
|
|
||||||
|
|
||||||
interface MenuItemProps {
|
interface MenuItemProps {
|
||||||
food: Food;
|
food: Food;
|
||||||
@@ -17,11 +17,11 @@ interface MenuItemProps {
|
|||||||
const MenuItem = ({ food }: MenuItemProps) => {
|
const MenuItem = ({ food }: MenuItemProps) => {
|
||||||
const { items, addToCart, removeFromCart } = useCart();
|
const { items, addToCart, removeFromCart } = useCart();
|
||||||
const params = useParams<{ name: string }>();
|
const params = useParams<{ name: string }>();
|
||||||
const name = params?.name || '';
|
const name = params?.name || "";
|
||||||
|
|
||||||
const quantity = useMemo(() => {
|
const quantity = useMemo(() => {
|
||||||
const item = items?.[food.id];
|
const item = items?.[food.id];
|
||||||
if (item && typeof item === 'object' && 'quantity' in item) {
|
if (item && typeof item === "object" && "quantity" in item) {
|
||||||
return item.quantity || 0;
|
return item.quantity || 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -29,7 +29,6 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
|
|
||||||
const fallbackImage = "/assets/images/no-image.png";
|
const fallbackImage = "/assets/images/no-image.png";
|
||||||
const resolvedImage = useMemo(() => {
|
const resolvedImage = useMemo(() => {
|
||||||
if (food.image) return food.image;
|
|
||||||
if (Array.isArray(food.images) && food.images.length > 0) {
|
if (Array.isArray(food.images) && food.images.length > 0) {
|
||||||
const [firstImage] = food.images;
|
const [firstImage] = food.images;
|
||||||
if (typeof firstImage === "string") return firstImage;
|
if (typeof firstImage === "string") return firstImage;
|
||||||
@@ -37,29 +36,28 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
return (typeof imageObj === "object" && imageObj?.url) || fallbackImage;
|
return (typeof imageObj === "object" && imageObj?.url) || fallbackImage;
|
||||||
}
|
}
|
||||||
return fallbackImage;
|
return fallbackImage;
|
||||||
}, [food.image, food.images]);
|
}, [food.images]);
|
||||||
|
|
||||||
const foodName = useMemo(
|
const foodName = useMemo(() => food.title || "بدون نام", [food.title]);
|
||||||
() => food.name || food.title || food.foodName || 'بدون نام',
|
|
||||||
[food.name, food.title, food.foodName]
|
|
||||||
);
|
|
||||||
|
|
||||||
const foodContent = useMemo(() => {
|
const foodContent = useMemo(() => {
|
||||||
const content = food.content;
|
const content = food.content;
|
||||||
if (!content) return '';
|
if (!content) return "";
|
||||||
|
|
||||||
if (Array.isArray(content)) {
|
if (Array.isArray(content)) {
|
||||||
return content.filter(item => item && typeof item === 'string').join('، ');
|
return content
|
||||||
|
.filter((item) => item && typeof item === "string")
|
||||||
|
.join("، ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return "";
|
||||||
}, [food.content]);
|
}, [food.content]);
|
||||||
|
|
||||||
const foodDescription = useMemo(() => {
|
const foodDescription = useMemo(() => {
|
||||||
const desc = food.description || food.desc;
|
const desc = food.desc;
|
||||||
if (!desc || typeof desc !== 'string') return '';
|
if (!desc || typeof desc !== "string") return "";
|
||||||
return desc.replace(/,/g, '،');
|
return desc.replace(/,/g, "،");
|
||||||
}, [food.description, food.desc]);
|
}, [food.desc]);
|
||||||
|
|
||||||
const finalPrice = useMemo(() => {
|
const finalPrice = useMemo(() => {
|
||||||
const basePrice = food.price || 0;
|
const basePrice = food.price || 0;
|
||||||
@@ -71,19 +69,16 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
}, [food.price, food.discount]);
|
}, [food.price, food.discount]);
|
||||||
|
|
||||||
const formattedPrice = useMemo(
|
const formattedPrice = useMemo(
|
||||||
() => (finalPrice ? finalPrice.toLocaleString('fa-IR') : '0'),
|
() => (finalPrice ? finalPrice.toLocaleString("fa-IR") : "0"),
|
||||||
[finalPrice]
|
[finalPrice],
|
||||||
);
|
);
|
||||||
|
|
||||||
const formattedOriginalPrice = useMemo(
|
const formattedOriginalPrice = useMemo(
|
||||||
() => (food.price ? food.price.toLocaleString('fa-IR') : '0'),
|
() => (food.price ? food.price.toLocaleString("fa-IR") : "0"),
|
||||||
[food.price]
|
[food.price],
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasDiscount = useMemo(
|
const hasDiscount = useMemo(() => (food.discount || 0) > 0, [food.discount]);
|
||||||
() => (food.discount || 0) > 0,
|
|
||||||
[food.discount]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleAddToCart = () => {
|
const handleAddToCart = () => {
|
||||||
addToCart(food.id);
|
addToCart(food.id);
|
||||||
@@ -93,7 +88,7 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
removeFromCart(food.id);
|
removeFromCart(food.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const foodDetailUrl = `/${name}/${food.id}?category=${food.category.id}`;
|
const foodDetailUrl = `/${name}/${food.id}?category=${food.category}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-4 w-full h-full items-center">
|
<div className="flex gap-4 w-full h-full items-center">
|
||||||
@@ -104,6 +99,7 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
height={112}
|
height={112}
|
||||||
width={112}
|
width={112}
|
||||||
alt={foodName}
|
alt={foodName}
|
||||||
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
<div className="w-full inline-flex flex-col justify-between min-w-0">
|
<div className="w-full inline-flex flex-col justify-between min-w-0">
|
||||||
@@ -144,7 +140,6 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
<button
|
<button
|
||||||
onClick={handleAddToCart}
|
onClick={handleAddToCart}
|
||||||
className="inline-flex w-full justify-center items-center gap-2"
|
className="inline-flex w-full justify-center items-center gap-2"
|
||||||
|
|
||||||
>
|
>
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
<div className="text-sm2 pt-0.5 font-normal text-foreground">
|
<div className="text-sm2 pt-0.5 font-normal text-foreground">
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
// export const API_BASE_URL = "https://dmenuplus-api.dev.danakcorp.com";
|
// export const API_BASE_URL = "https://dmenuplus-api.dev.danakcorp.com";
|
||||||
export const API_BASE_URL = "https://dmenu-api.danakcorp.com";
|
// export const API_BASE_URL = "https://dmenu-api.danakcorp.com";
|
||||||
|
export const API_BASE_URL = "http://192.168.99.131:2000";
|
||||||
export const TOKEN_NAME = "dmenu-t";
|
export const TOKEN_NAME = "dmenu-t";
|
||||||
export const REFRESH_TOKEN_NAME = "dmenu-rt";
|
export const REFRESH_TOKEN_NAME = "dmenu-rt";
|
||||||
|
|||||||
Reference in New Issue
Block a user