From 4b13e57fcbf2720f769987d04c95e955b8af8bbb Mon Sep 17 00:00:00 2001 From: Richard Date: Sat, 1 Aug 2026 12:20:24 +0200 Subject: [PATCH] fix: Render ProfileModal in App.jsx and support guest display name editing from Navbar --- frontend/dist/index.html | 2 +- frontend/src/App.jsx | 14 ++++++++++++ frontend/src/components/Navbar.jsx | 12 ++++++---- frontend/src/components/ProfileModal.jsx | 29 ++++++++++++++++-------- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 8ab2616..1407310 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 b40ce55..3800596 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -651,6 +651,20 @@ export default function App() { onSubmit={handleGuestSubmit} /> )} + + {showProfileModal && ( + setShowProfileModal(false)} + onUserUpdated={(updatedUser) => { + setUser(updatedUser); + setShowProfileModal(false); + refreshEvents(); + }} + onRefreshSkills={refreshSkills} + /> + )} ); } diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index 96cee5c..b7c9a9b 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -62,13 +62,17 @@ export default function Navbar({
{user ? ( - [ {user.display_name || user.username} ] + { e.stopPropagation(); onOpenProfile(); }} className="text-emerald-500 font-semibold hover:underline cursor-pointer"> + [ {user.display_name || user.username} ] + ) : savedGuestName ? ( - - [ 👤 GAST: {savedGuestName} ] + { e.stopPropagation(); onOpenProfile(); }} className="text-amber-400 font-semibold flex items-center gap-1 hover:underline cursor-pointer" title="Klicken um Gast-Name zu ändern"> + [ 👤 GAST: {savedGuestName} ✏️ ] ) : ( - [ GAST-MODUS ] + { e.stopPropagation(); onOpenProfile(); }} className="text-amber-500 font-semibold hover:underline cursor-pointer" title="Klicken um Gast-Name einzutragen"> + [ GAST-MODUS ✏️ ] + )}
diff --git a/frontend/src/components/ProfileModal.jsx b/frontend/src/components/ProfileModal.jsx index 2167dfd..a8c91dd 100644 --- a/frontend/src/components/ProfileModal.jsx +++ b/frontend/src/components/ProfileModal.jsx @@ -4,7 +4,9 @@ import { apiFetch } from '../api/client'; import { getRandomSkillColor } from '../utils/colors'; export default function ProfileModal({ user, skills, onClose, onUserUpdated, onRefreshSkills }) { - const [displayName, setDisplayName] = useState(user?.display_name || ''); + const [displayName, setDisplayName] = useState( + user?.display_name || localStorage.getItem('guest_display_name') || '' + ); const [selectedSkillIds, setSelectedSkillIds] = useState( user?.skills ? user.skills.map(s => s.id) : [] ); @@ -26,15 +28,22 @@ export default function ProfileModal({ user, skills, onClose, onUserUpdated, onR setSavingProfile(true); try { - const updatedUser = await apiFetch('/users/me/', { - method: 'PATCH', - body: JSON.stringify({ - display_name: displayName.trim(), - skill_ids: selectedSkillIds - }) - }); - setSuccess('Profil und Anzeigename erfolgreich aktualisiert!'); - onUserUpdated(updatedUser); + if (user) { + const updatedUser = await apiFetch('/users/me/', { + method: 'PATCH', + body: JSON.stringify({ + display_name: displayName.trim(), + skill_ids: selectedSkillIds + }) + }); + setSuccess('Profil und Anzeigename erfolgreich aktualisiert!'); + if (onUserUpdated) onUserUpdated(updatedUser); + } else { + localStorage.setItem('guest_display_name', displayName.trim()); + window.dispatchEvent(new Event('guest_name_updated')); + setSuccess('Gast-Name erfolgreich gespeichert!'); + setTimeout(() => onClose(), 600); + } } catch (err) { setError(err.message || 'Speichern des Profils fehlgeschlagen.'); } finally {