import { useEffect, useState } from 'react'; import { logout, getAuth } from '../lib/auth'; import { getUserProfile, getPointsBalance, type UserProfile, type PointsBalance } from '../lib/api'; interface Props { locale: string; dashboard: { brandName: string; navHome: string; navStore: string; navDivination: string; navManual: string; navAuto: string; navHistory: string; navLanguage: string; navSettings: string; logout: string }; settings: { title: string; profileTitle: string; emailLabel: string; nameLabel: string; joinedLabel: string; pointsTitle: string; pointsBalance: string; accountTitle: string; changeName: string; changeAvatar: string; changeLanguage: string; legalTitle: string; privacy: string; terms: string; logout: string; logoutConfirm: string }; } export default function SettingsPage({ locale, settings: s }: Props) { const [profile, setProfile] = useState(null); const [points, setPoints] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { setLoading(true); Promise.all([ getUserProfile(), getPointsBalance(), ]) .then(([profileData, pointsData]) => { setProfile(profileData); setPoints(pointsData); }) .catch(() => { // ignore errors }) .finally(() => setLoading(false)); }, []); const handleLogout = () => { if (confirm(s.logoutConfirm)) { logout().finally(() => { window.location.href = `/${locale}/login`; }); } }; const authEmail = getAuth()?.user?.email; const displayName = loading ? '' : (profile?.display_name || profile?.email?.split('@')[0] || authEmail?.split('@')[0] || ''); const email = loading ? '' : (profile?.email || authEmail || ''); const bio = profile?.bio || ''; return (
{/* Page Header */}

{s.title}

{locale === 'en' ? 'Manage account, preferences, and policies' : '管理账号资料、偏好与协议信息'}

verified_user {locale === 'en' ? 'Account OK' : '账号正常'}
{/* Main Content */}
{/* Left Column */}
{/* Profile Summary Card */}
{/* Avatar */} {profile?.avatar_url ? ( {displayName} ) : (
{displayName ? displayName[0].toUpperCase() : '?'}
)} {/* Name & Email */}

{loading ? '...' : (displayName || '-')}

{loading ? '...' : (email || '-')}

{/* Edit Profile Button */} edit
{/* Bio */} {bio && (

{bio}

)}
{/* Points Card */} {/* Points Icon */}
paid
{/* Points Info */}

{s.pointsTitle}

{loading ? '...' : points?.balance ?? 0} {s.pointsBalance}

{/* Arrow */} chevron_right
{/* Right Column */}
{/* Account Settings Panel */} {/* Legal Panel */} {/* Logout Button */}
); }