Spaces:
Paused
Paused
Download frontend/apps/internal/src/components/UserSettingsModal.tsx from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 16.1 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/frontend/apps/internal/src/components/UserSettingsModal.tsx
- Command line
-
hf download hf://spaces/3SCError404/miracle/frontend/apps/internal/src/components/UserSettingsModal.tsx
-
curl -L -o UserSettingsModal.tsx https://huggingface.co/spaces/3SCError404/miracle/resolve/main/frontend/apps/internal/src/components/UserSettingsModal.tsx
16.1 kB
| 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<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. 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 ( | |
| <div style={{ | |
| position: 'fixed', | |
| top: 0, left: 0, right: 0, bottom: 0, | |
| background: 'rgba(5, 5, 5, 0.6)', | |
| backdropFilter: 'blur(20px) saturate(180%)', | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'center', | |
| zIndex: 4000, | |
| }}> | |
| <motion.div | |
| initial={{ opacity: 0, scale: 0.95, y: 20 }} | |
| animate={{ opacity: 1, scale: 1, y: 0 }} | |
| exit={{ opacity: 0, scale: 0.95, y: 20 }} | |
| transition={{ type: 'spring', damping: 30, stiffness: 300 }} | |
| style={{ | |
| width: 520, | |
| background: 'rgba(22, 27, 34, 0.95)', | |
| borderRadius: 32, | |
| border: `1px solid ${COLORS.border}`, | |
| boxShadow: '0 40px 100px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,255,255,0.05)', | |
| overflow: 'hidden', | |
| display: 'flex', | |
| flexDirection: 'column', | |
| position: 'relative' | |
| }} | |
| > | |
| {/* Glow Effect */} | |
| <div style={{ | |
| position: 'absolute', | |
| top: -100, | |
| right: -100, | |
| width: 250, | |
| height: 250, | |
| background: 'radial-gradient(circle, rgba(124, 58, 237, 0.15) 0%, transparent 70%)', | |
| pointerEvents: 'none' | |
| }} /> | |
| {/* Header */} | |
| <div style={{ padding: '40px 40px 24px', position: 'relative' }}> | |
| <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}> | |
| <div> | |
| <div style={{ | |
| fontSize: 10, fontWeight: 950, color: COLORS.brandLight, | |
| letterSpacing: '0.2em', marginBottom: 12, display: 'flex', alignItems: 'center', gap: 8 | |
| }}> | |
| <Shield size={12} /> IDENTITY CONFIGURATION | |
| </div> | |
| <h2 style={{ fontSize: 28, fontWeight: 900, color: COLORS.text, margin: 0, letterSpacing: '-0.02em' }}>User Settings</h2> | |
| <p style={{ fontSize: 14, color: COLORS.subtext, margin: '8px 0 0 0', fontWeight: 500 }}>Manage your profile and account security.</p> | |
| </div> | |
| <button | |
| onClick={onClose} | |
| style={{ | |
| background: 'rgba(255,255,255,0.05)', border: 'none', | |
| width: 36, height: 36, borderRadius: 12, display: 'flex', | |
| alignItems: 'center', justifyContent: 'center', cursor: 'pointer', | |
| color: COLORS.subtext, transition: '0.2s' | |
| }} | |
| onMouseEnter={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,0.1)')} | |
| onMouseLeave={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,0.05)')} | |
| > | |
| <X size={20} /> | |
| </button> | |
| </div> | |
| </div> | |
| {/* Tabs */} | |
| <div style={{ padding: '0 40px', marginBottom: 32 }}> | |
| <div style={{ | |
| display: 'flex', background: 'rgba(0,0,0,0.2)', padding: '6px', | |
| borderRadius: 16, border: `1px solid ${COLORS.border}` | |
| }}> | |
| <button | |
| onClick={() => { setTab('profile'); setMessage(null); }} | |
| style={{ | |
| flex: 1, padding: '12px', border: 'none', | |
| background: tab === 'profile' ? 'rgba(255,255,255,0.08)' : 'transparent', | |
| cursor: 'pointer', borderRadius: 12, transition: '0.3s cubic-bezier(0.16, 1, 0.3, 1)', | |
| fontSize: 13, fontWeight: 700, color: tab === 'profile' ? COLORS.text : COLORS.subtext, | |
| display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10, | |
| boxShadow: tab === 'profile' ? '0 4px 12px rgba(0,0,0,0.2)' : 'none' | |
| }} | |
| > | |
| <User size={14} /> User Profile | |
| </button> | |
| <button | |
| onClick={() => { setTab('security'); setMessage(null); }} | |
| style={{ | |
| flex: 1, padding: '12px', border: 'none', | |
| background: tab === 'security' ? 'rgba(255,255,255,0.08)' : 'transparent', | |
| cursor: 'pointer', borderRadius: 12, transition: '0.3s cubic-bezier(0.16, 1, 0.3, 1)', | |
| fontSize: 13, fontWeight: 700, color: tab === 'security' ? COLORS.text : COLORS.subtext, | |
| display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10, | |
| boxShadow: tab === 'security' ? '0 4px 12px rgba(0,0,0,0.2)' : 'none' | |
| }} | |
| > | |
| <Key size={14} /> Security | |
| </button> | |
| </div> | |
| </div> | |
| <div style={{ padding: '0 40px 48px' }}> | |
| <AnimatePresence mode="wait"> | |
| {message && ( | |
| <motion.div | |
| initial={{ opacity: 0, height: 0, marginBottom: 0 }} | |
| animate={{ opacity: 1, height: 'auto', marginBottom: 24 }} | |
| exit={{ opacity: 0, height: 0, marginBottom: 0 }} | |
| style={{ | |
| padding: '14px 18px', borderRadius: 16, fontSize: 13, fontWeight: 600, | |
| background: message.type === 'success' ? 'rgba(63, 185, 80, 0.08)' : 'rgba(248, 81, 73, 0.08)', | |
| 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)'}`, | |
| display: 'flex', alignItems: 'center', gap: 10 | |
| }} | |
| > | |
| {message.type === 'success' ? <Check size={16} /> : <AlertCircle size={16} />} | |
| {message.text} | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| {tab === 'profile' ? ( | |
| <motion.form | |
| key="profile" | |
| initial={{ opacity: 0, x: -10 }} | |
| animate={{ opacity: 1, x: 0 }} | |
| exit={{ opacity: 0, x: 10 }} | |
| onSubmit={handleProfileUpdate} | |
| > | |
| <div style={{ marginBottom: 24 }}> | |
| <label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 11, fontWeight: 800, color: COLORS.subtext, marginBottom: 12, textTransform: 'uppercase', letterSpacing: '0.1em' }}> | |
| <User size={12} /> Full Name | |
| </label> | |
| <input | |
| value={profileForm.full_name} | |
| onChange={e => 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)} | |
| /> | |
| </div> | |
| <div style={{ marginBottom: 40 }}> | |
| <label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 11, fontWeight: 800, color: COLORS.subtext, marginBottom: 12, textTransform: 'uppercase', letterSpacing: '0.1em' }}> | |
| <Camera size={12} /> Avatar 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: '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)} | |
| /> | |
| </div> | |
| <motion.button | |
| whileHover={{ scale: 1.01, translateY: -2 }} | |
| whileTap={{ scale: 0.99 }} | |
| disabled={loading} | |
| style={{ | |
| width: '100%', padding: '18px', background: COLORS.brand, color: '#fff', | |
| border: 'none', borderRadius: 18, fontWeight: 800, cursor: 'pointer', | |
| opacity: loading ? 0.7 : 1, transition: '0.3s cubic-bezier(0.16, 1, 0.3, 1)', | |
| boxShadow: `0 20px 40px ${COLORS.brand}40`, | |
| fontSize: 15, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10 | |
| }} | |
| > | |
| {loading ? <Loader2 size={18} className="nexus-spin" /> : <Check size={18} />} | |
| {loading ? 'Updating...' : 'Save Changes'} | |
| </motion.button> | |
| </motion.form> | |
| ) : ( | |
| <motion.form | |
| key="security" | |
| initial={{ opacity: 0, x: -10 }} | |
| animate={{ opacity: 1, x: 0 }} | |
| exit={{ opacity: 0, x: 10 }} | |
| onSubmit={handlePasswordUpdate} | |
| > | |
| <div style={{ marginBottom: 20 }}> | |
| <label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 11, fontWeight: 800, color: COLORS.subtext, marginBottom: 12, textTransform: 'uppercase', letterSpacing: '0.1em' }}> | |
| <Key size={12} /> Current Password | |
| </label> | |
| <input | |
| type="password" | |
| value={securityForm.old_password} | |
| onChange={e => 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)} | |
| /> | |
| </div> | |
| <div style={{ marginBottom: 20 }}> | |
| <label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 11, fontWeight: 800, color: COLORS.subtext, marginBottom: 12, textTransform: 'uppercase', letterSpacing: '0.1em' }}> | |
| <Shield size={12} /> New Password | |
| </label> | |
| <input | |
| type="password" | |
| value={securityForm.new_password} | |
| onChange={e => 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)} | |
| /> | |
| </div> | |
| <div style={{ marginBottom: 40 }}> | |
| <label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 11, fontWeight: 800, color: COLORS.subtext, marginBottom: 12, textTransform: 'uppercase', letterSpacing: '0.1em' }}> | |
| Confirm New Password | |
| </label> | |
| <input | |
| type="password" | |
| value={securityForm.confirm_password} | |
| onChange={e => 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)} | |
| /> | |
| </div> | |
| <motion.button | |
| whileHover={{ scale: 1.01, translateY: -2 }} | |
| whileTap={{ scale: 0.99 }} | |
| disabled={loading} | |
| style={{ | |
| width: '100%', padding: '18px', background: COLORS.brand, color: '#fff', | |
| border: 'none', borderRadius: 18, fontWeight: 800, cursor: 'pointer', | |
| opacity: loading ? 0.7 : 1, transition: '0.3s cubic-bezier(0.16, 1, 0.3, 1)', | |
| boxShadow: `0 20px 40px ${COLORS.brand}40`, | |
| fontSize: 15, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10 | |
| }} | |
| > | |
| {loading ? <Loader2 size={18} className="nexus-spin" /> : <Shield size={18} />} | |
| {loading ? 'Updating...' : 'Update Password'} | |
| </motion.button> | |
| </motion.form> | |
| )} | |
| </div> | |
| </motion.div> | |
| <style>{` | |
| .nexus-spin { animation: nexus-spin-anim 1s linear infinite; } | |
| @keyframes nexus-spin-anim { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } | |
| `}</style> | |
| </div> | |
| ); | |
| }; | |