import React, { useState } from 'react'; import { api } from '@nexus/shared'; import { X, User, Shield, Key, Camera, Check, AlertCircle, Loader2 } from 'lucide-react'; import { motion, AnimatePresence } from 'framer-motion'; const COLORS = { brand: "#7C3AED", brandLight: "#A78BFA", bg: "#0A0C10", card: "#161B22", border: "rgba(255,255,255,0.08)", text: "#E6EDF3", subtext: "#8B949E", error: "#F85149", success: "#3FB950", }; interface UserSettingsModalProps { user: any; onClose: () => void; onUpdate: (updatedUser: any) => void; } export const UserSettingsModal: React.FC = ({ user, onClose, onUpdate }) => { const [tab, setTab] = useState<'profile' | 'security'>('profile'); const [loading, setLoading] = useState(false); const [message, setMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null); // Profile Form const [profileForm, setProfileForm] = useState({ full_name: user?.full_name || '', avatar_url: user?.avatar_url || '' }); // Security Form const [securityForm, setSecurityForm] = useState({ old_password: '', new_password: '', confirm_password: '' }); const handleProfileUpdate = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setMessage(null); try { const resp = await api.patch('users/me/', profileForm); onUpdate(resp.data); setMessage({ type: 'success', text: 'Profile updated successfully.' }); } catch (err) { setMessage({ type: 'error', text: 'Failed to update profile. Check your connection.' }); } finally { setLoading(false); } }; const handlePasswordUpdate = async (e: React.FormEvent) => { e.preventDefault(); if (securityForm.new_password !== securityForm.confirm_password) { setMessage({ type: 'error', text: 'New passwords do not match.' }); return; } setLoading(true); setMessage(null); try { await api.post('auth/change-password/', { old_password: securityForm.old_password, new_password: securityForm.new_password }); setMessage({ type: 'success', text: 'Password updated successfully.' }); setSecurityForm({ old_password: '', new_password: '', confirm_password: '' }); } catch (err) { setMessage({ type: 'error', text: 'Invalid current password or update failure.' }); } finally { setLoading(false); } }; return (
{/* Glow Effect */}
{/* Header */}
IDENTITY CONFIGURATION

User Settings

Manage your profile and account security.

{/* Tabs */}
{message && ( {message.type === 'success' ? : } {message.text} )} {tab === 'profile' ? (
setProfileForm({...profileForm, full_name: e.target.value})} placeholder="e.g. John Smith" style={{ width: '100%', padding: '16px 20px', borderRadius: 16, background: 'rgba(13, 17, 23, 0.6)', border: `1px solid ${COLORS.border}`, color: COLORS.text, fontSize: 15, outline: 'none', transition: '0.2s', fontWeight: 600 }} onFocus={(e) => (e.target.style.borderColor = COLORS.brand)} onBlur={(e) => (e.target.style.borderColor = COLORS.border)} />
setProfileForm({...profileForm, avatar_url: e.target.value})} placeholder="https://nexus.ai/assets/avatar.png" style={{ width: '100%', padding: '16px 20px', borderRadius: 16, background: 'rgba(13, 17, 23, 0.6)', border: `1px solid ${COLORS.border}`, color: COLORS.text, fontSize: 15, outline: 'none', transition: '0.2s', fontWeight: 500, fontFamily: 'var(--font-mono, monospace)' }} onFocus={(e) => (e.target.style.borderColor = COLORS.brand)} onBlur={(e) => (e.target.style.borderColor = COLORS.border)} />
{loading ? : } {loading ? 'Updating...' : 'Save Changes'}
) : (
setSecurityForm({...securityForm, old_password: e.target.value})} style={{ width: '100%', padding: '16px 20px', borderRadius: 16, background: 'rgba(13, 17, 23, 0.6)', border: `1px solid ${COLORS.border}`, color: COLORS.text, fontSize: 15, outline: 'none', fontWeight: 600 }} onFocus={(e) => (e.target.style.borderColor = COLORS.brand)} onBlur={(e) => (e.target.style.borderColor = COLORS.border)} />
setSecurityForm({...securityForm, new_password: e.target.value})} style={{ width: '100%', padding: '16px 20px', borderRadius: 16, background: 'rgba(13, 17, 23, 0.6)', border: `1px solid ${COLORS.border}`, color: COLORS.text, fontSize: 15, outline: 'none', fontWeight: 600 }} onFocus={(e) => (e.target.style.borderColor = COLORS.brand)} onBlur={(e) => (e.target.style.borderColor = COLORS.border)} />
setSecurityForm({...securityForm, confirm_password: e.target.value})} style={{ width: '100%', padding: '16px 20px', borderRadius: 16, background: 'rgba(13, 17, 23, 0.6)', border: `1px solid ${COLORS.border}`, color: COLORS.text, fontSize: 15, outline: 'none', fontWeight: 600 }} onFocus={(e) => (e.target.style.borderColor = COLORS.brand)} onBlur={(e) => (e.target.style.borderColor = COLORS.border)} />
{loading ? : } {loading ? 'Updating...' : 'Update Password'}
)}
); };