From 82a99f02ca5be4428647058413cde5f24f958e23 Mon Sep 17 00:00:00 2001 From: Starstrike Date: Thu, 1 May 2025 16:57:06 -0400 Subject: [PATCH] Fix RSVP update persistence: include event_id and add better error handling --- frontend/src/components/EventAdmin.tsx | 31 +++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/EventAdmin.tsx b/frontend/src/components/EventAdmin.tsx index 3f9e639..4c6aeb4 100644 --- a/frontend/src/components/EventAdmin.tsx +++ b/frontend/src/components/EventAdmin.tsx @@ -231,35 +231,42 @@ const EventAdmin: React.FC = () => { }; const handleEditSubmit = async () => { - if (!rsvpToEdit) return; + if (!rsvpToEdit || !event) return; try { // Prepare submission data in the exact format the backend expects const submissionData = { + id: rsvpToEdit.id, + event_id: event.id, // Include the event ID name: editForm.name, attending: editForm.attending, bringing_guests: editForm.bringing_guests, guest_count: parseInt(editForm.guest_count.toString(), 10), guest_names: editForm.guest_names, - items_bringing: JSON.stringify(editForm.items_bringing) + items_bringing: JSON.stringify(editForm.items_bringing), + created_at: rsvpToEdit.created_at, // Preserve original creation timestamp + updated_at: new Date().toISOString() // Update the timestamp }; // Log the data being sent for debugging console.log('Submitting RSVP update:', submissionData); + // First try to get the current RSVP to verify it exists + const currentRsvp = await axios.get(`/api/events/${slug}/rsvps/${rsvpToEdit.id}`); + console.log('Current RSVP:', currentRsvp.data); + const response = await axios.put(`/api/events/${slug}/rsvps/${rsvpToEdit.id}`, submissionData); // Log the response for debugging console.log('Server response:', response.data); + if (!response.data) { + throw new Error('Server returned empty response'); + } + // Create updated RSVP object preserving the ID and merging with response data const updatedRsvp: RSVP = { - id: rsvpToEdit.id, - name: editForm.name, - attending: editForm.attending, - bringing_guests: editForm.bringing_guests, - guest_count: parseInt(editForm.guest_count.toString(), 10), - guest_names: editForm.guest_names, + ...submissionData, items_bringing: editForm.items_bringing // Keep as array in local state }; @@ -324,10 +331,18 @@ const EventAdmin: React.FC = () => { if (!verifiedRsvp) { console.error('RSVP update did not persist:', rsvpToEdit.id); setError('Warning: The update may not have been saved properly. Please refresh the page to verify.'); + + // Log additional debug information + console.log('Original RSVP:', rsvpToEdit); + console.log('Event details:', event); + console.log('Edit form data:', editForm); } } catch (error) { console.error('Failed to update RSVP:', error); + if (axios.isAxiosError(error)) { + console.error('Server error response:', error.response?.data); + } setError('Failed to update RSVP'); } };