fix: pagination in PaymentsTable and TopupsTable components 🐛
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 7m35s

This commit is contained in:
2025-07-08 22:39:59 +05:00
parent fa12cd74d7
commit 783d4b360d
4 changed files with 33 additions and 27 deletions

View File

@ -52,7 +52,6 @@ export async function DevicesTable({
}
apiParams.limit = limit;
apiParams.offset = offset;
console.log("API Params:", apiParams);
const [error, devices] = await tryCatch(
getDevices(apiParams),
);

View File

@ -28,12 +28,17 @@ export async function PaymentsTable({
}>;
}) {
const resolvedParams = await searchParams;
const page = Number.parseInt(resolvedParams.page as string) || 1;
const limit = 10;
const offset = (page - 1) * limit;
const apiParams: Record<string, string | number | undefined> = {};
for (const [key, value] of Object.entries(resolvedParams)) {
if (value !== undefined && value !== "") {
apiParams[key] = typeof value === "number" ? value : String(value);
}
}
apiParams.limit = limit;
apiParams.offset = offset;
const [error, payments] = await tryCatch(getPayments(apiParams));
if (error) {
@ -166,7 +171,7 @@ export async function PaymentsTable({
</TableFooter>
</Table>
<Pagination
totalPages={meta.total / meta.per_page}
totalPages={meta.last_page}
currentPage={meta.current_page}
/>
</div>

View File

@ -27,7 +27,9 @@ export async function TopupsTable({
}>;
}) {
const resolvedParams = await searchParams;
const page = Number.parseInt(resolvedParams.page as string) || 1;
const limit = 10;
const offset = (page - 1) * limit;
// Build params object
const apiParams: Record<string, string | number | undefined> = {};
for (const [key, value] of Object.entries(resolvedParams)) {
@ -35,7 +37,8 @@ export async function TopupsTable({
apiParams[key] = typeof value === "number" ? value : String(value);
}
}
apiParams.limit = limit;
apiParams.offset = offset;
const [error, topups] = await tryCatch(getTopups(apiParams));
if (error) {
@ -151,8 +154,8 @@ export async function TopupsTable({
))}
</div>
<Pagination
totalPages={meta.total / meta.per_page}
currentPage={meta.current_page}
totalPages={meta?.last_page}
currentPage={meta?.current_page}
/>
</>
)}