From 500928c71938cab66ee8d89b634f81aa523626fe Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Wed, 3 Jan 2024 08:44:19 +0100 Subject: [PATCH] Chapter 11 - Implement invoice search --- app/dashboard/invoices/page.tsx | 36 +++++++++++++++++++++++++++++++-- app/ui/search.tsx | 18 +++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/dashboard/invoices/page.tsx b/app/dashboard/invoices/page.tsx index 702e489..583f12f 100644 --- a/app/dashboard/invoices/page.tsx +++ b/app/dashboard/invoices/page.tsx @@ -1,3 +1,35 @@ -export default function InvoicesPage() { - return

Invoices page

+import Pagination from '@/app/ui/invoices/pagination'; +import Search from '@/app/ui/search'; +import Table from '@/app/ui/invoices/table'; +import { CreateInvoice } from '@/app/ui/invoices/buttons'; +import { lusitana } from '@/app/ui/fonts'; +import { InvoicesTableSkeleton } from '@/app/ui/skeletons'; +import { Suspense } from 'react'; + +export default async function Page({ + searchParams, + }: { + searchParams?: { + query?: string; + page?: string; + }; +}) { + const query = searchParams?.query || ''; + const currentPage = Number(searchParams?.page) || 1; return ( +
+
+

Invoices

+
+
+ + +
+ }> + + +
+ {/* */} +
+ + ); } \ No newline at end of file diff --git a/app/ui/search.tsx b/app/ui/search.tsx index e6e9391..757722e 100644 --- a/app/ui/search.tsx +++ b/app/ui/search.tsx @@ -1,8 +1,22 @@ 'use client'; import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'; +import {usePathname, useRouter, useSearchParams} from "next/navigation"; export default function Search({ placeholder }: { placeholder: string }) { + const searchParams = useSearchParams(); + const pathname = usePathname(); + const { replace } = useRouter(); + function handleSearch(term: string) { + const params = new URLSearchParams(searchParams); + if (term) { + params.set('query', term); + } else { + params.delete('query'); + } + + replace(`${pathname}?${params.toString()}`); + } return (