From d2d071c1cee8d8e1302ad860f27f15b28213e44f Mon Sep 17 00:00:00 2001 From: Delba de Oliveira Date: Tue, 10 Oct 2023 14:52:07 +0100 Subject: [PATCH 1/3] Move breadcrumbs up to page --- .../app/dashboard/invoices/[id]/edit/page.tsx | 11 +++++++++++ .../app/dashboard/invoices/create/page.tsx | 11 +++++++++++ .../15-final/app/dashboard/invoices/page.tsx | 3 ++- .../15-final/app/ui/invoices/create-form.tsx | 17 +++-------------- .../15-final/app/ui/invoices/edit-form.tsx | 19 +++---------------- .../15-final/app/ui/invoices/pagination.tsx | 3 ++- dashboard/15-final/app/ui/search.tsx | 1 + 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx b/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx index c02654ef..da937fa8 100644 --- a/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx +++ b/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx @@ -1,6 +1,7 @@ import { fetchInvoiceById, fetchCustomerNames } from '@/app/lib/data'; import { notFound } from 'next/navigation'; import Form from '@/app/ui/invoices/edit-form'; +import { Breadcrumbs } from '@/app/ui/invoices/breadcrumbs'; export default async function Page({ params }: { params: { id: string } }) { const id = params.id; @@ -13,6 +14,16 @@ export default async function Page({ params }: { params: { id: string } }) { return (
+
); diff --git a/dashboard/15-final/app/dashboard/invoices/create/page.tsx b/dashboard/15-final/app/dashboard/invoices/create/page.tsx index b50595f1..a0cc4a75 100644 --- a/dashboard/15-final/app/dashboard/invoices/create/page.tsx +++ b/dashboard/15-final/app/dashboard/invoices/create/page.tsx @@ -1,11 +1,22 @@ import { fetchCustomerNames } from '@/app/lib/data'; import Form from '@/app/ui/invoices/create-form'; +import { Breadcrumbs } from '@/app/ui/invoices/breadcrumbs'; export default async function Page() { const customerNames = await fetchCustomerNames(); return (
+
); diff --git a/dashboard/15-final/app/dashboard/invoices/page.tsx b/dashboard/15-final/app/dashboard/invoices/page.tsx index fd35c3f9..1f4dca15 100644 --- a/dashboard/15-final/app/dashboard/invoices/page.tsx +++ b/dashboard/15-final/app/dashboard/invoices/page.tsx @@ -1,7 +1,7 @@ import Pagination from '@/app/ui/invoices/pagination'; import Search from '@/app/ui/search'; -import { CreateInvoice } from '@/app/ui/invoices/buttons'; 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/dashboard/skeletons'; import { Suspense } from 'react'; @@ -17,6 +17,7 @@ export default async function Page({ }) { const query = searchParams?.query || ''; const currentPage = Number(searchParams?.page) || 1; + const totalPages = await fetchInvoicesPages(query); return ( diff --git a/dashboard/15-final/app/ui/invoices/create-form.tsx b/dashboard/15-final/app/ui/invoices/create-form.tsx index c57af692..7900b43a 100644 --- a/dashboard/15-final/app/ui/invoices/create-form.tsx +++ b/dashboard/15-final/app/ui/invoices/create-form.tsx @@ -1,10 +1,7 @@ 'use client'; -import { createInvoice } from '@/app/lib/actions'; import { CustomerName } from '@/app/lib/definitions'; import Link from 'next/link'; -// @ts-ignore React types do not yet include useFormState -import { experimental_useFormState as useFormState } from 'react-dom'; import { CheckIcon, ClockIcon, @@ -12,7 +9,9 @@ import { UserCircleIcon, } from '@heroicons/react/24/outline'; import { Button } from '../button'; -import { Breadcrumbs } from './breadcrumbs'; +import { createInvoice } from '@/app/lib/actions'; +// @ts-ignore React types do not yet include useFormState +import { experimental_useFormState as useFormState } from 'react-dom'; export default function Form({ customerNames, @@ -24,16 +23,6 @@ export default function Form({ return (
-
{/* Customer Name */} diff --git a/dashboard/15-final/app/ui/invoices/edit-form.tsx b/dashboard/15-final/app/ui/invoices/edit-form.tsx index 2776335c..60e7d640 100644 --- a/dashboard/15-final/app/ui/invoices/edit-form.tsx +++ b/dashboard/15-final/app/ui/invoices/edit-form.tsx @@ -1,12 +1,7 @@ 'use client'; import { CustomerName, InvoiceForm } from '@/app/lib/definitions'; -import { updateInvoice } from '@/app/lib/actions'; -// @ts-ignore React types do not yet include useFormState -import { experimental_useFormState as useFormState } from 'react-dom'; import Link from 'next/link'; -import { lusitana } from '@/app/ui/fonts'; -import { clsx } from 'clsx'; import { CheckIcon, ClockIcon, @@ -14,7 +9,9 @@ import { UserCircleIcon, } from '@heroicons/react/24/outline'; import { Button } from '../button'; -import { Breadcrumbs } from './breadcrumbs'; +import { updateInvoice } from '@/app/lib/actions'; +// @ts-ignore React types do not yet include useFormState +import { experimental_useFormState as useFormState } from 'react-dom'; export default function EditInvoiceForm({ id, @@ -30,16 +27,6 @@ export default function EditInvoiceForm({ return (
-
{/* Customer Name */} diff --git a/dashboard/15-final/app/ui/invoices/pagination.tsx b/dashboard/15-final/app/ui/invoices/pagination.tsx index e9d0293a..20303319 100644 --- a/dashboard/15-final/app/ui/invoices/pagination.tsx +++ b/dashboard/15-final/app/ui/invoices/pagination.tsx @@ -10,7 +10,6 @@ export default function Pagination({ totalPages }: { totalPages: number }) { 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); @@ -18,6 +17,8 @@ export default function Pagination({ totalPages }: { totalPages: number }) { return `${pathname}?${params.toString()}`; }; + const allPages = generatePagination(currentPage, totalPages); + return (
Date: Tue, 10 Oct 2023 14:59:13 +0100 Subject: [PATCH 2/3] Use default exports --- .../15-final/app/dashboard/invoices/[id]/edit/page.tsx | 2 +- dashboard/15-final/app/dashboard/invoices/create/page.tsx | 2 +- dashboard/15-final/app/ui/invoices/breadcrumbs.tsx | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx b/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx index da937fa8..35299610 100644 --- a/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx +++ b/dashboard/15-final/app/dashboard/invoices/[id]/edit/page.tsx @@ -1,7 +1,7 @@ import { fetchInvoiceById, fetchCustomerNames } from '@/app/lib/data'; import { notFound } from 'next/navigation'; import Form from '@/app/ui/invoices/edit-form'; -import { Breadcrumbs } from '@/app/ui/invoices/breadcrumbs'; +import Breadcrumbs from '@/app/ui/invoices/breadcrumbs'; export default async function Page({ params }: { params: { id: string } }) { const id = params.id; diff --git a/dashboard/15-final/app/dashboard/invoices/create/page.tsx b/dashboard/15-final/app/dashboard/invoices/create/page.tsx index a0cc4a75..3d036cc6 100644 --- a/dashboard/15-final/app/dashboard/invoices/create/page.tsx +++ b/dashboard/15-final/app/dashboard/invoices/create/page.tsx @@ -1,6 +1,6 @@ import { fetchCustomerNames } from '@/app/lib/data'; import Form from '@/app/ui/invoices/create-form'; -import { Breadcrumbs } from '@/app/ui/invoices/breadcrumbs'; +import Breadcrumbs from '@/app/ui/invoices/breadcrumbs'; export default async function Page() { const customerNames = await fetchCustomerNames(); diff --git a/dashboard/15-final/app/ui/invoices/breadcrumbs.tsx b/dashboard/15-final/app/ui/invoices/breadcrumbs.tsx index 50779a69..cd9e2265 100644 --- a/dashboard/15-final/app/ui/invoices/breadcrumbs.tsx +++ b/dashboard/15-final/app/ui/invoices/breadcrumbs.tsx @@ -8,7 +8,11 @@ interface Breadcrumb { active?: boolean; } -export function Breadcrumbs({ breadcrumbs }: { breadcrumbs: Breadcrumb[] }) { +export default function Breadcrumbs({ + breadcrumbs, +}: { + breadcrumbs: Breadcrumb[]; +}) { return (