From 90e594850ea189c5a2970c16a165e88410a9fe3a Mon Sep 17 00:00:00 2001 From: Ryderjj89 Date: Sun, 4 May 2025 18:01:29 -0400 Subject: [PATCH] fix: split 'Other Items' on newlines and commas for RSVP submission and admin edit --- frontend/src/components/EventAdmin.tsx | 21 +++++++++++++++++---- frontend/src/components/RSVPForm.tsx | 8 +++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/EventAdmin.tsx b/frontend/src/components/EventAdmin.tsx index 1b596d0..e4cb04c 100644 --- a/frontend/src/components/EventAdmin.tsx +++ b/frontend/src/components/EventAdmin.tsx @@ -229,6 +229,12 @@ const EventAdmin: React.FC = () => { processedGuestNames = rsvp.guest_names.split(',').map(name => name.trim()); } + // Convert stored comma-separated other_items to multiline for textarea + let otherItemsMultiline = rsvp.other_items || ''; + if (otherItemsMultiline.includes(',')) { + otherItemsMultiline = otherItemsMultiline.split(',').map(s => s.trim()).join('\n'); + } + setRsvpToEdit(rsvp); setEditForm({ name: rsvp.name, @@ -239,7 +245,7 @@ const EventAdmin: React.FC = () => { items_bringing: Array.isArray(rsvp.items_bringing) ? rsvp.items_bringing : typeof rsvp.items_bringing === 'string' ? (rsvp.items_bringing ? JSON.parse(rsvp.items_bringing) : []) : [], - other_items: rsvp.other_items || '' + other_items: otherItemsMultiline }); setEditDialogOpen(true); }; @@ -334,7 +340,14 @@ const EventAdmin: React.FC = () => { const filteredGuestNames = editForm.guest_names .map(name => name.trim()) .filter(name => name.length > 0); - + + // Split other_items on newlines and commas, trim, filter, join with commas + const splitOtherItems = editForm.other_items + .split(/\r?\n|,/) + .map(s => s.trim()) + .filter(Boolean) + .join(', '); + // Prepare submission data in the exact format the backend expects const submissionData = { name: editForm.name, @@ -343,7 +356,7 @@ const EventAdmin: React.FC = () => { guest_count: editForm.bringing_guests === 'yes' ? Math.max(1, parseInt(editForm.guest_count.toString(), 10)) : 0, guest_names: filteredGuestNames, items_bringing: JSON.stringify(editForm.items_bringing), - other_items: editForm.other_items, + other_items: splitOtherItems, event_id: event.id }; @@ -378,7 +391,7 @@ const EventAdmin: React.FC = () => { ...submissionData, guest_names: filteredGuestNames, items_bringing: editForm.items_bringing, - other_items: editForm.other_items + other_items: splitOtherItems }; // Update the local state diff --git a/frontend/src/components/RSVPForm.tsx b/frontend/src/components/RSVPForm.tsx index 5b3c143..4182f1f 100644 --- a/frontend/src/components/RSVPForm.tsx +++ b/frontend/src/components/RSVPForm.tsx @@ -252,9 +252,15 @@ const RSVPForm: React.FC = () => { } try { + const splitOtherItems = formData.other_items + .split(/\r?\n|,/) + .map(s => s.trim()) + .filter(Boolean) + .join(', '); const submissionData = { ...formData, - items_bringing: formData.items_bringing + items_bringing: formData.items_bringing, + other_items: splitOtherItems }; const response = await axios.post(`/api/events/${slug}/rsvp`, submissionData);