This commit is contained in:
2024-10-10 17:09:17 +05:30
parent 8a6d9102cb
commit 36cf9fa610
5 changed files with 45 additions and 11 deletions

View File

@@ -36,6 +36,7 @@ import RequestRejectModal from "./RequestRejectModal";
const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size);
const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page);
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState("");
const formatDate = (date) => {
return new Date(date).toLocaleDateString('en-GB', {
@@ -45,6 +46,16 @@ import RequestRejectModal from "./RequestRejectModal";
});
};
// Debounce the search term to avoid making a request on every keystroke
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedSearchTerm(searchTerm);
}, 500); // Adjust delay as needed
return () => {
clearTimeout(handler);
};
}, [searchTerm]);
const {
isOpen: isConfirmOpen,
onOpen: onConfirmOpen,
@@ -61,7 +72,16 @@ import RequestRejectModal from "./RequestRejectModal";
isLoading: drawalRequestLoading,
error,
refetch
} = useGetFawateerRequestQuery();
} = useGetFawateerRequestQuery(
{
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);
@@ -105,6 +125,7 @@ import RequestRejectModal from "./RequestRejectModal";
});
const role = localStorage?.getItem('role')
// ====================================================[Table Setup]================================================================
const tableHeadRow = [
"Sr.no",
@@ -115,7 +136,7 @@ import RequestRejectModal from "./RequestRejectModal";
"Phone Number",
"Transaction Date",
"Transaction Amount",
"Action",
role === "Checker"&&"Action",
];

View File

@@ -236,7 +236,13 @@ const Sponser = () => {
{/* ====================[Pagination]===================== */}
<Pagination isLoading={isSponserLoading} pageSize={pageSize} setPageSize={setPageSize} currentPage={currentPage} setCurrentPage={setCurrentPage} totalItems={sponsors?.data?.totalItems} />
<Pagination
isLoading={isSponserLoading}
pageSize={pageSize}
setPageSize={setPageSize}
currentPage={currentPage}
setCurrentPage={setCurrentPage}
totalItems={sponsors?.data?.totalItems} />
{/* =====================[Add Button]===================== */}

View File

@@ -110,7 +110,7 @@ export const nav = [
submenu: [
{
title: "Create Request",
path: "/fawateer-request",
path: "/fawateer",
icon: RiMoneyDollarBoxLine,
},
{
@@ -127,12 +127,12 @@ export const nav = [
submenu: [
{
title: "Pending Request",
path: "/fawateer-approver",
path: "/fawateer",
icon: RiMoneyDollarBoxLine,
},
{
title: "View History",
path: "/approver-history",
path: "/fawateer-history",
icon: RiExchangeBoxLine,
},
],

View File

@@ -119,12 +119,12 @@ export const RouteLink = [
// ===============[ fawateer ]===============
{ path: "/fawateer-history", Component: FawateerRequest },
{ path: "/fawateer-request", Component: CreateRequest },
{ path: "/fawateer", Component: localStorage.getItem("role") === "Maker"? CreateRequest:ApproveRequest },
{ path: "/fawateer-history", Component: localStorage.getItem("role") === "Maker"?ApproveRequest: ApproveHistory },
{ path: "/fawateer-approver", Component: ApproveRequest },
{ path: "/approver-history", Component: ApproveHistory },
// { path: "/fawateer-approver", Component: ApproveRequest },
// { path: "/approver-history", Component: ApproveHistory },

View File

@@ -12,8 +12,15 @@ export const fawateerRequest = createApi({
tagTypes: ["getFawateerRequest"],
endpoints: (builder) => ({
getFawateerRequest: builder.query({
query: () => `/fawateer/admin/Pending`,
query: ({ page, size, searchTerm }) => {
let baseURL = `/fawateer/admin/Pending?search_data=${searchTerm || ""}`;
if (page !== undefined && size !== undefined) {
baseURL += `&page=${page}&size=${size}`; // Only add pagination if both are defined
}
return baseURL;
},
providesTags: ["getFawateerRequest"],
}),