diff --git a/app/dashboard/invoices/page.tsx b/app/dashboard/invoices/page.tsx index 583f12f..f5f18d7 100644 --- a/app/dashboard/invoices/page.tsx +++ b/app/dashboard/invoices/page.tsx @@ -5,6 +5,7 @@ import { CreateInvoice } from '@/app/ui/invoices/buttons'; import { lusitana } from '@/app/ui/fonts'; import { InvoicesTableSkeleton } from '@/app/ui/skeletons'; import { Suspense } from 'react'; +import {fetchInvoicesPages} from "@/app/lib/data"; export default async function Page({ searchParams, @@ -15,7 +16,10 @@ export default async function Page({ }; }) { const query = searchParams?.query || ''; - const currentPage = Number(searchParams?.page) || 1; return ( + const currentPage = Number(searchParams?.page) || 1; + const totalPages = await fetchInvoicesPages(query); + + return (

Invoices

@@ -28,7 +32,7 @@ export default async function Page({
- {/* */} +
); diff --git a/app/ui/invoices/pagination.tsx b/app/ui/invoices/pagination.tsx index 1a29cce..da1a301 100644 --- a/app/ui/invoices/pagination.tsx +++ b/app/ui/invoices/pagination.tsx @@ -4,17 +4,27 @@ import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline'; import clsx from 'clsx'; import Link from 'next/link'; import { generatePagination } from '@/app/lib/utils'; +import { usePathname, useSearchParams } from 'next/navigation'; export default function Pagination({ totalPages }: { totalPages: number }) { // NOTE: comment in this code when you get to this point in the course + const pathname = usePathname(); + const searchParams = useSearchParams(); + const currentPage = Number(searchParams.get('page')) || 1; - // const allPages = generatePagination(currentPage, totalPages); + const createPageURL = (pageNumber: number | string) => { + const params = new URLSearchParams(searchParams); + params.set('page', pageNumber.toString()); + return `${pathname}?${params.toString()}`; + }; + + const allPages = generatePagination(currentPage, totalPages); return ( <> {/* NOTE: comment in this code when you get to this point in the course */} - {/*
+
= totalPages} /> -
*/} +
); }