From 295d466cc4b745e3fb589d5e0f7409edfe094083 Mon Sep 17 00:00:00 2001 From: Nifemi Ogunmesa <95006475+Nogunmesa@users.noreply.github.com> Date: Wed, 14 May 2025 22:11:27 +0000 Subject: [PATCH 1/2] Edit button pushes to database, but it doesn't fully prefill --- frontend/src/app/dashboard/calendar/page.tsx | 34 +++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/dashboard/calendar/page.tsx b/frontend/src/app/dashboard/calendar/page.tsx index aef66f6b..44455fb3 100644 --- a/frontend/src/app/dashboard/calendar/page.tsx +++ b/frontend/src/app/dashboard/calendar/page.tsx @@ -271,6 +271,7 @@ export default function Home() { } } + async function handleDelete() { console.log('handleDelete called for event: ', idToDelete); @@ -326,6 +327,26 @@ export default function Home() { return; } + if (newEvent.id) { + // Editing an existing event + axios + .put(`${backendBaseUrl}/api/calendar/events/id/${newEvent.id}`, newEvent) + .then((response) => { + console.log('Successfully updated event:', response.data); + + // Update the event in the local state + setAllEvents( + allEvents.map((event) => + event.id === newEvent.id ? { ...event, ...newEvent } : event + ) + ); + }) + .catch((error) => { + console.error('Error updating event:', error); + }); + } else { + // Creating a new event + const eventWithUser: UserEvent & { start: Date; end?: Date; @@ -383,7 +404,7 @@ export default function Home() { .catch((error) => { console.error('Error saving event:', error); }); - + } setShowModal(false); setNewEvent({ ...example, @@ -602,6 +623,17 @@ export default function Home() {