import React, { useState, useEffect } from 'react'; import { Layout } from '../components/Layout/Layout'; import { useAuth } from '../context/AuthContext'; import { useNavigate } from 'react-router-dom'; import { Settings as SettingsIcon, Lock, Bell, Moon, Globe, Save, AlertCircle } from 'lucide-react'; const API_URL = 'http://localhost:3001/api'; export const Settings: React.FC = () => { const { user } = useAuth(); const navigate = useNavigate(); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); // Load saved settings from localStorage const loadSettings = () => { const saved = localStorage.getItem('userSettings'); if (saved) { try { const settings = JSON.parse(saved); if (settings.notifications) { setNotifications(settings.notifications); } if (settings.display) { setDisplay(settings.display); } } catch (e) { console.error('Error loading settings:', e); } } }; // Notification preferences const [notifications, setNotifications] = useState({ emailNotifications: true, pushNotifications: true, scheduleReminders: true, payrollAlerts: true, documentExpiry: true, }); // Display preferences const [display, setDisplay] = useState({ theme: 'light', language: 'en', timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, dateFormat: 'MM/DD/YYYY', timeFormat: '12h', }); useEffect(() => { loadSettings(); }, []); const handleNotificationChange = (key: string) => { setNotifications(prev => ({ ...prev, [key]: !prev[key as keyof typeof prev] })); }; const handleDisplayChange = (key: string, value: string) => { setDisplay(prev => ({ ...prev, [key]: value })); }; const handleSave = async () => { setLoading(true); setError(''); setSuccess(''); try { // In a real app, this would save to the backend // For now, we'll just save to localStorage localStorage.setItem('userSettings', JSON.stringify({ notifications, display, })); setSuccess('Settings saved successfully!'); setTimeout(() => setSuccess(''), 3000); } catch (error) { setError('Failed to save settings'); } finally { setLoading(false); } }; const handleChangePassword = () => { navigate('/change-password'); }; return (

Settings

{error && (
{error}
)} {success && (
{success}
)}
{/* Security Settings */}

Security

Password

Change your account password

{/* Notification Settings */}

Notifications

Email Notifications

Receive notifications via email

Push Notifications

Receive push notifications in browser

Schedule Reminders

Get reminders for upcoming shifts

Payroll Alerts

Notifications about payroll updates

Document Expiry Warnings

Alerts when documents are expiring

{/* Display Preferences */}

Display Preferences

); };