"use client"; import { useEffect, useState } from "react"; import { motion } from "framer-motion"; import { User, Bell, Sparkles, Shield, Save, Loader2, CheckCircle2 } from "lucide-react"; import { authApi } from "@/lib/api"; import { useAuthStore } from "@/lib/stores/authStore"; const PERSONALITIES = [ "Balanced Investor", "Conservative Saver", "Growth Focused", "Aggressive Trader", "Debt Reducer", ]; export default function SettingsPage() { const { user, restoreSession } = useAuthStore(); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); const [form, setForm] = useState({ name: "", email: "", financial_personality: "Balanced Investor", notifications_enabled: true, ai_coaching_enabled: true, fraud_alerts_enabled: true, }); useEffect(() => { (async () => { try { const me = await authApi.me(); setForm({ name: me.name, email: me.email, financial_personality: me.financial_personality || "Balanced Investor", notifications_enabled: me.notifications_enabled ?? true, ai_coaching_enabled: me.ai_coaching_enabled ?? true, fraud_alerts_enabled: me.fraud_alerts_enabled ?? true, }); } catch { if (user) { setForm((f) => ({ ...f, name: user.name, email: user.email, financial_personality: user.financial_personality || "Balanced Investor", })); } } finally { setLoading(false); } })(); }, [user]); const handleSave = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); setSaved(false); try { await authApi.updateSettings({ name: form.name, financial_personality: form.financial_personality, notifications_enabled: form.notifications_enabled, ai_coaching_enabled: form.ai_coaching_enabled, fraud_alerts_enabled: form.fraud_alerts_enabled, }); await restoreSession(); setSaved(true); setTimeout(() => setSaved(false), 3000); } catch { /* ignore */ } finally { setSaving(false); } }; const Toggle = ({ label, desc, checked, onChange, }: { label: string; desc: string; checked: boolean; onChange: (v: boolean) => void; }) => (

{label}

{desc}

); if (loading) { return (
Loading settings...
); } return (

Settings

Account preferences and AI personalization

Profile

setForm({ ...form, name: e.target.value })} className="mt-1 w-full rounded-xl border border-white/10 bg-white/5 px-3 py-2 text-sm text-white focus:border-emerald-500/40 focus:outline-none" />

Notifications & AI

setForm({ ...form, notifications_enabled: v })} /> setForm({ ...form, ai_coaching_enabled: v })} /> setForm({ ...form, fraud_alerts_enabled: v })} />

Security

Sessions use JWT encryption. Password changes require backend support in this demo.

User ID: {user?.user_id?.slice(0, 8) ?? "—"}…
); }