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