Files
tm_panel/src/components/Tables/tenders/index.tsx
T
AmirReza Jamali fc53d6b556 feat(pagination): implement windowed pagination for improved navigation
- Introduced windowed pagination logic in the TendersTable component to enhance user experience by allowing for a more manageable view of pages.
- Updated the pagination component to accept new props for page range and margin pages, enabling customizable pagination display.
- Refactored the useTenderListPresenter to utilize the new windowed pagination functionality, improving clarity and maintainability of pagination handling.
2026-05-18 15:28:07 +03:30

171 lines
5.9 KiB
TypeScript

"use client";
import { ExclamationIcon, EyeIcon } from "@/assets/icons";
import EmptyListWrapper from "@/components/HOC/EmptyListWrapper";
import Status from "@/components/ui/Status";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import IsVisible from "@/components/ui/IsVisible";
import ListHeader from "@/components/ui/ListHeader";
import ListWrapper from "@/components/ui/ListWrapper";
import Pagination from "@/components/ui/pagination";
import TableSkeleton from "@/components/ui/TableSkeleton";
import { _TooltipDefaultParams } from "@/constants/tooltip";
import { cn } from "@/lib/utils";
import { Tooltip } from "react-tooltip";
import TenderListFilters from "./TenderListFilters";
import useTenderListPresenter from "./useTenderListPresenter";
const TendersTable = () => {
const {
columns,
filterRegister,
handleFilterSubmit,
search,
watch,
setFilterValue,
control,
isMutating,
shouldShowPagination,
clearAllFilters,
tableSectionRef,
skeletonTbodyRef,
dataTbodyRef,
tendersList,
isPending,
navigateToTenderDetails,
navigateToTenderFeedback,
handlePaginationChange,
buildWindowedPageLabel,
getRowNumber,
formatDateTimeCell,
pagination,
} = useTenderListPresenter();
return (
<ListWrapper>
<ListHeader
hasFilter={false}
createButtonText="Create Tender"
hasCreate={false}
/>
<TenderListFilters
setValue={setFilterValue}
filterRegister={filterRegister}
control={control}
handleFilterSubmit={handleFilterSubmit}
isMutating={isMutating as number}
search={search}
watch={watch}
onClearAll={clearAllFilters}
/>
<div ref={tableSectionRef}>
<Table>
<TableHeader>
<TableRow className="border-none uppercase [&>th]:text-start">
{columns.map((column) => (
<TableHead key={column} colSpan={100}>
{column}
</TableHead>
))}
</TableRow>
</TableHeader>
{isPending ? (
<TableSkeleton ref={skeletonTbodyRef} column={columns.length} />
) : (
<TableBody ref={dataTbodyRef}>
<EmptyListWrapper
list={tendersList}
columns={columns}
emptyMessage="No tenders were found"
isLoading={false}
>
{tendersList.map((item, index) => (
<TableRow
key={item.id}
className="odd:bg-gray-2 dark:odd:bg-gray-7"
>
<TableCell className="text-start" colSpan={100}>
{getRowNumber(index)}
</TableCell>
<TableCell className="text-start" colSpan={100}>
{item.title}
</TableCell>
<TableCell className="text-start" colSpan={100}>
{item.country_code}
</TableCell>
<TableCell className="text-start" colSpan={100}>
{formatDateTimeCell(item.publication_date)}
</TableCell>
<TableCell className="text-start" colSpan={100}>
{formatDateTimeCell(item.submission_deadline)}
</TableCell>
<TableCell className="text-start" colSpan={100}>
{formatDateTimeCell(item.tender_deadline)}
</TableCell>
<TableCell className="text-start" colSpan={100}>
{formatDateTimeCell(item?.created_at ?? 0)}
</TableCell>
<TableCell className={cn(`text capitalize`)} colSpan={100}>
<Status status={item.status}>{item.status}</Status>
</TableCell>
<TableCell className="capitalize" colSpan={100}>
<div className="flex items-center gap-2">
<button
type="button"
data-tooltip-id="details"
data-tooltip-content="Details"
data-tooltip-place="top"
onClick={() => navigateToTenderDetails(item.id)}
>
<Tooltip
{..._TooltipDefaultParams({
id: "details",
})}
/>
<EyeIcon />
</button>
<button
type="button"
data-tooltip-id="feedback"
data-tooltip-content="Feedback"
data-tooltip-place="top"
className="text-gray-40 rounded-full bg-gray-dark bg-opacity-5 hover:text-green-dark dark:bg-gray dark:bg-opacity-5"
onClick={() => navigateToTenderFeedback(item.id)}
>
<Tooltip {..._TooltipDefaultParams({ id: "feedback" })} />
<ExclamationIcon />
</button>
</div>
</TableCell>
</TableRow>
))}
</EmptyListWrapper>
</TableBody>
)}
</Table>
</div>
<IsVisible condition={shouldShowPagination}>
<Pagination
currentPage={pagination.currentPage}
totalPages={pagination.totalPages}
onPageChange={handlePaginationChange}
pageRangeDisplayed={3}
marginPagesDisplayed={1}
pageLabelBuilder={buildWindowedPageLabel}
/>
</IsVisible>
</ListWrapper>
);
};
export default TendersTable;