From b73c9311f54869520276cd1396cdf55a2cc05182 Mon Sep 17 00:00:00 2001 From: "Federico Pasqua (eisterman)" Date: Tue, 1 Apr 2025 17:58:39 +0200 Subject: [PATCH] Complete "Updating Contacts with FormData" --- .../(sidebar)/contacts/[contactId]/edit/page.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx b/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx index ce2068c..3801c6b 100644 --- a/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx +++ b/src/app/(sidebar)/contacts/[contactId]/edit/page.tsx @@ -1,8 +1,16 @@ import Form from "next/form"; import { fetchContact } from "@/app/(sidebar)/loaders"; -import { notFound } from "next/navigation"; +import { notFound, redirect } from "next/navigation"; +import { updateContact } from "@/app/data"; +async function editContact(contactId: string, formData: FormData) { + "use server"; + const updates = Object.fromEntries(formData); + await updateContact(contactId, updates); + redirect(`/contacts/${contactId}`); +} + export default async function EditContactPage({ params }: { @@ -13,9 +21,10 @@ export default async function EditContactPage({ if (c === null) notFound(); return c; }); + const editThisContact = editContact.bind(null, contactId); return ( -
+

Name