Files
NextEdu/src/app/(dashboard)/settings/page.tsx
SpecialX 1a9377222c feat(app): add error/loading boundaries and update dashboard routes
- Add error.tsx and loading.tsx boundaries for admin, parent, student, teacher routes

- Add dashboard-error-fallback and dashboard-loading-skeleton components

- Add student/learning page, parent/leave routes, teacher textbook components

- Update existing app routes across auth, dashboard, and API endpoints

- Update proxy middleware and next-auth type declarations
2026-06-23 17:38:28 +08:00

68 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { redirect } from "next/navigation"
import { getTranslations } from "next-intl/server"
import { headers } from "next/headers"
import { requireAuth } from "@/shared/lib/auth-guard"
import { SettingsView } from "@/modules/settings/components/settings-view"
import { SettingsServiceProvider } from "@/modules/settings/components/settings-service-context"
import { resolveRoleSettingsConfig } from "@/modules/settings/config/role-settings-config"
import type { SettingsService } from "@/modules/settings/types"
import {
updateProfileAction,
updateNotificationPreferencesAction,
} from "@/modules/settings/actions-service"
import { getUserProfile } from "@/modules/users/data-access"
import { getNotificationPreferences } from "@/modules/notifications/preferences"
export const dynamic = "force-dynamic"
export const metadata = {
title: "Settings",
}
export default async function SettingsPage() {
const ctx = await requireAuth()
const userId = ctx.userId
const userProfile = await getUserProfile(userId)
if (!userProfile) redirect("/login")
const roles = ctx.roles
const notificationPrefs = await getNotificationPreferences(userId)
const t = await getTranslations("settings")
// 获取当前请求的 User-Agent用于安全中心标记当前会话
const headerList = await headers()
const currentUserAgent = headerList.get("user-agent") ?? ""
const config = resolveRoleSettingsConfig(roles)
const description = t(config?.descriptionKey ?? "title")
const backHref = config?.backHref ?? "/dashboard"
const generalExtra = config?.generalExtra
// 构建 SettingsService仅传递 Server Action 引用
// Next.js 要求传递给 Client Component 的函数必须是 "use server" 标记的 Server Action
const service: SettingsService = {
profile: {
updateProfile: updateProfileAction,
},
notifications: {
updatePreferences: updateNotificationPreferencesAction,
},
}
return (
<SettingsServiceProvider service={service}>
<SettingsView
description={description}
backHref={backHref}
user={userProfile}
notificationPreferences={notificationPrefs}
generalExtra={generalExtra}
currentUserAgent={currentUserAgent}
/>
</SettingsServiceProvider>
)
}