Fix TypeScript error: Handle guest_names as both string and array in EventAdmin

This commit is contained in:
Starstrike
2025-05-01 17:50:57 -04:00
parent 023a4cf84f
commit 7c967d9209

View File

@@ -211,13 +211,20 @@ const EventAdmin: React.FC = () => {
};
const handleEditRsvp = (rsvp: RSVP) => {
let processedGuestNames: string[] = [];
if (Array.isArray(rsvp.guest_names)) {
processedGuestNames = rsvp.guest_names;
} else if (typeof rsvp.guest_names === 'string' && rsvp.guest_names) {
processedGuestNames = rsvp.guest_names.split(',').map(name => name.trim());
}
setRsvpToEdit(rsvp);
setEditForm({
name: rsvp.name,
attending: rsvp.attending || 'yes',
bringing_guests: rsvp.bringing_guests || 'no',
guest_count: typeof rsvp.guest_count === 'number' ? rsvp.guest_count : 0,
guest_names: rsvp.guest_names ? rsvp.guest_names.split(',').map(name => name.trim()) : [],
guest_names: processedGuestNames,
items_bringing: Array.isArray(rsvp.items_bringing) ? rsvp.items_bringing :
typeof rsvp.items_bringing === 'string' ?
(rsvp.items_bringing ? JSON.parse(rsvp.items_bringing) : []) : []