diff --git a/src/pages/order/List.tsx b/src/pages/order/List.tsx index 2a4129d..2702f32 100644 --- a/src/pages/order/List.tsx +++ b/src/pages/order/List.tsx @@ -1,4 +1,4 @@ -import Filters from '@/components/Filters' +import Filters, { type FilterValues } from '@/components/Filters' import { type FC, useState } from 'react' import Table from '@/components/Table' import { AddSquare, Edit2, Eye, Printer, Receipt21 } from 'iconsax-react' @@ -10,10 +10,16 @@ import type { OrderListItemType } from './types/Types' import Button from '@/components/Button' import UserSearch from '../user/UserSearch' import DesignerSearch from '../designer/DesignerSearch' +import CategoriesSelect from '../product/components/CategoriesSelect' const OrdersList: FC = () => { + const [designId, setDesignId] = useState() - const { data } = useGetOrders({ designId }) + const [categoryId, setCategoryId] = useState() + const [userId, setUserId] = useState() + const [filters, setFilters] = useState({}) + + const { data } = useGetOrders({ designId, categoryId, userId, ...filters }) return (
@@ -38,26 +44,37 @@ const OrdersList: FC = () => { placeholder: 'جستجو', }, { - name: 'status', - type: 'select', - placeholder: 'وضعیت', - options: [ - { label: 'درحال انتظار', value: 'pending' }, - ], + name: 'from', + type: 'date', + placeholder: 'از تاریخ', }, { - name: 'date', + name: 'to', type: 'date', - placeholder: 'تاریخ', + placeholder: 'تا تریخ', }, ]} - onChange={() => { }} /> - + onChange={setFilters} /> +
+ +
+ setUserId(id || undefined)} + /> setDesignId(id || undefined)} /> +
+ setCategoryId(e.target.value || undefined)} + /> +
diff --git a/src/pages/order/hooks/useOrderData.ts b/src/pages/order/hooks/useOrderData.ts index 51fe049..49babf1 100644 --- a/src/pages/order/hooks/useOrderData.ts +++ b/src/pages/order/hooks/useOrderData.ts @@ -6,9 +6,9 @@ import type { OrderPrintFormType, } from "../types/Types"; -export const useGetOrders = (params?: { designId?: string }) => { +export const useGetOrders = (params?: api.GetOrdersParams) => { return useQuery({ - queryKey: ["orders", params?.designId], + queryKey: ["orders", params], queryFn: () => api.getOrders(params), }); }; diff --git a/src/pages/order/service/OrderService.ts b/src/pages/order/service/OrderService.ts index b02202a..ee9f8da 100644 --- a/src/pages/order/service/OrderService.ts +++ b/src/pages/order/service/OrderService.ts @@ -15,9 +15,28 @@ import type { ProductResponeType, } from "@/pages/product/types/Types"; -export const getOrders = async (params?: { designId?: string }) => { +export type GetOrdersParams = { + designId?: string; + categoryId?: string; + userId?: string; + search?: string | null; + from?: string | null; + to?: string | null; +}; + +const cleanParams = (params?: GetOrdersParams) => { + if (!params) return undefined; + return Object.fromEntries( + Object.entries(params).filter( + ([_, v]) => v != null && v !== '', + ) as [string, string][], + ); +}; + +export const getOrders = async (params?: GetOrdersParams) => { + const query = cleanParams(params); const { data } = await axios.get(`/admin/orders`, { - params: params?.designId ? { designId: params.designId } : undefined, + params: query, }); return data; }; diff --git a/src/pages/product/components/CategoriesSelect.tsx b/src/pages/product/components/CategoriesSelect.tsx index cbc7bd8..3485d6f 100644 --- a/src/pages/product/components/CategoriesSelect.tsx +++ b/src/pages/product/components/CategoriesSelect.tsx @@ -4,6 +4,8 @@ import Select from '@/components/Select' type Props = { error_text?: string, + isDisableShowLable?: boolean, + placeholder?: string, } & SelectHTMLAttributes @@ -13,8 +15,8 @@ const CategoriesSelect: FC = (props) => { return (