diff --git a/src/components/dashboards/ReviewTable.tsx b/src/components/dashboards/ReviewTable.tsx index 38cb924..b07ad63 100644 --- a/src/components/dashboards/ReviewTable.tsx +++ b/src/components/dashboards/ReviewTable.tsx @@ -18,9 +18,18 @@ import { DropdownMenuTrigger, } from "../ui/dropdown-menu"; import { useReviewTable } from "@/src/hooks/useReviewTable"; +import { + Pagination, + PaginationContent, + PaginationItem, + PaginationLink, + PaginationNext, + PaginationPrevious, +} from "../ui/pagination"; export function ReviewTable() { - const { data, isLoading } = useReviewTable(); + const { currentData, isLoading, pagination } = useReviewTable(10); + const { currentPage, totalPages, nextPage, prevPage, goToPage } = pagination; if (isLoading) { return ( @@ -47,7 +56,7 @@ export function ReviewTable() { - {data.length === 0 ? ( + {currentData.length === 0 ? (
@@ -64,7 +73,7 @@ export function ReviewTable() { ) : ( - data.map((review, index) => ( + currentData.map((review, index) => ( + + {totalPages > 1 && ( +
+ + + + { + e.preventDefault(); + prevPage(); + }} + className={ + currentPage === 1 + ? "pointer-events-none opacity-50" + : "cursor-pointer" + } + /> + + + {[...Array(totalPages)].map((_, i) => ( + + { + e.preventDefault(); + goToPage(i + 1); + }} + isActive={currentPage === i + 1} + > + {i + 1} + + + ))} + + + { + e.preventDefault(); + nextPage(); + }} + className={ + currentPage === totalPages + ? "pointer-events-none opacity-50" + : "cursor-pointer" + } + /> + + + +
+ )}
); } diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index b0f700b..fbe0fe7 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -13,7 +13,7 @@ const buttonVariants = cva( destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60", outline: - "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50", + "border bg-primary text-white", secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", ghost: diff --git a/src/components/ui/pagination.tsx b/src/components/ui/pagination.tsx new file mode 100644 index 0000000..ebba50f --- /dev/null +++ b/src/components/ui/pagination.tsx @@ -0,0 +1,127 @@ +import * as React from "react"; +import { + ChevronLeftIcon, + ChevronRightIcon, + MoreHorizontalIcon, +} from "lucide-react"; + +import { cn } from "@/lib/utils"; +import { Button, buttonVariants } from "./button"; + +function Pagination({ className, ...props }: React.ComponentProps<"nav">) { + return ( +