From d40eadb35ee781f8019bd5ddaf0339a2a5fa1f3a Mon Sep 17 00:00:00 2001 From: YasinShaikh123 <123150391+YasinShaikh123@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:42:57 +0530 Subject: [PATCH] [ Approve Historty maker search ] --- .../ApproveHistory/ApproveHistoryChecker.jsx | 23 +++++++++++++++++-- .../ApproveHistory/ApproveHistoryMaker.jsx | 2 +- src/Services/fawateer.request.service.js | 15 ++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx index 58d792e..b1286e5 100644 --- a/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx +++ b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx @@ -37,6 +37,7 @@ const ApproveHistory = () => { const [actionId, setActionId] = useState(false); const [mouseEntered, setMouseEntered] = useState(false); const [mouseEnteredId, setMouseEnteredId] = useState(""); + const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(""); const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); @@ -65,7 +66,16 @@ const ApproveHistory = () => { isLoading: drawalRequestLoading, error, refetch, - } = useGetApproveHistoryQuery(); + } = useGetApproveHistoryQuery( + { + page: debouncedSearchTerm ? undefined : currentPage, // Omit pagination for search + size: debouncedSearchTerm ? undefined : pageSize, // Omit pagination for search + searchTerm: debouncedSearchTerm, + }, + { + skip: debouncedSearchTerm === "" && searchTerm !== "", // Skip if search is empty and it's not the initial request + } + ); console.log(data?.data?.rows); @@ -84,6 +94,15 @@ const ApproveHistory = () => { return () => clearTimeout(timer); }, []); + + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedSearchTerm(searchTerm); + }, 500); // Adjust delay as needed + return () => { + clearTimeout(handler); + }; + }, [searchTerm]); // ====================================================[Table Filter]================================================================ const filteredData = data?.data?.rows?.filter((item) => { // Filter by name (case insensitive) @@ -117,7 +136,7 @@ const ApproveHistory = () => { "Status", ]; - const extractedArray = filteredData?.map((item, idx) => ({ + const extractedArray = data?.data?.rows?.map((item, idx) => ({ // id: item?.id, "Sr.no": ( { skip: debouncedSearchTerm === "" && searchTerm !== "", // Skip if search is empty and it's not the initial request } ); - + useEffect(() => { const handler = setTimeout(() => { setDebouncedSearchTerm(searchTerm); diff --git a/src/Services/fawateer.request.service.js b/src/Services/fawateer.request.service.js index 1a5e90a..2d5a79c 100644 --- a/src/Services/fawateer.request.service.js +++ b/src/Services/fawateer.request.service.js @@ -50,8 +50,19 @@ export const fawateerRequest = createApi({ providesTags: ["getFawateerMakerRequest"], }), + // getApproveHistory: builder.query({ + // query: () => `/fawateer/admin/getAll`, + // providesTags: ["getApproveHistory"], + // }), + getApproveHistory: builder.query({ - query: () => `/fawateer/admin/getAll`, + query: ({ page, size, searchTerm }) => { + let baseURL = `/fawateer/admin/getAll?search=${searchTerm || ""}`; + if (page !== undefined && size !== undefined) { + baseURL += `&page=${page}&size=${size}`; // Only add pagination if both are defined + } + return baseURL; + }, providesTags: ["getApproveHistory"], }), @@ -72,7 +83,7 @@ export const fawateerRequest = createApi({ }), invalidatesTags: ["getFawateerRequest"], }), - + }), });