Spaces:
Paused
Paused
Download frontend/apps/internal/src/components/UserSettingsModal.tsx from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 10.9 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/frontend/apps/internal/src/components/UserSettingsModal.tsx
- Command line
-
hf download hf://spaces/3SCError404/nexus/frontend/apps/internal/src/components/UserSettingsModal.tsx
-
curl -L -o UserSettingsModal.tsx https://huggingface.co/spaces/3SCError404/nexus/resolve/main/frontend/apps/internal/src/components/UserSettingsModal.tsx
10.9 kB
| import React, { useState } from 'react'; | |
| import { api } from '@nexus/shared'; | |
| const COLORS = { | |
| brand: "#7C3AED", | |
| 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<UserSettingsModalProps> = ({ 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.' }); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| const handlePasswordUpdate = async (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| if (securityForm.new_password !== securityForm.confirm_password) { | |
| setMessage({ type: 'error', text: '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 changed successfully!' }); | |
| setSecurityForm({ old_password: '', new_password: '', confirm_password: '' }); | |
| } catch (err) { | |
| setMessage({ type: 'error', text: 'Incorrect current password or update failed.' }); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| return ( | |
| <div style={{ | |
| position: 'fixed', | |
| top: 0, | |
| left: 0, | |
| right: 0, | |
| bottom: 0, | |
| background: 'rgba(0,0,0,0.7)', | |
| backdropFilter: 'blur(8px)', | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'center', | |
| zIndex: 3000, | |
| animation: 'nexus-fade-in 0.2s ease-out' | |
| }}> | |
| <style> | |
| {` @keyframes nexus-fade-in { from { opacity: 0; } to { opacity: 1; } } | |
| @keyframes nexus-pop-in { from { transform: scale(0.98) translateY(10px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } } | |
| `} | |
| </style> | |
| <div style={{ | |
| width: 480, | |
| background: COLORS.card, | |
| borderRadius: 16, | |
| border: `1px solid ${COLORS.border}`, | |
| boxShadow: '0 24px 48px rgba(0,0,0,0.5)', | |
| overflow: 'hidden', | |
| animation: 'nexus-pop-in 0.3s cubic-bezier(0.16, 1, 0.3, 1)' | |
| }}> | |
| <div style={{ padding: '24px', borderBottom: `1px solid ${COLORS.border}`, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}> | |
| <div> | |
| <h2 style={{ fontSize: 18, fontWeight: 700, color: COLORS.text, margin: 0 }}>Command Settings</h2> | |
| <p style={{ fontSize: 12, color: COLORS.subtext, margin: '4px 0 0 0' }}>Manage your operational identity and security.</p> | |
| </div> | |
| <button | |
| onClick={onClose} | |
| style={{ | |
| background: 'rgba(255,255,255,0.05)', | |
| border: 'none', | |
| width: 32, | |
| height: 32, | |
| borderRadius: 8, | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'center', | |
| cursor: 'pointer', | |
| color: COLORS.subtext | |
| }} | |
| > | |
| × | |
| </button> | |
| </div> | |
| <div style={{ display: 'flex', background: 'rgba(0,0,0,0.2)', padding: '4px' }}> | |
| <button | |
| onClick={() => { setTab('profile'); setMessage(null); }} | |
| style={{ | |
| flex: 1, padding: '10px', border: 'none', background: tab === 'profile' ? 'rgba(255,255,255,0.05)' : 'none', | |
| cursor: 'pointer', borderRadius: 8, transition: '0.2s', | |
| fontSize: 13, fontWeight: 600, color: tab === 'profile' ? COLORS.text : COLORS.subtext, | |
| }} | |
| > | |
| Operational Profile | |
| </button> | |
| <button | |
| onClick={() => { setTab('security'); setMessage(null); }} | |
| style={{ | |
| flex: 1, padding: '10px', border: 'none', background: tab === 'security' ? 'rgba(255,255,255,0.05)' : 'none', | |
| cursor: 'pointer', borderRadius: 8, transition: '0.2s', | |
| fontSize: 13, fontWeight: 600, color: tab === 'security' ? COLORS.text : COLORS.subtext, | |
| }} | |
| > | |
| Access Security | |
| </button> | |
| </div> | |
| <div style={{ padding: '32px' }}> | |
| {message && ( | |
| <div style={{ | |
| padding: '12px 16px', borderRadius: 8, marginBottom: 20, fontSize: 13, fontWeight: 500, | |
| background: message.type === 'success' ? 'rgba(63, 185, 80, 0.1)' : 'rgba(248, 81, 73, 0.1)', | |
| color: message.type === 'success' ? COLORS.success : COLORS.error, | |
| border: `1px solid ${message.type === 'success' ? 'rgba(63, 185, 80, 0.2)' : 'rgba(248, 81, 73, 0.2)'}` | |
| }}> | |
| {message.text} | |
| </div> | |
| )} | |
| {tab === 'profile' ? ( | |
| <form onSubmit={handleProfileUpdate}> | |
| <div style={{ marginBottom: 20 }}> | |
| <label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: COLORS.subtext, marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>Full Operational Name</label> | |
| <input | |
| value={profileForm.full_name} | |
| onChange={e => setProfileForm({...profileForm, full_name: e.target.value})} | |
| style={{ | |
| width: '100%', padding: '12px', borderRadius: 8, | |
| background: '#0D1117', border: `1px solid ${COLORS.border}`, | |
| color: COLORS.text, fontSize: 14, outline: 'none' | |
| }} | |
| /> | |
| </div> | |
| <div style={{ marginBottom: 32 }}> | |
| <label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: COLORS.subtext, marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>Avatar Manifest URL</label> | |
| <input | |
| value={profileForm.avatar_url} | |
| onChange={e => setProfileForm({...profileForm, avatar_url: e.target.value})} | |
| placeholder="https://nexus.ai/assets/avatar.png" | |
| style={{ | |
| width: '100%', padding: '12px', borderRadius: 8, | |
| background: '#0D1117', border: `1px solid ${COLORS.border}`, | |
| color: COLORS.text, fontSize: 14, outline: 'none' | |
| }} | |
| /> | |
| </div> | |
| <button | |
| disabled={loading} | |
| style={{ | |
| width: '100%', padding: '14px', background: COLORS.brand, color: '#fff', | |
| border: 'none', borderRadius: 8, fontWeight: 600, cursor: 'pointer', | |
| opacity: loading ? 0.7 : 1, transition: '0.2s', boxShadow: '0 4px 12px rgba(124, 58, 237, 0.3)' | |
| }} | |
| > | |
| {loading ? 'Processing Sync...' : 'Commit Profile Changes'} | |
| </button> | |
| </form> | |
| ) : ( | |
| <form onSubmit={handlePasswordUpdate}> | |
| <div style={{ marginBottom: 16 }}> | |
| <label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: COLORS.subtext, marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>Current Credentials</label> | |
| <input | |
| type="password" | |
| value={securityForm.old_password} | |
| onChange={e => setSecurityForm({...securityForm, old_password: e.target.value})} | |
| style={{ | |
| width: '100%', padding: '12px', borderRadius: 8, | |
| background: '#0D1117', border: `1px solid ${COLORS.border}`, | |
| color: COLORS.text, fontSize: 14, outline: 'none' | |
| }} | |
| /> | |
| </div> | |
| <div style={{ marginBottom: 16 }}> | |
| <label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: COLORS.subtext, marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>New Access Key</label> | |
| <input | |
| type="password" | |
| value={securityForm.new_password} | |
| onChange={e => setSecurityForm({...securityForm, new_password: e.target.value})} | |
| style={{ | |
| width: '100%', padding: '12px', borderRadius: 8, | |
| background: '#0D1117', border: `1px solid ${COLORS.border}`, | |
| color: COLORS.text, fontSize: 14, outline: 'none' | |
| }} | |
| /> | |
| </div> | |
| <div style={{ marginBottom: 32 }}> | |
| <label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: COLORS.subtext, marginBottom: 8, textTransform: 'uppercase', letterSpacing: '0.05em' }}>Re-verify Access Key</label> | |
| <input | |
| type="password" | |
| value={securityForm.confirm_password} | |
| onChange={e => setSecurityForm({...securityForm, confirm_password: e.target.value})} | |
| style={{ | |
| width: '100%', padding: '12px', borderRadius: 8, | |
| background: '#0D1117', border: `1px solid ${COLORS.border}`, | |
| color: COLORS.text, fontSize: 14, outline: 'none' | |
| }} | |
| /> | |
| </div> | |
| <button | |
| disabled={loading} | |
| style={{ | |
| width: '100%', padding: '14px', background: COLORS.brand, color: '#fff', | |
| border: 'none', borderRadius: 8, fontWeight: 600, cursor: 'pointer', | |
| opacity: loading ? 0.7 : 1, transition: '0.2s', boxShadow: '0 4px 12px rgba(124, 58, 237, 0.3)' | |
| }} | |
| > | |
| {loading ? 'Encrypting Access...' : 'Rotate Credentials'} | |
| </button> | |
| </form> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| }; | |