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
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import type { JSX } from "react"
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
@@ -9,15 +11,16 @@ export default function ParentGradesError({
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}) {
|
||||
}): JSX.Element {
|
||||
const t = useTranslations("grades")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="子女成绩页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
title={t("page.error.title")}
|
||||
description={t("page.error.description")}
|
||||
action={{
|
||||
label: "重试",
|
||||
label: t("page.error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { JSX } from "react"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
export default function Loading(): JSX.Element {
|
||||
return (
|
||||
<div className="space-y-8 p-6 md:p-8">
|
||||
<div className="space-y-2">
|
||||
|
||||
@@ -2,15 +2,17 @@ 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 { getStudentGrowthArchive } from "@/modules/grades/data-access-analytics"
|
||||
import { StudentGradeSummary } from "@/modules/grades/components/student-grade-summary"
|
||||
import { GradeTrendCard } from "@/modules/grades/components/grade-trend-card"
|
||||
import { GrowthArchiveChart } from "@/modules/grades/components/growth-archive-chart"
|
||||
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"
|
||||
import type { ClassAverageTrendResult, StudentGrowthArchiveResult } from "@/modules/grades/types"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -19,6 +21,7 @@ interface ChildGradeItem {
|
||||
studentId: string
|
||||
summary: NonNullable<Awaited<ReturnType<typeof getStudentGradeSummary>>>
|
||||
classAverageTrend: ClassAverageTrendResult | null
|
||||
growthArchive: StudentGrowthArchiveResult | null
|
||||
}
|
||||
|
||||
export default async function ParentGradesPage() {
|
||||
@@ -40,29 +43,24 @@ export default async function ParentGradesPage() {
|
||||
// 使用 allSettled 容错:单个子女查询失败不影响其他子女展示
|
||||
const results = await Promise.allSettled(
|
||||
ctx.dataScope.childrenIds.map(async (id) => {
|
||||
const [summary, classAverageTrend] = await Promise.all([
|
||||
const [summary, classAverageTrend, growthArchive] = await Promise.all([
|
||||
getStudentGradeSummary(id, ctx.dataScope),
|
||||
// v3-P2-8:家长页面补齐趋势图,复用班级平均对比线
|
||||
getClassAverageTrend(id, undefined, undefined, ctx.dataScope),
|
||||
// P3-4:子女纵向成长档案
|
||||
getStudentGrowthArchive(id, ctx.dataScope),
|
||||
])
|
||||
return { summary, classAverageTrend, studentId: id }
|
||||
return { summary, classAverageTrend, growthArchive, studentId: id }
|
||||
}),
|
||||
)
|
||||
const validItems: ChildGradeItem[] = results
|
||||
.filter(
|
||||
(
|
||||
r,
|
||||
): r is PromiseFulfilledResult<{
|
||||
summary: Awaited<ReturnType<typeof getStudentGradeSummary>>
|
||||
classAverageTrend: ClassAverageTrendResult | null
|
||||
studentId: string
|
||||
}> => r.status === "fulfilled" && r.value.summary !== null,
|
||||
)
|
||||
.map((r) => ({
|
||||
studentId: r.value.studentId,
|
||||
summary: r.value.summary as NonNullable<typeof r.value.summary>,
|
||||
classAverageTrend: r.value.classAverageTrend,
|
||||
}))
|
||||
// P1-8 修复:用循环 + 类型守卫替代 `as` 断言
|
||||
const validItems: ChildGradeItem[] = []
|
||||
for (const r of results) {
|
||||
if (r.status !== "fulfilled") continue
|
||||
const { summary, classAverageTrend, growthArchive, studentId } = r.value
|
||||
if (summary === null) continue
|
||||
validItems.push({ studentId, summary, classAverageTrend, growthArchive })
|
||||
}
|
||||
|
||||
return (
|
||||
<ParentChildrenDataPage
|
||||
@@ -72,7 +70,7 @@ export default async function ParentGradesPage() {
|
||||
noRecordsTitle={t("parent.noGrades")}
|
||||
noRecordsDescription={t("parent.noGradesDesc")}
|
||||
items={validItems}
|
||||
renderItem={({ studentId, summary, classAverageTrend }) => (
|
||||
renderItem={({ studentId, summary, classAverageTrend, growthArchive }) => (
|
||||
<>
|
||||
<div className="flex items-center justify-between border-b pb-2">
|
||||
<h3 className="text-lg font-semibold">{summary.studentName}</h3>
|
||||
@@ -82,6 +80,8 @@ export default async function ParentGradesPage() {
|
||||
{summary.records.length > 0 && (
|
||||
<GradeTrendCard summary={summary} classAverageData={classAverageTrend} />
|
||||
)}
|
||||
{/* P3-4:子女纵向成长档案 */}
|
||||
<GrowthArchiveChart data={growthArchive} />
|
||||
<StudentGradeSummary summary={summary} />
|
||||
</>
|
||||
)}
|
||||
|
||||
35
src/app/(dashboard)/parent/grades/report-card/error.tsx
Normal file
35
src/app/(dashboard)/parent/grades/report-card/error.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import type { JSX } from "react"
|
||||
import { useEffect } from "react"
|
||||
import { AlertTriangle } from "lucide-react"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
export default function Error({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}): JSX.Element {
|
||||
const t = useTranslations("grades")
|
||||
useEffect(() => {
|
||||
console.error("[ReportCard] Route error:", error)
|
||||
}, [error])
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-4 p-12">
|
||||
<AlertTriangle className="h-10 w-10 text-destructive" aria-hidden="true" />
|
||||
<div className="text-center">
|
||||
<h2 className="text-lg font-semibold">{t("reportCard.errorTitle")}</h2>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
{t("reportCard.errorDescription")}
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={reset} variant="outline">
|
||||
{t("reportCard.retry")}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
12
src/app/(dashboard)/parent/grades/report-card/loading.tsx
Normal file
12
src/app/(dashboard)/parent/grades/report-card/loading.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Loader2 } from "lucide-react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
export default async function Loading() {
|
||||
const t = await getTranslations("grades")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-3 p-12">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" aria-hidden="true" />
|
||||
<p className="text-sm text-muted-foreground">{t("reportCard.loading")}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
116
src/app/(dashboard)/parent/grades/report-card/page.tsx
Normal file
116
src/app/(dashboard)/parent/grades/report-card/page.tsx
Normal file
@@ -0,0 +1,116 @@
|
||||
import type { JSX } from "react"
|
||||
import { ArrowLeft } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
|
||||
import { getReportCardData } from "@/modules/grades/lib/report-card"
|
||||
import { ReportCardView } from "@/modules/grades/components/report-card-view"
|
||||
import { ReportCardPrintAction } from "@/modules/grades/components/report-card-print-action"
|
||||
import { getAcademicYears } from "@/modules/school/data-access"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
/**
|
||||
* P3-1: 家长视角的子女成绩报告卡页面。
|
||||
*
|
||||
* 路由:/parent/grades/report-card?studentId=xxx
|
||||
* 查询参数:
|
||||
* - studentId: 必填,目标学生 ID(必须在家长子女范围内)
|
||||
* - academicYearId?: 指定学年
|
||||
* - semester?: "1" | "2"
|
||||
*
|
||||
* 权限:GRADE_RECORD_READ(children scope 在 data-access 层校验子女归属)
|
||||
*/
|
||||
export default async function ParentReportCardPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
const sp = await searchParams
|
||||
const ctx = await requirePermission(Permissions.GRADE_RECORD_READ)
|
||||
const t = await getTranslations("grades")
|
||||
|
||||
const studentId = getParam(sp, "studentId")
|
||||
const academicYearIdParam = getParam(sp, "academicYearId")
|
||||
const semesterParam = getParam(sp, "semester")
|
||||
const academicYearId =
|
||||
academicYearIdParam && academicYearIdParam !== "all"
|
||||
? academicYearIdParam
|
||||
: undefined
|
||||
const semester =
|
||||
semesterParam === "1" || semesterParam === "2" ? semesterParam : undefined
|
||||
|
||||
if (!studentId) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-6 p-8 md:flex">
|
||||
<Button asChild variant="ghost" size="sm" className="w-fit">
|
||||
<Link href="/parent/grades">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
{t("reportCard.backToGrades")}
|
||||
</Link>
|
||||
</Button>
|
||||
<EmptyState
|
||||
title={t("reportCard.missingStudentTitle")}
|
||||
description={t("reportCard.missingStudentDescription")}
|
||||
icon={ArrowLeft}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const [data, academicYears] = await Promise.all([
|
||||
getReportCardData(studentId, ctx.dataScope, {
|
||||
academicYearId,
|
||||
semester,
|
||||
}),
|
||||
getAcademicYears(),
|
||||
])
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-6 p-8 md:flex">
|
||||
<Button asChild variant="ghost" size="sm" className="w-fit">
|
||||
<Link href="/parent/grades">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
{t("reportCard.backToGrades")}
|
||||
</Link>
|
||||
</Button>
|
||||
<EmptyState
|
||||
title={t("reportCard.emptyTitle")}
|
||||
description={t("reportCard.emptyDescription")}
|
||||
icon={ArrowLeft}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 p-6">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<Button asChild variant="ghost" size="sm">
|
||||
<Link href="/parent/grades">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||
{t("reportCard.backToGrades")}
|
||||
</Link>
|
||||
</Button>
|
||||
<ReportCardPrintAction />
|
||||
</div>
|
||||
|
||||
<ReportCardView data={data} />
|
||||
|
||||
<p className="text-center text-xs text-muted-foreground">
|
||||
{t("reportCard.academicYearsCount", {
|
||||
count: academicYears.length,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user