Fix item claiming in RSVP submission - Handle JSON stringification in backend, improve response handling
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user