Fix RSVP items handling and response format

This commit is contained in:
2025-05-01 09:11:15 -04:00
parent 1470eecb99
commit d8f99d3169
2 changed files with 22 additions and 7 deletions

View File

@@ -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' });

View File

@@ -154,8 +154,9 @@ const RSVPForm: React.FC = () => {
const claimed = new Set<string>();
// 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') {
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));
}
} catch (e) {
console.error('Error processing RSVP items:', e);
}