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 {
|
try {
|
||||||
const submissionData = {
|
const submissionData = {
|
||||||
...formData,
|
...formData,
|
||||||
items_bringing: JSON.stringify(formData.items_bringing)
|
items_bringing: formData.items_bringing
|
||||||
};
|
};
|
||||||
const response = await axios.post(`/api/events/${slug}/rsvp`, submissionData);
|
const response = await axios.post(`/api/events/${slug}/rsvp`, submissionData);
|
||||||
|
|
||||||
@@ -198,6 +198,7 @@ const RSVPForm: React.FC = () => {
|
|||||||
setClaimedItems(Array.from(claimed));
|
setClaimedItems(Array.from(claimed));
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error('Error submitting RSVP:', err);
|
||||||
setError('Failed to submit RSVP. Please try again.');
|
setError('Failed to submit RSVP. Please try again.');
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
|
|||||||
@@ -125,12 +125,15 @@ app.post('/api/events/:slug/rsvp', async (req, res) => {
|
|||||||
return res.status(404).json({ error: 'Event not found' });
|
return res.status(404).json({ error: 'Event not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new RSVP with the submitted data
|
||||||
const result = await db.run(
|
const result = await db.run(
|
||||||
'INSERT INTO rsvps (event_id, name, attending, bringing_guests, guest_count, guest_names, items_bringing) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
'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) {
|
} catch (error) {
|
||||||
console.error('Error creating RSVP:', error);
|
console.error('Error creating RSVP:', error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
|
|||||||
Reference in New Issue
Block a user