import React, { useState } from 'react'; import { api } from '@nexus/shared'; import { X, User, Lock, Shield, Fingerprint, AlertTriangle, RefreshCcw, Save } from 'lucide-react'; const COLORS = { brand: "var(--primary)", error: "var(--error)", success: "var(--success)", bg: "var(--bg-card)", text: "var(--text-main)", muted: "var(--text-muted)", }; 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: 'Error: Failed to update profile.' }); } finally { setLoading(false); } }; const handlePasswordUpdate = async (e: React.FormEvent) => { e.preventDefault(); if (securityForm.new_password !== securityForm.confirm_password) { setMessage({ type: 'error', text: 'Error: 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: 'Error: Incorrect current password.' }); } finally { setLoading(false); } }; return (
{/* Header */}
ACCOUNT SETTINGS

Account Profile

{/* Tab Navigation */}
{/* Body Content */}
{message && (
{message.type === 'success' ? : } {message.text}
)} {tab === 'profile' ? (
setProfileForm({...profileForm, full_name: e.target.value})} className="input-focus" style={{ width: '100%', padding: '18px 24px', background: 'var(--bg-dark)', borderRadius: 16, border: `1.5px solid var(--border-subtle)`, fontSize: 16, color: COLORS.text, outline: 'none', boxSizing: 'border-box', transition: 'all 0.3s', fontWeight: 500 }} />
setProfileForm({...profileForm, avatar_url: e.target.value})} placeholder="https://nexus.cdn/identity/vector.jpg" className="input-focus" style={{ width: '100%', padding: '18px 24px', background: 'var(--bg-dark)', borderRadius: 16, border: `1.5px solid var(--border-subtle)`, fontSize: 16, color: COLORS.text, outline: 'none', boxSizing: 'border-box', transition: 'all 0.3s', fontWeight: 500 }} />
) : (
setSecurityForm({...securityForm, old_password: e.target.value})} style={{ width: '100%', padding: '18px 24px', background: 'var(--bg-dark)', borderRadius: 16, border: `1.5px solid var(--border-subtle)`, fontSize: 16, color: COLORS.text, outline: 'none', boxSizing: 'border-box', transition: 'all 0.3s' }} />
setSecurityForm({...securityForm, new_password: e.target.value})} style={{ width: '100%', padding: '18px 24px', background: 'var(--bg-dark)', borderRadius: 16, border: `1.5px solid var(--border-subtle)`, fontSize: 16, color: COLORS.text, outline: 'none', boxSizing: 'border-box', transition: 'all 0.3s' }} />
setSecurityForm({...securityForm, confirm_password: e.target.value})} style={{ width: '100%', padding: '18px 24px', background: 'var(--bg-dark)', borderRadius: 16, border: `1.5px solid var(--border-subtle)`, fontSize: 16, color: COLORS.text, outline: 'none', boxSizing: 'border-box', transition: 'all 0.3s' }} />
)}
); };