add pagination and inverntory
This commit is contained in:
@@ -17,7 +17,6 @@ const FoodsList: FC = () => {
|
|||||||
apiParams,
|
apiParams,
|
||||||
handleFiltersChange,
|
handleFiltersChange,
|
||||||
handlePageChange,
|
handlePageChange,
|
||||||
limit,
|
|
||||||
} = useFoodFilters()
|
} = useFoodFilters()
|
||||||
|
|
||||||
const { data: foodsData, isLoading } = useGetFoods(apiParams)
|
const { data: foodsData, isLoading } = useGetFoods(apiParams)
|
||||||
@@ -30,7 +29,7 @@ const FoodsList: FC = () => {
|
|||||||
})
|
})
|
||||||
const filterFields = useFoodFiltersFields()
|
const filterFields = useFoodFiltersFields()
|
||||||
|
|
||||||
const totalPages = Math.ceil(foods.length / limit) || 1
|
const totalPages = foodsData?.meta?.totalPages || 1
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mt-5'>
|
<div className='mt-5'>
|
||||||
|
|||||||
@@ -60,6 +60,24 @@ export const getFoodTableColumns = ({ onDelete, isDeleting }: GetFoodTableColumn
|
|||||||
return formatTime(item.prepareTime || 0)
|
return formatTime(item.prepareTime || 0)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'inventory',
|
||||||
|
title: 'موجودی',
|
||||||
|
render: (item: Food) => {
|
||||||
|
const availableStock = item.inventory.availableStock
|
||||||
|
const totalStock = item.inventory.totalStock
|
||||||
|
return (
|
||||||
|
<div className='flex flex-col gap-1'>
|
||||||
|
<span className='text-sm'>
|
||||||
|
{availableStock} / {totalStock}
|
||||||
|
</span>
|
||||||
|
{availableStock === 0 && (
|
||||||
|
<span className='text-xs text-red-500'>ناموجود</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'isActive',
|
key: 'isActive',
|
||||||
title: 'وضعیت',
|
title: 'وضعیت',
|
||||||
|
|||||||
@@ -40,6 +40,16 @@ export type FoodDetailsCategory = {
|
|||||||
avatarUrl: string | null;
|
avatarUrl: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Inventory = {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
food: string;
|
||||||
|
totalStock: number;
|
||||||
|
availableStock: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type Food = {
|
export type Food = {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
@@ -47,7 +57,7 @@ export type Food = {
|
|||||||
deletedAt: string | null;
|
deletedAt: string | null;
|
||||||
restaurant: string;
|
restaurant: string;
|
||||||
category: FoodDetailsCategory;
|
category: FoodDetailsCategory;
|
||||||
inventory: string | null;
|
inventory: Inventory;
|
||||||
title: string;
|
title: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
content: string[];
|
content: string[];
|
||||||
@@ -60,7 +70,7 @@ export type Food = {
|
|||||||
images: string[];
|
images: string[];
|
||||||
inPlaceServe: boolean;
|
inPlaceServe: boolean;
|
||||||
pickupServe: boolean;
|
pickupServe: boolean;
|
||||||
score: number | null;
|
score: number;
|
||||||
discount: number;
|
discount: number;
|
||||||
isSpecialOffer: boolean;
|
isSpecialOffer: boolean;
|
||||||
};
|
};
|
||||||
@@ -82,7 +92,7 @@ export type FoodDetails = {
|
|||||||
deletedAt: string | null;
|
deletedAt: string | null;
|
||||||
restaurant: string;
|
restaurant: string;
|
||||||
category: FoodDetailsCategory;
|
category: FoodDetailsCategory;
|
||||||
inventory: string | null;
|
inventory: Inventory | null;
|
||||||
title: string;
|
title: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
content: string[];
|
content: string[];
|
||||||
@@ -100,8 +110,15 @@ export type FoodDetails = {
|
|||||||
isSpecialOffer: boolean;
|
isSpecialOffer: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type PaginationMeta = {
|
||||||
|
total: number;
|
||||||
|
page: string;
|
||||||
|
limit: string;
|
||||||
|
totalPages: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type GetCategoriesResponseType = IResponse<Category[]>;
|
export type GetCategoriesResponseType = IResponse<Category[]>;
|
||||||
export type GetFoodsResponseType = IResponse<Food[]>;
|
export type GetFoodsResponseType = IResponse<Food[]> & { meta: PaginationMeta };
|
||||||
export type GetFoodDetailsResponseType = IResponse<FoodDetails>;
|
export type GetFoodDetailsResponseType = IResponse<FoodDetails>;
|
||||||
|
|
||||||
export type CreateCategoryType = {
|
export type CreateCategoryType = {
|
||||||
|
|||||||
Reference in New Issue
Block a user