diff --git a/.pnpm-store/v11/index.db b/.pnpm-store/v11/index.db new file mode 100644 index 0000000..7f9770b Binary files /dev/null and b/.pnpm-store/v11/index.db differ 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; };