diff --git a/app/[lang]/dashboard/settings/page.tsx b/app/[lang]/dashboard/settings/page.tsx index 8775203..8b3784c 100644 --- a/app/[lang]/dashboard/settings/page.tsx +++ b/app/[lang]/dashboard/settings/page.tsx @@ -9,6 +9,7 @@ export default function SettingsPage() { const [profile, setProfile] = useState(null); const [waStatus, setWaStatus] = useState(null); const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); const [saving, setSaving] = useState(false); const dict = useDictionary(); @@ -16,7 +17,6 @@ export default function SettingsPage() { fetchProfile(); fetchWaStatus(); - // Check WA status every 5 seconds if not connected const interval = setInterval(() => { fetchWaStatus(); }, 5000); @@ -25,10 +25,21 @@ export default function SettingsPage() { }, []); const fetchProfile = async () => { - const res = await fetch("/api/users/profile"); - const data = await res.json(); - setProfile(data); - setLoading(false); + try { + const res = await fetch("/api/users/profile"); + const data = await res.json(); + if (data.error) { + setError(data.error); + } else if (!data) { + setError("Kullanıcı profili bulunamadı."); + } else { + setProfile(data); + } + } catch (e: any) { + setError(e.message); + } finally { + setLoading(false); + } }; const fetchWaStatus = async () => { @@ -45,20 +56,27 @@ export default function SettingsPage() { e.preventDefault(); setSaving(true); try { - await fetch("/api/users/profile", { + const res = await fetch("/api/users/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(profile) }); - alert("Ayarlar kaydedildi!"); - } catch (e) { - console.error(e); + if (res.ok) { + alert("Ayarlar kaydedildi!"); + } else { + const data = await res.json(); + alert("Hata: " + data.error); + } + } catch (e: any) { + alert("Hata: " + e.message); } finally { setSaving(false); } }; if (loading) return
; + if (error) return
Hata: {error}
; + if (!profile) return
Profil yüklenemedi.
; return ( <>