import { useState } from 'react'; import { logout, getAuth, clearAuth, redirectToLogin } from '../lib/auth'; import { usePoints, useProfile } from '../lib/resources'; 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 profileState = useProfile(); const pointsState = usePoints(); const profile = profileState.data ?? null; const points = pointsState.data ?? null; const loading = profileState.loading || pointsState.loading; const [logoutLoading, setLogoutLoading] = useState(false); const handleLogout = async () => { if (logoutLoading) return; if (!confirm(s.logoutConfirm)) return; setLogoutLoading(true); try { // Call backend logout first (needs auth) await logout(); } catch { // Ignore logout API errors } // Clear local auth and redirect clearAuth(); redirectToLogin(); }; const authEmail = getAuth()?.user?.email; const displayName = loading ? '' : (profile?.display_name || authEmail?.split('@')[0] || ''); const email = loading ? '' : (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 */}

{s.accountTitle}

{/* General Settings */} tune

{locale === 'en' ? 'General' : '通用设置'}

{locale === 'en' ? 'Language, notifications' : '语言、通知'}

{/* Feedback */} feedback

{locale === 'en' ? 'Feedback' : '意见反馈'}

{locale === 'en' ? 'Submit suggestions' : '提交问题与建议'}

{/* Account Data */} person

{locale === 'en' ? 'Account Data' : '账号数据'}

{locale === 'en' ? 'Profile information' : '账号信息'}

{/* Legal Panel */}

{s.legalTitle}

{/* About */} info

{locale === 'en' ? 'About' : '关于我们'}

{locale === 'en' ? 'Product vision' : '产品理念与定位'}

{/* Privacy */} security

{s.privacy}

{locale === 'en' ? 'Privacy policy' : '隐私保护说明'}

{/* Terms */} description

{s.terms}

{locale === 'en' ? 'User agreement' : '用户服务协议'}

{/* Logout Button */}
); }