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 (
{locale === 'en' ? 'Manage account, preferences, and policies' : '管理账号资料、偏好与协议信息'}
{loading ? '...' : (displayName || '-')}
{loading ? '...' : (email || '-')}
{bio}
)}{s.pointsTitle}
{loading ? '...' : points?.balance ?? 0} {s.pointsBalance}
{locale === 'en' ? 'General' : '通用设置'}
{locale === 'en' ? 'Language, notifications' : '语言、通知'}
{locale === 'en' ? 'Feedback' : '意见反馈'}
{locale === 'en' ? 'Submit suggestions' : '提交问题与建议'}
{locale === 'en' ? 'Account Data' : '账号数据'}
{locale === 'en' ? 'Profile information' : '账号信息'}