// frontend/src/pages/Settings/Settings.tsx import React, { useState, useEffect } from 'react'; import { useAuth } from '../../contexts/AuthContext'; import { employeeService } from '../../services/employeeService'; import { useNotification } from '../../contexts/NotificationContext'; import AvailabilityManager from '../Employees/components/AvailabilityManager'; import { Employee } from '../../models/Employee'; const Settings: React.FC = () => { const { user: currentUser, updateUser } = useAuth(); const { showNotification } = useNotification(); const [activeTab, setActiveTab] = useState<'profile' | 'password' | 'availability'>('profile'); const [loading, setLoading] = useState(false); const [showAvailabilityManager, setShowAvailabilityManager] = useState(false); // Profile form state const [profileForm, setProfileForm] = useState({ name: currentUser?.name || '' }); // Password form state const [passwordForm, setPasswordForm] = useState({ currentPassword: '', newPassword: '', confirmPassword: '' }); useEffect(() => { if (currentUser) { setProfileForm({ name: currentUser.name }); } }, [currentUser]); const handleProfileChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setProfileForm(prev => ({ ...prev, [name]: value })); }; const handlePasswordChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setPasswordForm(prev => ({ ...prev, [name]: value })); }; const handleProfileUpdate = async (e: React.FormEvent) => { e.preventDefault(); if (!currentUser) return; try { setLoading(true); await employeeService.updateEmployee(currentUser.id, { name: profileForm.name.trim() }); // Update the auth context with new user data const updatedUser = await employeeService.getEmployee(currentUser.id); updateUser(updatedUser); showNotification({ type: 'success', title: 'Erfolg', message: 'Profil erfolgreich aktualisiert' }); } catch (error: any) { showNotification({ type: 'error', title: 'Fehler', message: error.message || 'Profil konnte nicht aktualisiert werden' }); } finally { setLoading(false); } }; const handlePasswordUpdate = async (e: React.FormEvent) => { e.preventDefault(); if (!currentUser) return; // Validation if (passwordForm.newPassword.length < 6) { showNotification({ type: 'error', title: 'Fehler', message: 'Das neue Passwort muss mindestens 6 Zeichen lang sein' }); return; } if (passwordForm.newPassword !== passwordForm.confirmPassword) { showNotification({ type: 'error', title: 'Fehler', message: 'Die Passwörter stimmen nicht überein' }); return; } try { setLoading(true); // Use the actual password change endpoint await employeeService.changePassword(currentUser.id, { currentPassword: passwordForm.currentPassword, newPassword: passwordForm.newPassword }); showNotification({ type: 'success', title: 'Erfolg', message: 'Passwort erfolgreich geändert' }); // Clear password form setPasswordForm({ currentPassword: '', newPassword: '', confirmPassword: '' }); } catch (error: any) { showNotification({ type: 'error', title: 'Fehler', message: error.message || 'Passwort konnte nicht geändert werden' }); } finally { setLoading(false); } }; const handleAvailabilitySave = () => { setShowAvailabilityManager(false); showNotification({ type: 'success', title: 'Erfolg', message: 'Verfügbarkeit erfolgreich gespeichert' }); }; const handleAvailabilityCancel = () => { setShowAvailabilityManager(false); }; if (!currentUser) { return
Nicht eingeloggt
; } if (showAvailabilityManager) { return ( ); } return (

⚙️ Einstellungen

{/* Tab Navigation */}
{/* Profile Tab */} {activeTab === 'profile' && (

Profilinformationen

{/* Read-only information */}

Systeminformationen

{/* Editable name */}
)} {/* Password Tab */} {activeTab === 'password' && (

Passwort ändern

Das Passwort muss mindestens 6 Zeichen lang sein.
)} {/* Availability Tab */} {activeTab === 'availability' && (

Meine Verfügbarkeit

📅

Verfügbarkeit verwalten

Hier können Sie Ihre persönliche Verfügbarkeit für Schichtpläne festlegen. Legen Sie für jeden Tag und jede Schicht fest, ob Sie bevorzugt, möglicherweise oder nicht verfügbar sind.

💡 Informationen:
  • Bevorzugt: Sie möchten diese Schicht arbeiten
  • Möglich: Sie können diese Schicht arbeiten
  • Nicht möglich: Sie können diese Schicht nicht arbeiten
)}
); }; export default Settings;