fix filter with category id
This commit is contained in:
@@ -16,6 +16,7 @@ import CategoryScroll from "@/app/[name]/(Main)/components/CategoryScroll";
|
|||||||
import MenuFilterDrawer from "@/app/[name]/(Main)/components/MenuFilterDrawer";
|
import MenuFilterDrawer from "@/app/[name]/(Main)/components/MenuFilterDrawer";
|
||||||
import MenuSortingDrawer from "@/app/[name]/(Main)/components/MenuSortingDrawer";
|
import MenuSortingDrawer from "@/app/[name]/(Main)/components/MenuSortingDrawer";
|
||||||
import { useGetCategories, useGetFoods } from "./hooks/useMenuData";
|
import { useGetCategories, useGetFoods } from "./hooks/useMenuData";
|
||||||
|
import type { Food, Category } from "./types/Types";
|
||||||
|
|
||||||
const sortings = [
|
const sortings = [
|
||||||
"PopularityDescending",
|
"PopularityDescending",
|
||||||
@@ -23,17 +24,14 @@ const sortings = [
|
|||||||
"PriceAscending",
|
"PriceAscending",
|
||||||
"RateDescending",
|
"RateDescending",
|
||||||
"PriceDescending"
|
"PriceDescending"
|
||||||
]
|
];
|
||||||
|
|
||||||
const MenuIndex = () => {
|
const MenuIndex = () => {
|
||||||
const { data: foodsData } = useGetFoods();
|
const { data: foodsData } = useGetFoods();
|
||||||
const { data: categoriesData } = useGetCategories();
|
const { data: categoriesData } = useGetCategories();
|
||||||
|
|
||||||
const foods = useMemo(() => {
|
const foods = useMemo<Food[]>(() => foodsData?.data || [], [foodsData?.data]);
|
||||||
const foodsList = foodsData?.data || [];
|
const categories = useMemo<Category[]>(() => categoriesData?.data || [], [categoriesData?.data]);
|
||||||
return foodsList;
|
|
||||||
}, [foodsData?.data]);
|
|
||||||
const categories = useMemo(() => categoriesData?.data || [], [categoriesData?.data]);
|
|
||||||
const { t: tCommon } = useTranslation('common');
|
const { t: tCommon } = useTranslation('common');
|
||||||
const { t: tMenu } = useTranslation('menu', {
|
const { t: tMenu } = useTranslation('menu', {
|
||||||
keyPrefix: "Menu"
|
keyPrefix: "Menu"
|
||||||
@@ -103,7 +101,8 @@ const MenuIndex = () => {
|
|||||||
|
|
||||||
return foods.filter(
|
return foods.filter(
|
||||||
(item) => {
|
(item) => {
|
||||||
const matchesCategory = selectedCategory === '0' || item.category === selectedCatId;
|
const matchesCategory =
|
||||||
|
selectedCategory === '0' || item.category?.id === selectedCatId;
|
||||||
const itemName = item.name || item.title || item.foodName || '';
|
const itemName = item.name || item.title || item.foodName || '';
|
||||||
const matchesSearch = !search || itemName.toLowerCase().includes(lowerSearch);
|
const matchesSearch = !search || itemName.toLowerCase().includes(lowerSearch);
|
||||||
return matchesCategory && matchesSearch;
|
return matchesCategory && matchesSearch;
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { api } from "@/lib/api/axiosInstance";
|
import { api } from "@/config/axios";
|
||||||
import {
|
import { CategoriesResponse, FoodsResponse } from "../types/Types";
|
||||||
CategoriesResponse,
|
|
||||||
FoodsResponse,
|
|
||||||
} from "@/app/[name]/(Main)/types/Types";
|
|
||||||
|
|
||||||
export const getFoods = async (slug: string): Promise<FoodsResponse> => {
|
export const getFoods = async (slug: string): Promise<FoodsResponse> => {
|
||||||
const response = await api.get<FoodsResponse>(
|
const response = await api.get<FoodsResponse>(
|
||||||
|
|||||||
@@ -5,22 +5,6 @@ export interface BaseResponse<T = unknown> {
|
|||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Food {
|
|
||||||
id: string;
|
|
||||||
name?: string;
|
|
||||||
title?: string;
|
|
||||||
foodName?: string;
|
|
||||||
description?: string;
|
|
||||||
desc?: string;
|
|
||||||
content?: string;
|
|
||||||
price: number;
|
|
||||||
image?: string;
|
|
||||||
category?: string;
|
|
||||||
[key: string]: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FoodsResponse = BaseResponse<Food[]>;
|
|
||||||
|
|
||||||
export interface Category {
|
export interface Category {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
@@ -33,3 +17,42 @@ export interface Category {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type CategoriesResponse = BaseResponse<Category[]>;
|
export type CategoriesResponse = BaseResponse<Category[]>;
|
||||||
|
|
||||||
|
export type FoodImage = string | { url: string; alt?: string | null };
|
||||||
|
|
||||||
|
export interface Food {
|
||||||
|
id: string;
|
||||||
|
createdAt?: string;
|
||||||
|
updatedAt?: string;
|
||||||
|
deletedAt?: string | null;
|
||||||
|
restaurant?: string;
|
||||||
|
category?: Category;
|
||||||
|
name?: string;
|
||||||
|
title?: string;
|
||||||
|
foodName?: string;
|
||||||
|
description?: string;
|
||||||
|
desc?: string | null;
|
||||||
|
content?: string | null;
|
||||||
|
price: number;
|
||||||
|
image?: string | null;
|
||||||
|
images?: FoodImage[] | null;
|
||||||
|
points?: number | null;
|
||||||
|
order?: number | null;
|
||||||
|
prepareTime?: number | null;
|
||||||
|
sat?: boolean;
|
||||||
|
sun?: boolean;
|
||||||
|
mon?: boolean;
|
||||||
|
breakfast?: boolean;
|
||||||
|
noon?: boolean;
|
||||||
|
dinner?: boolean;
|
||||||
|
stock?: number;
|
||||||
|
stockDefault?: number;
|
||||||
|
isActive?: boolean;
|
||||||
|
inPlaceServe?: boolean;
|
||||||
|
pickupServe?: boolean;
|
||||||
|
rate?: number;
|
||||||
|
discount?: number;
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FoodsResponse = BaseResponse<Food[]>;
|
||||||
|
|||||||
@@ -1,23 +1,14 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { memo } from "react";
|
import { memo, useMemo } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import PlusIcon from "@/components/icons/PlusIcon";
|
import PlusIcon from "@/components/icons/PlusIcon";
|
||||||
import MinusIcon from "@/components/icons/MinusIcon";
|
import MinusIcon from "@/components/icons/MinusIcon";
|
||||||
import { useReceiptStore } from "@/zustand/receiptStore";
|
import { useReceiptStore } from "@/zustand/receiptStore";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
|
import type { Food } from "@/app/[name]/(Main)/types/Types";
|
||||||
interface MenuItemProps {
|
interface MenuItemProps {
|
||||||
food: {
|
food: Food;
|
||||||
id: string | number;
|
|
||||||
name?: string;
|
|
||||||
title?: string;
|
|
||||||
foodName?: string;
|
|
||||||
description?: string;
|
|
||||||
desc?: string;
|
|
||||||
content?: string;
|
|
||||||
price: number;
|
|
||||||
image?: string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MenuItem = ({ food }: MenuItemProps) => {
|
const MenuItem = ({ food }: MenuItemProps) => {
|
||||||
@@ -26,7 +17,16 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
const increment = useReceiptStore(state => state.increment);
|
const increment = useReceiptStore(state => state.increment);
|
||||||
const decrement = useReceiptStore(state => state.decrement);
|
const decrement = useReceiptStore(state => state.decrement);
|
||||||
|
|
||||||
if (!food) return null;
|
const fallbackImage = "/assets/images/food-preview.png";
|
||||||
|
const resolvedImage = useMemo(() => {
|
||||||
|
if (food.image) return food.image;
|
||||||
|
if (Array.isArray(food.images) && food.images.length > 0) {
|
||||||
|
const [firstImage] = food.images;
|
||||||
|
if (typeof firstImage === "string") return firstImage;
|
||||||
|
return firstImage?.url || fallbackImage;
|
||||||
|
}
|
||||||
|
return fallbackImage;
|
||||||
|
}, [food.image, food.images]);
|
||||||
|
|
||||||
const foodName = food.name || food.title || food.foodName || 'بدون نام';
|
const foodName = food.name || food.title || food.foodName || 'بدون نام';
|
||||||
const foodDescription = food.description || food.desc || food.content || '';
|
const foodDescription = food.description || food.desc || food.content || '';
|
||||||
@@ -35,7 +35,7 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
|||||||
<div className="flex gap-4 w-full h-full">
|
<div className="flex gap-4 w-full h-full">
|
||||||
<Image
|
<Image
|
||||||
className="rounded-xl w-28 h-28"
|
className="rounded-xl w-28 h-28"
|
||||||
src={food.image || "/assets/images/food-preview.png"}
|
src={resolvedImage}
|
||||||
height={100}
|
height={100}
|
||||||
width={100}
|
width={100}
|
||||||
alt="Food image"
|
alt="Food image"
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { api } from "@/lib/api/axiosInstance";
|
||||||
|
|
||||||
|
export { api };
|
||||||
|
|
||||||
Reference in New Issue
Block a user