feat(getPageNumber - fixed and applied)

This commit is contained in:
2025-10-30 21:12:50 +05:30
parent 9232e8f654
commit 103142b2d3
4 changed files with 11 additions and 62 deletions

View File

@@ -35,6 +35,7 @@ import { formatDateToHumanReadable } from "@/utils/dateUtils";
import ClaimViewModal from "./claim-view-modal";
import ClaimEditModal from "./claim-edit-modal";
import { Claim, ClaimStatus, ClaimWithServiceLines } from "@repo/db/types";
import { getPageNumbers } from "@/utils/pageNumberGenerator";
interface ClaimApiResponse {
claims: ClaimWithServiceLines[];
@@ -294,25 +295,6 @@ export default function ClaimsRecentTable({
);
};
function getPageNumbers(current: number, total: number): (number | "...")[] {
const delta = 2;
const range: (number | "...")[] = [];
const left = Math.max(2, current - delta);
const right = Math.min(total - 1, current + delta);
range.push(1);
if (left > 2) range.push("...");
for (let i = left; i <= right; i++) {
range.push(i);
}
if (right < total - 1) range.push("...");
if (total > 1) range.push(total);
return range;
}
return (
<div className="bg-white shadow rounded-lg overflow-hidden">
<div className="overflow-x-auto">

View File

@@ -43,6 +43,7 @@ import {
import EditPaymentModal from "./payment-edit-modal";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { ConfirmationDialog } from "../ui/confirmationDialog";
import { getPageNumbers } from "@/utils/pageNumberGenerator";
interface PaymentApiResponse {
payments: PaymentWithExtras[];
@@ -474,25 +475,6 @@ export default function PaymentsRecentTable({
}
};
function getPageNumbers(current: number, total: number): (number | "...")[] {
const delta = 2;
const range: (number | "...")[] = [];
const left = Math.max(2, current - delta);
const right = Math.min(total - 1, current + delta);
range.push(1);
if (left > 2) range.push("...");
for (let i = left; i <= right; i++) {
range.push(i);
}
if (right < total - 1) range.push("...");
if (total > 1) range.push(total);
return range;
}
return (
<div className="bg-white shadow rounded-lg overflow-hidden">
<div className="overflow-x-auto">

View File

@@ -23,6 +23,7 @@ import {
PaginationPrevious,
} from "@/components/ui/pagination";
import DocumentsFilePreviewModal from "@/components/documents/file-preview-modal";
import { getPageNumbers } from "@/utils/pageNumberGenerator";
export default function DocumentsPage() {
const [selectedPatient, setSelectedPatient] = useState<Patient | null>(null);
@@ -205,23 +206,6 @@ export default function DocumentsPage() {
? Math.min(offset + limit, totalForExpandedGroup)
: 0;
function getPageNumbers(current: number, total: number) {
const delta = 2;
const range: (number | "...")[] = [];
for (
let i = Math.max(2, current - delta);
i <= Math.min(total - 1, current + delta);
i++
) {
range.push(i);
}
if (current - delta > 2) range.unshift("...");
if (current + delta < total - 1) range.push("...");
range.unshift(1);
if (total > 1) range.push(total);
return range;
}
return (
<div>
<div className="container mx-auto space-y-6">

View File

@@ -5,16 +5,17 @@ export function getPageNumbers(current: number, total: number, maxButtons = 7) {
return pages;
}
const half = Math.floor(maxButtons / 2);
let start = Math.max(1, current - half);
let end = Math.min(total, current + half);
const delta = 2;
const start = Math.max(2, current - delta);
const end = Math.min(total - 1, current + delta);
if (start === 1) end = Math.min(total, maxButtons);
if (end === total) start = Math.max(1, total - maxButtons + 1);
pages.push(1);
if (start > 2) pages.push("...");
if (start > 1) pages.push(1, "...");
for (let i = start; i <= end; i++) pages.push(i);
if (end < total) pages.push("...", total);
if (end < total - 1) pages.push("...");
if (total > 1) pages.push(total);
return pages;
}