diff --git a/frontend/dist/index.html b/frontend/dist/index.html index c1abaf1..a5475d6 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -11,7 +11,7 @@ Schichtplaner — Veranstaltungsschichtpläne - + diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 65e30f8..0d47f67 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -490,6 +490,7 @@ export default function App() { /> ) : activeTab === 'event-editor' ? ( { fetchUsers(); - if (eventToEdit) { - setEventId(eventToEdit.id); - setTitle(eventToEdit.title || ''); - setDescription(eventToEdit.description || ''); - setLocation(eventToEdit.location || ''); - setStartDate(eventToEdit.start_date || new Date().toISOString().split('T')[0]); - setEndDate(eventToEdit.end_date || new Date().toISOString().split('T')[0]); - setCoManagerIds( - eventToEdit.co_managers ? eventToEdit.co_managers.map(u => (typeof u === 'object' ? u.id : u)) : [] - ); + const currentId = eventToEdit?.id || null; - if (eventToEdit.task_areas && eventToEdit.task_areas.length > 0) { - const formattedAreas = eventToEdit.task_areas.map(ta => ({ - id: ta.id, - name: ta.name, - description: ta.description || '', - shifts: (ta.shifts || []).map(s => ({ - id: s.id, - title: s.title, - date: s.date || eventToEdit.start_date, - start_time: s.start_time, - end_time: s.end_time, - max_participants: s.max_participants || 1, - required_skill_ids: s.required_skills ? s.required_skills.map(sk => (typeof sk === 'object' ? sk.id : sk)) : [] - })) - })); - setTaskAreas(formattedAreas); - } else { - setTaskAreas([]); - } - } else { - setEventId(null); - setTitle(''); - setDescription(''); - setLocation(''); - setStartDate(new Date().toISOString().split('T')[0]); - setEndDate(new Date().toISOString().split('T')[0]); - setCoManagerIds([]); - setTaskAreas([ - { - name: 'Tresendienst', - description: 'Getränke- und Barverkauf', - shifts: [{ title: 'Schicht 1', start_time: '18:00', end_time: '22:00', max_participants: 2, required_skill_ids: [] }] - }, - { - name: 'Essen kochen', - description: 'Zubereitung von Speisen', - shifts: [{ title: 'Frühschicht', start_time: '15:00', end_time: '19:00', max_participants: 3, required_skill_ids: [] }] - }, - { - name: 'Aufbau & Aufräumen', - description: 'Tische, Stühle & Technik', - shifts: [{ title: 'Aufbau', start_time: '12:00', end_time: '15:00', max_participants: 4, required_skill_ids: [] }] + // Only populate form fields if eventId changed or initial load + if (loadedEventIdRef.current !== currentId) { + loadedEventIdRef.current = currentId; + + if (eventToEdit) { + setEventId(eventToEdit.id); + setTitle(eventToEdit.title || ''); + setDescription(eventToEdit.description || ''); + setLocation(eventToEdit.location || ''); + setStartDate(eventToEdit.start_date || new Date().toISOString().split('T')[0]); + setEndDate(eventToEdit.end_date || new Date().toISOString().split('T')[0]); + setCoManagerIds( + eventToEdit.co_managers ? eventToEdit.co_managers.map(u => (typeof u === 'object' ? u.id : u)) : [] + ); + + if (eventToEdit.task_areas && eventToEdit.task_areas.length > 0) { + const formattedAreas = eventToEdit.task_areas.map(ta => ({ + id: ta.id, + name: ta.name, + description: ta.description || '', + shifts: (ta.shifts || []).map(s => ({ + id: s.id, + title: s.title, + date: s.date || eventToEdit.start_date, + start_time: s.start_time, + end_time: s.end_time, + max_participants: s.max_participants || 1, + required_skill_ids: s.required_skills ? s.required_skills.map(sk => (typeof sk === 'object' ? sk.id : sk)) : [] + })) + })); + setTaskAreas(formattedAreas); + } else { + setTaskAreas([]); } - ]); + } else { + setEventId(null); + setTitle(''); + setDescription(''); + setLocation(''); + setStartDate(new Date().toISOString().split('T')[0]); + setEndDate(new Date().toISOString().split('T')[0]); + setCoManagerIds([]); + setTaskAreas([ + { + name: 'Tresendienst', + description: 'Getränke- und Barverkauf', + shifts: [{ title: 'Schicht 1', start_time: '18:00', end_time: '22:00', max_participants: 2, required_skill_ids: [] }] + }, + { + name: 'Essen kochen', + description: 'Zubereitung von Speisen', + shifts: [{ title: 'Frühschicht', start_time: '15:00', end_time: '19:00', max_participants: 3, required_skill_ids: [] }] + }, + { + name: 'Aufbau & Aufräumen', + description: 'Tische, Stühle & Technik', + shifts: [{ title: 'Aufbau', start_time: '12:00', end_time: '15:00', max_participants: 4, required_skill_ids: [] }] + } + ]); + } } }, [eventToEdit]);