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
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getStudentGradeSummary } from "@/modules/grades/data-access"
|
||||
import { getClassAverageTrend } from "@/modules/grades/data-access-ranking"
|
||||
import { StudentGradeSummary } from "@/modules/grades/components/student-grade-summary"
|
||||
import { GradeTrendCard } from "@/modules/grades/components/grade-trend-card"
|
||||
import {
|
||||
ParentChildrenDataPage,
|
||||
ParentNoChildrenPage,
|
||||
} from "@/modules/parent/components/parent-children-data-page"
|
||||
import { ParentExportButton } from "@/modules/parent/components/parent-export-button"
|
||||
import { GraduationCap } from "lucide-react"
|
||||
import type { ClassAverageTrendResult } from "@/modules/grades/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
interface ChildGradeItem {
|
||||
studentId: string
|
||||
summary: NonNullable<Awaited<ReturnType<typeof getStudentGradeSummary>>>
|
||||
classAverageTrend: ClassAverageTrendResult | null
|
||||
}
|
||||
|
||||
export default async function ParentGradesPage() {
|
||||
const ctx = await getAuthContext()
|
||||
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
|
||||
|
||||
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
|
||||
return (
|
||||
@@ -26,26 +37,49 @@ export default async function ParentGradesPage() {
|
||||
|
||||
// 使用 allSettled 容错:单个子女查询失败不影响其他子女展示
|
||||
const results = await Promise.allSettled(
|
||||
ctx.dataScope.childrenIds.map((id) => getStudentGradeSummary(id)),
|
||||
ctx.dataScope.childrenIds.map(async (id) => {
|
||||
const [summary, classAverageTrend] = await Promise.all([
|
||||
getStudentGradeSummary(id, ctx.dataScope),
|
||||
// v3-P2-8:家长页面补齐趋势图,复用班级平均对比线
|
||||
getClassAverageTrend(id, undefined, undefined, ctx.dataScope),
|
||||
])
|
||||
return { summary, classAverageTrend, studentId: id }
|
||||
}),
|
||||
)
|
||||
const validSummaries = results
|
||||
const validItems: ChildGradeItem[] = results
|
||||
.filter(
|
||||
(r): r is PromiseFulfilledResult<NonNullable<Awaited<ReturnType<typeof getStudentGradeSummary>>>> =>
|
||||
r.status === "fulfilled" && r.value !== null,
|
||||
(
|
||||
r,
|
||||
): r is PromiseFulfilledResult<{
|
||||
summary: Awaited<ReturnType<typeof getStudentGradeSummary>>
|
||||
classAverageTrend: ClassAverageTrendResult | null
|
||||
studentId: string
|
||||
}> => r.status === "fulfilled" && r.value.summary !== null,
|
||||
)
|
||||
.map((r) => r.value)
|
||||
.map((r) => ({
|
||||
studentId: r.value.studentId,
|
||||
summary: r.value.summary as NonNullable<typeof r.value.summary>,
|
||||
classAverageTrend: r.value.classAverageTrend,
|
||||
}))
|
||||
|
||||
return (
|
||||
<ParentChildrenDataPage
|
||||
title="Children Grades"
|
||||
description="View your children's grade records."
|
||||
description="Compare grades across all your children. For single-child analysis, open the child's detail page."
|
||||
icon={GraduationCap}
|
||||
noRecordsTitle="No grade records"
|
||||
noRecordsDescription="Your children don't have any grade records yet."
|
||||
items={validSummaries}
|
||||
renderItem={(summary) => (
|
||||
items={validItems}
|
||||
renderItem={({ studentId, summary, classAverageTrend }) => (
|
||||
<>
|
||||
<h3 className="text-lg font-semibold border-b pb-2">{summary.studentName}</h3>
|
||||
<div className="flex items-center justify-between border-b pb-2">
|
||||
<h3 className="text-lg font-semibold">{summary.studentName}</h3>
|
||||
{/* v4-P1-12: 接入 exportGradesAction,支持按 studentId 导出 */}
|
||||
<ParentExportButton studentId={studentId} studentName={summary.studentName} />
|
||||
</div>
|
||||
{summary.records.length > 0 && (
|
||||
<GradeTrendCard summary={summary} classAverageData={classAverageTrend} />
|
||||
)}
|
||||
<StudentGradeSummary summary={summary} />
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user