From d13aa44c917bc450c8817f2e1455c16b1948ba97 Mon Sep 17 00:00:00 2001 From: Starstrike Date: Thu, 1 May 2025 16:43:34 -0400 Subject: [PATCH] Fix TypeScript type errors in items_bringing handling --- frontend/src/components/EventAdmin.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/EventAdmin.tsx b/frontend/src/components/EventAdmin.tsx index d142f95..c04ed67 100644 --- a/frontend/src/components/EventAdmin.tsx +++ b/frontend/src/components/EventAdmin.tsx @@ -58,6 +58,15 @@ interface Event { rsvp_cutoff_date?: string; } +interface EditFormData { + name: string; + attending: 'yes' | 'no' | 'maybe'; + bringing_guests: 'yes' | 'no'; + guest_count: number; + guest_names: string; + items_bringing: string[]; // Always an array in the form +} + const EventAdmin: React.FC = () => { const { slug } = useParams<{ slug: string }>(); const navigate = useNavigate(); @@ -71,7 +80,7 @@ const EventAdmin: React.FC = () => { const [rsvpToDelete, setRsvpToDelete] = useState(null); const [editDialogOpen, setEditDialogOpen] = useState(false); const [rsvpToEdit, setRsvpToEdit] = useState(null); - const [editForm, setEditForm] = useState>({ + const [editForm, setEditForm] = useState({ name: '', attending: 'yes', bringing_guests: 'no', @@ -187,7 +196,8 @@ const EventAdmin: React.FC = () => { guest_count: typeof rsvp.guest_count === 'number' ? rsvp.guest_count : 0, guest_names: rsvp.guest_names || '', items_bringing: Array.isArray(rsvp.items_bringing) ? rsvp.items_bringing : - typeof rsvp.items_bringing === 'string' ? JSON.parse(rsvp.items_bringing) : [] + typeof rsvp.items_bringing === 'string' ? + (rsvp.items_bringing ? JSON.parse(rsvp.items_bringing) : []) : [] }); setEditDialogOpen(true); }; @@ -210,7 +220,7 @@ const EventAdmin: React.FC = () => { const handleItemsChange = (e: SelectChangeEvent) => { const { value } = e.target; - const newItems = Array.isArray(value) ? value : []; + const newItems = typeof value === 'string' ? value.split(',') : value; setEditForm(prev => ({ ...prev, items_bringing: newItems @@ -787,7 +797,7 @@ const EventAdmin: React.FC = () => { )} What items are you bringing? -