diff --git a/frontend/src/components/RSVPForm.tsx b/frontend/src/components/RSVPForm.tsx index d672bac..69c0543 100644 --- a/frontend/src/components/RSVPForm.tsx +++ b/frontend/src/components/RSVPForm.tsx @@ -140,7 +140,7 @@ const RSVPForm: React.FC = () => { try { const submissionData = { ...formData, - items_bringing: JSON.stringify(formData.items_bringing) + items_bringing: formData.items_bringing }; const response = await axios.post(`/api/events/${slug}/rsvp`, submissionData); @@ -198,6 +198,7 @@ const RSVPForm: React.FC = () => { setClaimedItems(Array.from(claimed)); setSuccess(true); } catch (err) { + console.error('Error submitting RSVP:', err); setError('Failed to submit RSVP. Please try again.'); } finally { setIsSubmitting(false); diff --git a/src/index.ts b/src/index.ts index bf8e9d1..c60cda1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,12 +125,15 @@ app.post('/api/events/:slug/rsvp', async (req, res) => { return res.status(404).json({ error: 'Event not found' }); } + // Create a new RSVP with the submitted data const result = await db.run( 'INSERT INTO rsvps (event_id, name, attending, bringing_guests, guest_count, guest_names, items_bringing) VALUES (?, ?, ?, ?, ?, ?, ?)', - [event.id, name, attending, bringing_guests, guest_count, guest_names, items_bringing] + [event.id, name, attending, bringing_guests, guest_count, guest_names, JSON.stringify(items_bringing || [])] ); - res.status(201).json(result); + // Fetch the newly created RSVP to return in response + const newRsvp = await db.get('SELECT * FROM rsvps WHERE id = ?', result.lastID); + res.status(201).json(newRsvp); } catch (error) { console.error('Error creating RSVP:', error); res.status(500).json({