import { useState, FormEvent } from 'react'; import { useGetSettings, useUpdateSettings } from '../generated/anthoLumeAPIV1'; import { User, Lock, Clock } from 'lucide-react'; import { Button } from '../components/Button'; import { useToasts } from '../components/ToastContext'; export default function SettingsPage() { const { data, isLoading } = useGetSettings(); const updateSettings = useUpdateSettings(); const settingsData = data?.data; const { showInfo, showError } = useToasts(); const [password, setPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [timezone, setTimezone] = useState(settingsData?.timezone || ''); const handlePasswordSubmit = async (e: FormEvent) => { e.preventDefault(); if (!password || !newPassword) { showError('Please enter both current and new password'); return; } try { await updateSettings.mutateAsync({ data: { password: password, new_password: newPassword, }, }); showInfo('Password updated successfully'); setPassword(''); setNewPassword(''); } catch (error: any) { showError('Failed to update password: ' + (error.response?.data?.message || error.message || 'Unknown error')); } }; const handleTimezoneSubmit = async (e: FormEvent) => { e.preventDefault(); try { await updateSettings.mutateAsync({ data: { timezone: timezone, }, }); showInfo('Timezone updated successfully'); } catch (error: any) { showError('Failed to update timezone: ' + (error.response?.data?.message || error.message || 'Unknown error')); } }; if (isLoading) { return (
); } return (
{/* User Profile Card */}

{settingsData?.user?.username}

{/* Change Password Form */}

Change Password

setPassword(e.target.value)} className="flex-1 appearance-none rounded-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent" placeholder="Password" />
setNewPassword(e.target.value)} className="flex-1 appearance-none rounded-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent" placeholder="New Password" />
{/* Change Timezone Form */}

Change Timezone

{/* Devices Table */}

Devices

{!settingsData?.devices || settingsData.devices.length === 0 ? ( ) : ( settingsData.devices.map((device: any) => ( )) )}
Name Last Sync Created
No Results

{device.device_name || 'Unknown'}

{device.last_synced ? new Date(device.last_synced).toLocaleString() : 'N/A'}

{device.created_at ? new Date(device.created_at).toLocaleString() : 'N/A'}

); }