From 24171dbaf8ebe298722762295718bd9521c5f938 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 22 Jul 2026 15:46:12 +0330 Subject: [PATCH] customer search --- .pnpm-store/v11/index.db | Bin 0 -> 8192 bytes src/pages/customer/List.tsx | 34 ++++++------------ src/pages/customer/hooks/useCustomerData.ts | 6 ++-- src/pages/customer/service/CustomerService.ts | 6 ++-- 4 files changed, 17 insertions(+), 29 deletions(-) create mode 100644 .pnpm-store/v11/index.db diff --git a/.pnpm-store/v11/index.db b/.pnpm-store/v11/index.db new file mode 100644 index 0000000000000000000000000000000000000000..7f9770bd25137067815560f9ef52a33e713f2b53 GIT binary patch literal 8192 zcmeIuzpBD86bA4#2p0s=&GDX11#$5OY&BppTCFMSqD0LV@%|C%po4=C;1j#tR!Xsx zd-*<+oFpepe$$EEhlalXPCq)NHmfksS%-)*#*-P9XRK%~B>T9;=Xc?(b$^tiS5|q+ zqJcmF0uX=z1Rwwb2tWV=5P$##awu^7v_7h}nsvK|di`yVdUMb_v)cb|%{g=6U0>Kr zkg^>qDAS^Pkk?+mi kUUFZI)hjuq$Cn@g0SG_<0uX=z1Rwwb2tWV=5J(070T$gf00000 literal 0 HcmV?d00001 diff --git a/src/pages/customer/List.tsx b/src/pages/customer/List.tsx index 7bb8eac..1d5f6ea 100644 --- a/src/pages/customer/List.tsx +++ b/src/pages/customer/List.tsx @@ -6,7 +6,6 @@ import Button from "../../components/Button"; import Input from "../../components/Input"; import PageLoading from "../../components/PageLoading"; import Pagination from "../../components/Pagination"; -import Select from "../../components/Select"; import Td from "../../components/Td"; import { Pages } from "../../config/Pages"; import { useGetCustomers } from "./hooks/useCustomerData"; @@ -16,7 +15,13 @@ const CustomerList: FC = () => { const { t } = useTranslation("global"); const [page, setPage] = useState(1); const [limit, setLimit] = useState(10); - const getCustomers = useGetCustomers(page, limit); + const [search, setSearch] = useState(""); + const getCustomers = useGetCustomers(page, limit, false, search); + + const handleSearch = (value: string) => { + setPage(1); + setSearch(value); + }; return (
@@ -35,32 +40,13 @@ const CustomerList: FC = () => {
-
-
- -
+
diff --git a/src/pages/customer/hooks/useCustomerData.ts b/src/pages/customer/hooks/useCustomerData.ts index 1deb715..28a6ccd 100644 --- a/src/pages/customer/hooks/useCustomerData.ts +++ b/src/pages/customer/hooks/useCustomerData.ts @@ -2,10 +2,10 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import * as api from "../service/CustomerService"; import { CreateCustomerType } from "../types/CustomerTypes"; -export const useGetCustomers = (page: number, limit: number, withoutPaginate?: boolean) => { +export const useGetCustomers = (page: number, limit: number, withoutPaginate?: boolean, search?: string) => { return useQuery({ - queryKey: ["customers", page, limit], - queryFn: () => api.getCustomers(page, limit, withoutPaginate), + queryKey: ["customers", page, limit, withoutPaginate, search], + queryFn: () => api.getCustomers(page, limit, withoutPaginate, search), }); }; diff --git a/src/pages/customer/service/CustomerService.ts b/src/pages/customer/service/CustomerService.ts index fdd9c45..b7ad634 100644 --- a/src/pages/customer/service/CustomerService.ts +++ b/src/pages/customer/service/CustomerService.ts @@ -1,8 +1,10 @@ import axios from "../../../config/axios"; import { CreateCustomerType } from "../types/CustomerTypes"; -export const getCustomers = async (page: number, limit: number, withoutPaginate?: boolean) => { - const { data } = await axios.get(`/users/customers?page=${page}&limit=${limit}&paginate=${withoutPaginate ? "0" : "1"}`); +export const getCustomers = async (page: number, limit: number, withoutPaginate?: boolean, search?: string) => { + const { data } = await axios.get( + `/users/customers?page=${page}&limit=${limit}&paginate=${withoutPaginate ? "0" : "1"}&q=${encodeURIComponent(search ?? "")}`, + ); return data; };