From cdf8bff0ecd452f4648743d46f5842dd63db3374 Mon Sep 17 00:00:00 2001 From: Starstrike Date: Thu, 1 May 2025 08:33:33 -0400 Subject: [PATCH] Implement wallpaper upload functionality with proper file handling and UI feedback --- frontend/src/components/EventForm.tsx | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/EventForm.tsx b/frontend/src/components/EventForm.tsx index 708a89c..239170d 100644 --- a/frontend/src/components/EventForm.tsx +++ b/frontend/src/components/EventForm.tsx @@ -8,6 +8,7 @@ import { Container, Paper, Chip, + Input, } from '@mui/material'; import axios from 'axios'; @@ -20,6 +21,7 @@ const EventForm: React.FC = () => { location: '', needed_items: [] as string[], }); + const [wallpaper, setWallpaper] = useState(null); const [currentItem, setCurrentItem] = useState(''); const [error, setError] = useState(null); @@ -31,6 +33,12 @@ const EventForm: React.FC = () => { })); }; + const handleWallpaperChange = (e: React.ChangeEvent) => { + if (e.target.files && e.target.files[0]) { + setWallpaper(e.target.files[0]); + } + }; + const handleItemChange = (e: React.ChangeEvent) => { setCurrentItem(e.target.value); }; @@ -56,7 +64,27 @@ const EventForm: React.FC = () => { e.preventDefault(); setError(null); try { - await axios.post('/api/events', formData); + const submitData = new FormData(); + + // Append all form fields + Object.entries(formData).forEach(([key, value]) => { + if (key === 'needed_items') { + submitData.append(key, JSON.stringify(value)); + } else { + submitData.append(key, value); + } + }); + + // Append wallpaper if selected + if (wallpaper) { + submitData.append('wallpaper', wallpaper); + } + + await axios.post('/api/events', submitData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); navigate('/'); } catch (error) { setError('Failed to create event. Please try again.'); @@ -119,6 +147,21 @@ const EventForm: React.FC = () => { variant="outlined" required /> + + Event Wallpaper + + {wallpaper && ( + + Selected file: {wallpaper.name} + + )} + Needed Items