* feat: implement standard pagination for org member list * fix type error * i18n for pagination * add paginationMode * apply the change to PlatformManagedUsersTable * replace useInfiniteQuery with useQuery * fix type error * fix type error * fix type error * fix type error * update comment * remove optimistic update * minor changes * update usage on nuqs --------- Co-authored-by: Benny Joo <sldisek783@gmail.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { type Table } from "@tanstack/react-table";
|
|
|
|
import { Pagination } from "@calcom/ui";
|
|
|
|
import { useDataTable } from "../hooks";
|
|
|
|
interface DataTablePaginationProps<TData> {
|
|
table: Table<TData>;
|
|
totalRowCount: number;
|
|
paginationMode?: "infinite" | "standard";
|
|
}
|
|
|
|
export function DataTablePagination<TData>({
|
|
table,
|
|
totalRowCount,
|
|
paginationMode = "infinite",
|
|
}: DataTablePaginationProps<TData>) {
|
|
const { pageIndex, pageSize, setPageIndex, setPageSize } = useDataTable();
|
|
|
|
if (paginationMode === "infinite") {
|
|
const loadedCount = table.getFilteredRowModel().rows.length;
|
|
return (
|
|
<p className="text-subtle text-sm tabular-nums">
|
|
Loaded <span className="text-default font-medium">{loadedCount}</span> of{" "}
|
|
<span className="text-default font-medium">{totalRowCount}</span>
|
|
</p>
|
|
);
|
|
} else if (paginationMode === "standard") {
|
|
return (
|
|
<Pagination
|
|
currentPage={pageIndex + 1}
|
|
pageSize={pageSize}
|
|
totalItems={totalRowCount}
|
|
onPageChange={(page) => setPageIndex(page - 1)}
|
|
onPageSizeChange={(newSize) => setPageSize(newSize)}
|
|
onNext={() => setPageIndex(pageIndex + 1)}
|
|
onPrevious={() => setPageIndex(pageIndex - 1)}
|
|
/>
|
|
);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|