Chapter 13 - Handle specific error (not found in this case)
This commit is contained in:
18
app/dashboard/invoices/[id]/edit/not-found.tsx
Normal file
18
app/dashboard/invoices/[id]/edit/not-found.tsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import Link from 'next/link';
|
||||||
|
import { FaceFrownIcon } from '@heroicons/react/24/outline';
|
||||||
|
|
||||||
|
export default function NotFound() {
|
||||||
|
return (
|
||||||
|
<main className="flex h-full flex-col items-center justify-center gap-2">
|
||||||
|
<FaceFrownIcon className="w-10 text-gray-400" />
|
||||||
|
<h2 className="text-xl font-semibold">404 Not Found</h2>
|
||||||
|
<p>Could not find the requested invoice.</p>
|
||||||
|
<Link
|
||||||
|
href="/dashboard/invoices"
|
||||||
|
className="mt-4 rounded-md bg-blue-500 px-4 py-2 text-sm text-white transition-colors hover:bg-blue-400"
|
||||||
|
>
|
||||||
|
Go Back
|
||||||
|
</Link>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import Form from '@/app/ui/invoices/edit-form';
|
import Form from '@/app/ui/invoices/edit-form';
|
||||||
import Breadcrumbs from '@/app/ui/invoices/breadcrumbs';
|
import Breadcrumbs from '@/app/ui/invoices/breadcrumbs';
|
||||||
import {fetchCustomers, fetchInvoiceById} from '@/app/lib/data';
|
import {fetchCustomers, fetchInvoiceById} from '@/app/lib/data';
|
||||||
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { id: string } }) {
|
export default async function Page({ params }: { params: { id: string } }) {
|
||||||
const id = params.id;
|
const id = params.id;
|
||||||
@@ -8,6 +9,10 @@ export default async function Page({ params }: { params: { id: string } }) {
|
|||||||
fetchInvoiceById(id),
|
fetchInvoiceById(id),
|
||||||
fetchCustomers(),
|
fetchCustomers(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!invoice) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ export async function fetchInvoiceById(id: string) {
|
|||||||
amount: invoice.amount / 100,
|
amount: invoice.amount / 100,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
console.log(invoice);
|
||||||
return invoice[0];
|
return invoice[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Database Error:', error);
|
console.error('Database Error:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user