diff --git a/backend/src/index.ts b/backend/src/index.ts index e577f12..197827e 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -213,7 +213,18 @@ app.post('/api/events/:slug/rsvp', async (req: Request, res: Response) => { 'INSERT INTO rsvps (event_id, name, attending, bringing_guests, guest_count, guest_names, items_bringing) VALUES (?, ?, ?, ?, ?, ?, ?)', [eventId, name, attending, bringing_guests, guest_count, guest_names, JSON.stringify(items_bringing || [])] ); - res.status(201).json(result); + + // Return the complete RSVP data including the parsed items_bringing + res.status(201).json({ + ...result, + id: result.lastID, + name, + attending, + bringing_guests, + guest_count, + guest_names, + items_bringing: items_bringing || [] + }); } catch (error) { console.error('Error creating RSVP:', error); res.status(500).json({ error: 'Internal server error' }); diff --git a/frontend/src/components/RSVPForm.tsx b/frontend/src/components/RSVPForm.tsx index 2c5124b..eea2531 100644 --- a/frontend/src/components/RSVPForm.tsx +++ b/frontend/src/components/RSVPForm.tsx @@ -154,8 +154,9 @@ const RSVPForm: React.FC = () => { const claimed = new Set(); // First add items from the new submission - if (Array.isArray(response.data.items_bringing)) { - response.data.items_bringing.forEach((item: string) => claimed.add(item)); + const newRsvpItems = response.data.items_bringing || []; + if (Array.isArray(newRsvpItems)) { + newRsvpItems.forEach((item: string) => claimed.add(item)); } // Then add items from existing RSVPs @@ -163,14 +164,17 @@ const RSVPForm: React.FC = () => { try { let rsvpItems: string[] = []; if (typeof rsvp.items_bringing === 'string') { - rsvpItems = JSON.parse(rsvp.items_bringing); + try { + rsvpItems = JSON.parse(rsvp.items_bringing); + } catch (e) { + console.error('Error parsing items_bringing JSON:', e); + rsvpItems = []; + } } else if (Array.isArray(rsvp.items_bringing)) { rsvpItems = rsvp.items_bringing; } - if (rsvpItems.length > 0) { - rsvpItems.forEach((item: string) => claimed.add(item)); - } + rsvpItems.forEach((item: string) => claimed.add(item)); } catch (e) { console.error('Error processing RSVP items:', e); }