"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 [saving, setSaving] = useState(false); const dict = useDictionary(); useEffect(() => { fetchProfile(); fetchWaStatus(); // Check WA status every 5 seconds if not connected const interval = setInterval(() => { fetchWaStatus(); }, 5000); return () => clearInterval(interval); }, []); const fetchProfile = async () => { const res = await fetch("/api/users/profile"); const data = await res.json(); setProfile(data); 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 handleSave = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); try { await fetch("/api/users/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(profile) }); alert("Ayarlar kaydedildi!"); } catch (e) { console.error(e); } finally { setSaving(false); } }; if (loading) return
; 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" />

Botu başlatın ve ID'nizi buraya yazın.

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 ; }