"use client"; import { useState, useEffect } from "react"; import { useDictionary } from "@/components/DictionaryContext"; import { useSession } from "next-auth/react"; export default function SettingsPage() { const { data: session } = useSession(); 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 [fetchingQr, setFetchingQr] = useState(false); const dict = useDictionary(); useEffect(() => { fetchProfile(); fetchWaStatus(); const interval = setInterval(() => { fetchWaStatus(); }, 5000); return () => clearInterval(interval); }, []); const fetchProfile = async () => { try { const res = await fetch("/api/users/profile"); const data = await res.json(); if (data && 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 () => { try { const res = await fetch("/api/whatsapp/status"); const data = await res.json(); setWaStatus(data); } catch (e) { console.error(e); } }; const handleConnectWa = async () => { setFetchingQr(true); try { const res = await fetch("/api/whatsapp/qr"); const data = await res.json(); setWaStatus(data); } catch (e) { console.error(e); } finally { setFetchingQr(false); } }; const handleSave = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); try { const res = await fetch("/api/users/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(profile) }); if (res.ok) alert("Ayarlar kaydedildi!"); else { const data = await res.json(); alert("Hata: " + (data?.error || "Bilinmeyen bir hata oluştu.")); } } 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 ( <>

Bildirim Ayarları

Telegram ve WhatsApp bildirimlerinizi buradan yönetin.

Telegram Bildirimleri

setProfile({...profile, telegramEnabled: e.target.checked})} />
setProfile({...profile, telegramId: e.target.value})} placeholder="Örn: 5009005027" />

WhatsApp Bildirimleri

setProfile({...profile, whatsappEnabled: e.target.checked})} />
setProfile({...profile, whatsappNumber: e.target.value})} placeholder="90554XXXXXXX" />
{waStatus?.status === 'connected' ? (
Bağlı ✅
) : (
Bağlı Değil
{waStatus?.qr ? (
QR Code

WhatsApp'tan okutun

) : ( )}
)}
); } function TelegramIcon() { return ; } function WhatsAppIcon() { return ; }