filter category id

This commit is contained in:
hamid zarghami
2026-02-07 12:39:45 +03:30
parent 1552830e76
commit d9012e524a
5 changed files with 47 additions and 20 deletions
+10 -8
View File
@@ -174,14 +174,16 @@ const Filters: FC<FiltersProps> = ({
case 'select':
return (
<Select
key={field.name}
placeholder={field.placeholder}
onChange={(e) => handleChange(field.name, e.target.value)}
defaultValue={currentValue as string || field.defaultValue || ''}
items={field.options}
className='min-w-[170px]'
/>
<div className='mt-1'>
<Select
key={field.name}
placeholder={field.placeholder}
onChange={(e) => handleChange(field.name, e.target.value)}
defaultValue={currentValue as string || field.defaultValue || ''}
items={field.options}
className='min-w-[170px]'
/>
</div>
);
case 'multiselect':
+3 -1
View File
@@ -19,9 +19,11 @@ const FoodsList: FC = () => {
handlePageChange,
} = useFoodFilters()
const { data: foodsData, isLoading } = useGetFoods(apiParams)
const { data: foodsData, isLoading } = useGetFoods(apiParams, filters)
const { mutate: deleteFood, isPending: isDeleting } = useDeleteFood()
const foods = foodsData?.data || []
const columns = getFoodTableColumns({
onDelete: (id: string) => deleteFood(id),
@@ -1,13 +1,27 @@
import { useMemo } from 'react'
import type { FieldType } from '@/components/Filters'
import { useGetCategories } from '../hooks/useFoodData'
export const useFoodFiltersFields = (): FieldType[] => {
const { data } = useGetCategories()
return useMemo(() => [
{
type: 'input',
name: 'search',
placeholder: 'جستجو',
},
], [])
{
type: 'select',
name: 'categoryId',
placeholder: 'انتخاب',
options: data?.data?.map((item) => {
return {
label: item.title,
value: item.id
}
}) || []
},
], [data?.data])
}
+7 -3
View File
@@ -5,6 +5,7 @@ import type {
CreateFoodType,
GetFoodsParams,
} from "../types/Types";
import type { FilterValues } from "@/components/Filters";
export const useCreateFood = () => {
return useMutation({
@@ -12,10 +13,13 @@ export const useCreateFood = () => {
});
};
export const useGetFoods = (params?: GetFoodsParams) => {
export const useGetFoods = (
params?: GetFoodsParams,
filters?: FilterValues,
) => {
return useQuery({
queryKey: ["foods", params],
queryFn: () => api.getFoods(params),
queryKey: ["foods", params, filters],
queryFn: () => api.getFoods(params, filters),
});
};
+11 -6
View File
@@ -8,6 +8,7 @@ import type {
GetFoodsResponseType,
GetIconsResponseType,
} from "../types/Types";
import type { FilterValues } from "@/components/Filters";
export const createFood = async (params: CreateFoodType) => {
const { data } = await axios.post(`/admin/foods`, params);
@@ -15,19 +16,23 @@ export const createFood = async (params: CreateFoodType) => {
};
export const getFoods = async (
params?: GetFoodsParams
params?: GetFoodsParams,
filters?: FilterValues,
): Promise<GetFoodsResponseType> => {
const { data } = await axios.get<GetFoodsResponseType>(`/admin/foods`, {
params,
params: {
...params,
...filters,
},
});
return data;
};
export const getFoodDetails = async (
id: string
id: string,
): Promise<GetFoodDetailsResponseType> => {
const { data } = await axios.get<GetFoodDetailsResponseType>(
`/admin/foods/${id}`
`/admin/foods/${id}`,
);
return data;
};
@@ -39,7 +44,7 @@ export const updateFood = async (id: string, params: CreateFoodType) => {
export const getCategories = async (): Promise<GetCategoriesResponseType> => {
const { data } = await axios.get<GetCategoriesResponseType>(
`/admin/categories`
`/admin/categories`,
);
return data;
};
@@ -61,7 +66,7 @@ export const deleteCategory = async (id: string) => {
export const updateCategory = async (
id: string,
params: CreateCategoryType
params: CreateCategoryType,
) => {
const { data } = await axios.patch(`/admin/categories/${id}`, params);
return data;