Files
NextEdu/src/app/(dashboard)/settings/page.tsx
SpecialX 21142f9b99 feat(app): add error/loading boundaries across all dashboard routes and new routes
- Add error.tsx and loading.tsx boundaries for admin, parent, student, teacher routes

- Add admin announcements edit, audit-logs overview, curriculum-map, invitation-codes, permissions, questions, roles routes

- Add admin elective detail and components, files, course-plans, users, scheduling boundaries

- Add messages group-compose route

- Add parent course-plans, elective, grades report-card, practice routes

- Add student course-plans, elective detail, error-book dialogs, grades report-card, learning study-path, leave, schedule boundaries

- Add teacher attendance report, classes boundaries, course-plans boundaries, elective, exams analytics/edit-rich/all/create/new, grades report-card, homework boundaries, leave, lesson-plans calendar

- Add auth loading, onboarding loading, api cron
2026-07-03 10:26:25 +08:00

69 lines
2.3 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 async function generateMetadata() {
const t = await getTranslations("settings")
return { title: t("title") }
}
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>
)
}