Spaces:
Paused

miracle / frontend /apps /customer /src /components /UserSettingsModal.tsx
dushyantsingh0
backend stabilization
fb1a28a
Raw History Blame Contribute Delete
13.6 kB
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<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: '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 (
<div style={{
position: 'fixed',
inset: 0,
background: 'rgba(2, 6, 23, 0.65)',
backdropFilter: 'blur(16px)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 2000,
fontFamily: "var(--font-sans)"
}}>
<div className="hover-lift" style={{
width: 580,
background: "var(--bg-card)",
borderRadius: 36,
boxShadow: 'var(--shadow-2xl)',
overflow: 'hidden',
border: '1.5px solid var(--border-subtle)',
animation: 'nexus-pop-in 0.5s cubic-bezier(0.16, 1, 0.3, 1)',
position: 'relative'
}}>
<div style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '4px', background: 'var(--primary)', opacity: 0.1 }} />
{/* Header */}
<div style={{
padding: '40px 48px',
borderBottom: `1.5px solid var(--border-subtle)`,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
background: 'var(--bg-dark)'
}}>
<div>
<div className="metadata" style={{ color: "var(--primary)", marginBottom: 8, letterSpacing: '0.15em', fontWeight: 900 }}>ACCOUNT SETTINGS</div>
<h2 style={{ fontSize: 26, fontWeight: 800, color: COLORS.text, margin: 0, fontFamily: "var(--font-heading)", letterSpacing: "-0.025em" }}>Account Profile</h2>
</div>
<button
onClick={onClose}
className="hover-lift"
style={{
background: 'var(--bg-dark)',
border: '1.5px solid var(--border-subtle)',
width: 44, height: 44, borderRadius: '50%',
color: COLORS.muted, cursor: 'pointer',
display: 'flex', alignItems: 'center', justifyContent: 'center',
transition: 'all 0.3s'
}}
>
<X size={20} />
</button>
</div>
{/* Tab Navigation */}
<div style={{ display: 'flex', background: 'var(--bg-dark)', padding: '6px', margin: '24px 48px 0', borderRadius: 16, border: '1.5px solid var(--border-subtle)' }}>
<button
onClick={() => { setTab('profile'); setMessage(null); }}
style={{
flex: 1, padding: '14px', border: 'none',
background: tab === 'profile' ? "var(--bg-card)" : 'transparent',
cursor: 'pointer',
fontSize: 12, fontWeight: 800,
color: tab === 'profile' ? COLORS.brand : COLORS.muted,
borderRadius: 12, transition: 'all 0.4s cubic-bezier(0.16, 1, 0.3, 1)',
fontFamily: "var(--font-heading)", textTransform: "uppercase",
letterSpacing: "0.1em", display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
boxShadow: tab === 'profile' ? 'var(--shadow-sm)' : 'none'
}}
>
<User size={16} /> Profile Information
</button>
<button
onClick={() => { setTab('security'); setMessage(null); }}
style={{
flex: 1, padding: '14px', border: 'none',
background: tab === 'security' ? "var(--bg-card)" : 'transparent',
cursor: 'pointer',
fontSize: 12, fontWeight: 800,
color: tab === 'security' ? COLORS.brand : COLORS.muted,
borderRadius: 12, transition: 'all 0.4s cubic-bezier(0.16, 1, 0.3, 1)',
fontFamily: "var(--font-heading)", textTransform: "uppercase",
letterSpacing: "0.1em", display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
boxShadow: tab === 'security' ? 'var(--shadow-sm)' : 'none'
}}
>
<Lock size={16} /> Password & Security
</button>
</div>
{/* Body Content */}
<div style={{ padding: '32px 48px 48px' }}>
{message && (
<div style={{
padding: '18px 24px', borderRadius: 16, marginBottom: 32, fontSize: 13, fontWeight: 700,
background: message.type === 'success' ? 'rgba(16, 185, 129, 0.05)' : 'rgba(239, 68, 68, 0.05)',
color: message.type === 'success' ? COLORS.success : COLORS.error,
border: `1.5px solid ${message.type === 'success' ? 'var(--success)' : 'var(--error)'}33`,
display: 'flex', alignItems: 'center', gap: 14,
animation: 'slideIn 0.3s ease'
}}>
{message.type === 'success' ? <Shield size={18} /> : <AlertTriangle size={18} />}
<span style={{ flex: 1 }}>{message.text}</span>
</div>
)}
{tab === 'profile' ? (
<form onSubmit={handleProfileUpdate} style={{ display: 'flex', flexDirection: 'column', gap: 32 }}>
<div>
<label className="metadata" style={{ marginBottom: 12, display: 'block', fontWeight: 800, letterSpacing: '0.05em' }}>DISPLAY NAME</label>
<input
value={profileForm.full_name}
onChange={e => 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 }}
/>
</div>
<div>
<label className="metadata" style={{ marginBottom: 12, display: 'block', fontWeight: 800, letterSpacing: '0.05em' }}>AVATAR URL</label>
<input
value={profileForm.avatar_url}
onChange={e => 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 }}
/>
</div>
<button
disabled={loading}
className="hover-lift"
style={{
width: '100%', padding: '18px', background: COLORS.brand, color: 'var(--bg-card)',
border: 'none', borderRadius: 20, fontWeight: 900, cursor: 'pointer',
opacity: loading ? 0.7 : 1, marginTop: 16, fontFamily: "var(--font-heading)",
textTransform: "uppercase", letterSpacing: "0.1em", boxShadow: "0 10px 30px var(--primary-glow)",
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 12, fontSize: 15
}}
>
{loading ? <RefreshCcw size={18} className="spin" /> : <Save size={18} />}
{loading ? 'SAVING...' : 'SAVE CHANGES'}
</button>
</form>
) : (
<form onSubmit={handlePasswordUpdate} style={{ display: 'flex', flexDirection: 'column', gap: 28 }}>
<div>
<label className="metadata" style={{ marginBottom: 12, display: 'block', fontWeight: 800, letterSpacing: '0.05em' }}>CURRENT PASSWORD</label>
<input
type="password"
value={securityForm.old_password}
className="input-focus"
onChange={e => 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' }}
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24 }}>
<div>
<label className="metadata" style={{ marginBottom: 12, display: 'block', fontWeight: 800, letterSpacing: '0.05em' }}>NEW PASSWORD</label>
<input
type="password"
value={securityForm.new_password}
className="input-focus"
onChange={e => 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' }}
/>
</div>
<div>
<label className="metadata" style={{ marginBottom: 12, display: 'block', fontWeight: 800, letterSpacing: '0.05em' }}>CONFIRM PASSWORD</label>
<input
type="password"
value={securityForm.confirm_password}
className="input-focus"
onChange={e => 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' }}
/>
</div>
</div>
<button
disabled={loading}
className="hover-lift"
style={{
width: '100%', padding: '18px', background: COLORS.brand, color: 'var(--bg-card)',
border: 'none', borderRadius: 20, fontWeight: 900, cursor: 'pointer',
opacity: loading ? 0.7 : 1, marginTop: 16, fontFamily: "var(--font-heading)",
textTransform: "uppercase", letterSpacing: "0.1em", boxShadow: "0 10px 30px var(--primary-glow)",
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 12, fontSize: 15
}}
>
{loading ? <RefreshCcw size={18} className="spin" /> : <Fingerprint size={20} />}
{loading ? 'UPDATING...' : 'UPDATE PASSWORD'}
</button>
</form>
)}
</div>
</div>
<style>{`
@keyframes nexus-pop-in {
0% { transform: scale(0.95); opacity: 0; }
100% { transform: scale(1); opacity: 1; }
}
@keyframes slideIn {
from { transform: translateY(-10px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.spin { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.input-focus:focus {
border-color: var(--primary) !important;
box-shadow: 0 0 0 4px var(--primary-glow) !important;
}
`}</style>
</div>
);
};