forked from adrianhajdin/banking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPagination.tsx
64 lines (57 loc) · 1.57 KB
/
Pagination.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use client";
import Image from "next/image";
import { useRouter, useSearchParams } from "next/navigation";
import { Button } from "@/components/ui/button";
import { formUrlQuery } from "@/lib/utils";
export const Pagination = ({ page, totalPages }: PaginationProps) => {
const router = useRouter();
const searchParams = useSearchParams()!;
const handleNavigation = (type: "prev" | "next") => {
const pageNumber = type === "prev" ? page - 1 : page + 1;
const newUrl = formUrlQuery({
params: searchParams.toString(),
key: "page",
value: pageNumber.toString(),
});
router.push(newUrl, { scroll: false });
};
return (
<div className="flex justify-between gap-3">
<Button
size="lg"
variant="ghost"
className="p-0 hover:bg-transparent"
onClick={() => handleNavigation("prev")}
disabled={Number(page) <= 1}
>
<Image
src="/icons/arrow-left.svg"
alt="arrow"
width={20}
height={20}
className="mr-2"
/>
Prev
</Button>
<p className="text-14 flex items-center px-2">
{page} / {totalPages}
</p>
<Button
size="lg"
variant="ghost"
className="p-0 hover:bg-transparent"
onClick={() => handleNavigation("next")}
disabled={Number(page) >= totalPages}
>
Next
<Image
src="/icons/arrow-left.svg"
alt="arrow"
width={20}
height={20}
className="ml-2 -scale-x-100"
/>
</Button>
</div>
);
};