import React, { useState, useEffect } from 'react'; import { Save, X, AlertCircle } from 'lucide-react'; interface UserProfile { id?: number; email?: string; username?: string; timezone: string; preferred_trading_start: string; preferred_trading_end: string; risk_tolerance: string; trading_style: string; daily_target?: number; max_loss?: number; notifications_enabled: boolean; email_reports: boolean; sms_enabled: boolean; push_notifications: boolean; phone_number?: string; } interface UserProfileSetupProps { onClose: () => void; onSaved?: (profile: UserProfile) => void; } const UserProfileSetup: React.FC = ({ onClose, onSaved }) => { const [profile, setProfile] = useState({ timezone: 'UTC', preferred_trading_start: '09:00', preferred_trading_end: '17:00', risk_tolerance: 'moderate', trading_style: 'day_trader', notifications_enabled: true, email_reports: true, sms_enabled: false, push_notifications: true, }); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); useEffect(() => { // Load existing profile loadProfile(); }, []); const loadProfile = async () => { try { const response = await fetch('/api/daily-helper/profile'); if (response.ok) { const data = await response.json(); setProfile(data); } } catch (err) { // Profile doesn't exist yet, start fresh console.log('Starting with default profile'); } }; const handleChange = (field: keyof UserProfile, value: any) => { setProfile(prev => ({ ...prev, [field]: value })); }; const handleSave = async () => { setLoading(true); setError(''); setSuccess(false); try { const isUpdate = profile.id; const method = isUpdate ? 'PUT' : 'POST'; const endpoint = '/api/daily-helper/profile'; const response = await fetch(endpoint, { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(profile), }); if (!response.ok) { throw new Error('Failed to save profile'); } const savedProfile = await response.json(); setProfile(savedProfile); setSuccess(true); if (onSaved) { onSaved(savedProfile); } setTimeout(() => { onClose(); }, 1500); } catch (err) { setError(err instanceof Error ? err.message : 'Error saving profile'); } finally { setLoading(false); } }; return (

User Profile Setup

{error && (

{error}

)} {success && (

✓ Profile saved successfully!

)}
{/* Email and Username */}
handleChange('email', e.target.value)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white placeholder-gray-500 focus:outline-none focus:border-blue-500" placeholder="your@email.com" />
handleChange('username', e.target.value)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white placeholder-gray-500 focus:outline-none focus:border-blue-500" placeholder="your_username" />
{/* Timezone and Trading Style */}
{/* Trading Hours */}
handleChange('preferred_trading_start', e.target.value)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white focus:outline-none focus:border-blue-500" />
handleChange('preferred_trading_end', e.target.value)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white focus:outline-none focus:border-blue-500" />
{/* Risk Profile */}
handleChange('max_loss', e.target.value ? parseFloat(e.target.value) : null)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white placeholder-gray-500 focus:outline-none focus:border-blue-500" placeholder="500" />
{/* Daily Target */}
handleChange('daily_target', e.target.value ? parseFloat(e.target.value) : null)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white placeholder-gray-500 focus:outline-none focus:border-blue-500" placeholder="1000" />
{/* Notifications Settings */}

Notification Preferences

{profile.sms_enabled && (
handleChange('phone_number', e.target.value)} className="w-full bg-gray-800 border border-gray-600 rounded px-3 py-2 text-white placeholder-gray-500 focus:outline-none focus:border-blue-500" placeholder="+1 (555) 123-4567" />
)}
{/* Action Buttons */}
); }; export default UserProfileSetup;