Implementing Get api.

This commit is contained in:
Kartik Sharma 2025-11-19 18:47:30 +05:30
parent e7a68aeab7
commit 7e4dffff34

View File

@ -22,12 +22,11 @@ const ServiceBranch = () => {
const { data, isLoading, isError, error } = useBranches( const { data, isLoading, isError, error } = useBranches(
projectId, projectId,
debouncedSearch || null, true,
null, ITEMS_PER_PAGE,
currentPage, currentPage,
ITEMS_PER_PAGE debouncedSearch,
); );
const paginate = (page) => { const paginate = (page) => {
if (page >= 1 && page <= (data?.totalPages ?? 1)) { if (page >= 1 && page <= (data?.totalPages ?? 1)) {
setCurrentPage(page); setCurrentPage(page);
@ -68,30 +67,38 @@ const ServiceBranch = () => {
<div className="mx-2"> <div className="mx-2">
{/* {Array.isArray(filteredData) && filteredData.length > 0 && ( */} {/* {Array.isArray(filteredData) && filteredData.length > 0 && ( */}
<table className="table border-top dataTable text-nowrap align-middle"> <table className="table border-top text-nowrap align-middle">
<thead> <thead>
<tr> <tr>
{ServiceBranch.map((col) => ( {ServiceBranch.map((col) => (
<th key={col.key} className={`sorting ${col.align}`}> <th key={col.key} className={col.align}>
{col.label} {col.label}
</th> </th>
))} ))}
<th className="text-center">Action</th> <th className="text-center">Action</th>
</tr> </tr>
</thead> </thead>
<tbody>
{/* <tbody>
{isLoading ? ( {isLoading ? (
<tr> <tr>
<td colSpan={ServiceBranch.length + 1} className="text-center py-5"> <td colSpan={ServiceBranch.length + 1} className="text-center py-5">
Loading... Loading...
</td> </td>
</tr> </tr>
) : isError ? (
<tr>
<td colSpan={ServiceBranch.length + 1} className="text-center py-5">
{error?.message || "Error loading branches"}
</td>
</tr>
) : data?.data?.length > 0 ? ( ) : data?.data?.length > 0 ? (
data.data.map((branch) => ( data.data.map((branch) => (
<tr key={branch.id} className="align-middle"> <tr key={branch.id}>
<td className="text-start">{branch.branchName}</td> {ServiceBranch.map((col) => (
<td key={col.key} className={col.align}>
{col.getValue(branch)}
</td>
))}
<td className="text-center"> <td className="text-center">
<i <i
className="bx bx-edit text-primary cursor-pointer" className="bx bx-edit text-primary cursor-pointer"
@ -101,7 +108,7 @@ const ServiceBranch = () => {
branchId: branch.id, branchId: branch.id,
}) })
} }
></i> />
</td> </td>
</tr> </tr>
)) ))
@ -112,9 +119,7 @@ const ServiceBranch = () => {
</td> </td>
</tr> </tr>
)} )}
</tbody> */} </tbody>
</table> </table>
{/* )} */} {/* )} */}
{/* {!filteredData || {/* {!filteredData ||