"use client"; import { useEffect, useRef, useState } from "react"; import Image from "next/image"; import { Blocks, Brain, Key, Save, Shield, User } from "lucide-react"; import { loadSettings, saveAiSettings, updatePassword, updateProfile } from "./actions"; import { Button, Card, CardContent, Input, Label } from "poyraz-ui/atoms"; import { toast } from "poyraz-ui/molecules"; type AiProvider = "groq" | "ollama" | "openai" | "gemini"; export default function SettingsPage() { const [activeTab, setActiveTab] = useState("AI Preferences"); // Profile States const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); const [avatarUrl, setAvatarUrl] = useState(""); // Security States const formRef = useRef(null); // AI States const [aiProvider, setAiProvider] = useState("gemini"); const [apiKey, setApiKey] = useState(""); const [hasApiKey, setHasApiKey] = useState(false); const tabs = [ { name: "Profile & Account", icon: User }, { name: "AI Preferences", icon: Brain }, { name: "Security", icon: Shield }, ]; useEffect(() => { let isActive = true; const fetchData = async () => { const settings = await loadSettings(); if (!isActive) return; setFirstName(settings.firstName); setLastName(settings.lastName); setAvatarUrl(settings.avatarUrl); setAiProvider(settings.aiProvider); setHasApiKey(settings.hasApiKey); }; void fetchData(); return () => { isActive = false; }; }, []); const handleProfileAction = async (formData: FormData) => { const response = await updateProfile(formData); if (response?.error) { toast.error(`Hata: ${response.error}`); } else { toast.success("Profil güncellendi!"); const avatar = formData.get("avatar"); if (avatar instanceof File && avatar.size > 0) window.location.reload(); } }; const handlePasswordAction = async (formData: FormData) => { const response = await updatePassword(formData); if (response?.error) { toast.error(`Hata: ${response.error}`); } else { toast.success("Şifre güncellendi!"); formRef.current?.reset(); } }; const handleSaveAI = async () => { const response = await saveAiSettings(aiProvider, apiKey); if (response.error) { toast.error(response.error); return; } setHasApiKey(Boolean(response.hasApiKey)); setApiKey(""); toast.success("Yapay Zeka ayarları kaydedildi!"); }; return (
Settings / {activeTab}

Ayarlar

Profilinizi, güvenlik ayarlarınızı ve yapay zeka tercihlerinizi yönetin.

{/* Settings Sidebar */}
{tabs.map((tab) => { const Icon = tab.icon; return ( ) })}
{/* Settings Content Area */}
{activeTab === "Profile & Account" && (

Kullanıcı Profili

{avatarUrl ? ( Avatar ) : (
)}
setFirstName(e.target.value)} />
setLastName(e.target.value)} />
)} {activeTab === "Security" && (

Şifre İşlemleri

)} {activeTab === "AI Preferences" && (

AI Asistan Konfigürasyonu

Model ve Sağlayıcı Seçimi

{aiProvider !== "ollama" && (

API Keys

setApiKey(e.target.value)} placeholder={hasApiKey ? "Kayıtlı anahtarı korumak için boş bırakın" : "sk-..."} />
)}
)} {["Integrations", "Notifications", "Billing & Plans"].includes(activeTab) && (

{activeTab}

Bu bölüm şu an geliştirme aşamasındadır.

)}
); }