From aa81948f29b302ef2a95fc4f1c2c7311cb6298c1 Mon Sep 17 00:00:00 2001 From: "Federico Pasqua (eisterman)" Date: Tue, 1 Apr 2025 17:14:43 +0200 Subject: [PATCH] Edit Contact but without loading? --- .../contacts/[contactId]/Contact.tsx | 11 ++- .../contacts/[contactId]/edit/loading.tsx | 5 ++ .../contacts/[contactId]/edit/page.tsx | 69 +++++++++++++++++++ .../(sidebar)/contacts/[contactId]/page.tsx | 4 +- src/app/(sidebar)/layout.tsx | 5 +- src/app/(sidebar)/loaders.ts | 10 +++ 6 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 src/app/(sidebar)/contacts/[contactId]/edit/loading.tsx create mode 100644 src/app/(sidebar)/contacts/[contactId]/edit/page.tsx create mode 100644 src/app/(sidebar)/loaders.ts diff --git a/src/app/(sidebar)/contacts/[contactId]/Contact.tsx b/src/app/(sidebar)/contacts/[contactId]/Contact.tsx index e54c418..edd5764 100644 --- a/src/app/(sidebar)/contacts/[contactId]/Contact.tsx +++ b/src/app/(sidebar)/contacts/[contactId]/Contact.tsx @@ -3,6 +3,7 @@ import { ContactRecord } from "@/app/data"; import Form from "next/form"; import { use } from "react"; +import { useRouter } from "next/navigation"; export default function Contact({ contact @@ -10,6 +11,7 @@ export default function Contact({ contact: Promise }) { const c = use(contact); + const router = useRouter(); return (
@@ -47,9 +49,12 @@ export default function Contact({ {c.notes ?

{c.notes}

: null}
-
- -
+
Loading Edit Contact...
+ ); +} \ No newline at end of file diff --git a/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx b/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx new file mode 100644 index 0000000..ce2068c --- /dev/null +++ b/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx @@ -0,0 +1,69 @@ +import Form from "next/form"; +import { fetchContact } from "@/app/(sidebar)/loaders"; +import { notFound } from "next/navigation"; + + +export default async function EditContactPage({ + params +}: { + params: Promise<{ contactId: string }> +}) { + const { contactId } = await params; + const contact = await fetchContact(contactId).then((c) => { + if (c === null) notFound(); + return c; + }); + + return ( + +

+ Name + + +

+ + +