[ Approve Historty maker search ]
This commit is contained in:
@@ -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": (
|
||||
<Text
|
||||
|
||||
@@ -92,7 +92,7 @@ const ApproveHistoryMaker = () => {
|
||||
skip: debouncedSearchTerm === "" && searchTerm !== "", // Skip if search is empty and it's not the initial request
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedSearchTerm(searchTerm);
|
||||
|
||||
@@ -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"],
|
||||
}),
|
||||
|
||||
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user