Fix item claiming not showing up immediately after RSVP submission
This commit is contained in:
@@ -168,8 +168,14 @@ const RSVPForm: React.FC = () => {
|
||||
|
||||
// Get all claimed items from existing RSVPs including the new submission
|
||||
const claimed = new Set<string>();
|
||||
const allRsvps = [...rsvpsResponse.data, response.data];
|
||||
allRsvps.forEach((rsvp: any) => {
|
||||
|
||||
// First add items from the new submission
|
||||
if (Array.isArray(response.data.items_bringing)) {
|
||||
response.data.items_bringing.forEach(item => claimed.add(item));
|
||||
}
|
||||
|
||||
// Then add items from existing RSVPs
|
||||
rsvpsResponse.data.forEach((rsvp: any) => {
|
||||
try {
|
||||
let rsvpItems: string[] = [];
|
||||
if (typeof rsvp.items_bringing === 'string') {
|
||||
|
||||
15
src/index.ts
15
src/index.ts
@@ -131,9 +131,18 @@ app.post('/api/events/:slug/rsvp', async (req, res) => {
|
||||
[event.id, name, attending, bringing_guests, guest_count, guest_names, JSON.stringify(items_bringing || [])]
|
||||
);
|
||||
|
||||
// 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);
|
||||
// Return a complete response with the original items_bringing array
|
||||
res.status(201).json({
|
||||
id: result.lastID,
|
||||
event_id: event.id,
|
||||
name,
|
||||
attending,
|
||||
bringing_guests,
|
||||
guest_count,
|
||||
guest_names,
|
||||
items_bringing: items_bringing || [],
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating RSVP:', error);
|
||||
res.status(500).json({
|
||||
|
||||
Reference in New Issue
Block a user