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:
SpecialX
2026-07-03 10:26:25 +08:00
parent e9a5264fe7
commit 21142f9b99
280 changed files with 7137 additions and 1855 deletions

View File

@@ -1,18 +1,27 @@
import type { JSX } from "react"
import { Suspense } from "react"
import type { ReactNode } from "react"
import Link from "next/link"
import { notFound } from "next/navigation"
import { getHomeworkAssignmentAnalytics } from "@/modules/homework/data-access"
import { getHomeworkAssignmentAnalytics } from "@/modules/homework/stats-service"
import { HomeworkAssignmentExamContentCard } from "@/modules/homework/components/homework-assignment-exam-content-card"
import { HomeworkAssignmentQuestionErrorOverviewCard } from "@/modules/homework/components/homework-assignment-question-error-overview-card"
import { Badge } from "@/shared/components/ui/badge"
import { Button } from "@/shared/components/ui/button"
import { Skeleton } from "@/shared/components/ui/skeleton"
import { SectionErrorBoundary } from "@/shared/components/section-error-boundary"
import { formatDate } from "@/shared/lib/utils"
import { ArrowLeft, Users, Calendar, BarChart3, CheckCircle2 } from "lucide-react"
import { requirePermission } from "@/shared/lib/auth-guard"
import { getTranslations } from "next-intl/server"
import { Permissions } from "@/shared/types/permissions"
export const dynamic = "force-dynamic"
export default async function HomeworkAssignmentDetailPage({ params }: { params: Promise<{ id: string }> }): Promise<JSX.Element> {
const { id } = await params
await requirePermission(Permissions.HOMEWORK_CREATE)
const t = await getTranslations("examHomework")
const analytics = await getHomeworkAssignmentAnalytics(id)
if (!analytics) return notFound()
@@ -28,7 +37,7 @@ export default async function HomeworkAssignmentDetailPage({ params }: { params:
<Button asChild variant="ghost" size="sm" className="w-fit">
<Link href="/teacher/homework/assignments">
<ArrowLeft className="mr-2 h-4 w-4" aria-hidden="true" />
{t("homework.result.backToList")}
</Link>
</Button>
<div className="flex items-center gap-3">
@@ -37,14 +46,14 @@ export default async function HomeworkAssignmentDetailPage({ params }: { params:
{assignment.status}
</Badge>
</div>
<p className="text-muted-foreground text-sm max-w-2xl">{assignment.description || "No description provided."}</p>
<p className="text-muted-foreground text-sm max-w-2xl">{assignment.description || t("homework.take.noDescription")}</p>
</div>
<div className="flex items-center gap-3 mt-2 md:mt-0">
<Button asChild variant="outline" className="shadow-sm">
<Link href={`/teacher/homework/assignments/${assignment.id}/submissions`}>
<Users className="h-4 w-4 mr-2" aria-hidden="true" />
View Submissions
{t("homework.detail.viewSubmissions")}
</Link>
</Button>
</div>
@@ -54,38 +63,40 @@ export default async function HomeworkAssignmentDetailPage({ params }: { params:
<div className="flex flex-wrap gap-x-8 gap-y-2 mt-6 text-sm">
<div className="flex items-center gap-2 text-muted-foreground">
<Calendar className="h-4 w-4" aria-hidden="true" />
<span>Due: <span className="font-medium text-foreground tabular-nums">{assignment.dueAt ? formatDate(assignment.dueAt) : "No due date"}</span></span>
<span>{t("homework.detail.dueLabel")}: <span className="font-medium text-foreground tabular-nums">{assignment.dueAt ? formatDate(assignment.dueAt) : t("homework.detail.noDueDate")}</span></span>
</div>
<div className="flex items-center gap-2 text-muted-foreground">
<Users className="h-4 w-4" aria-hidden="true" />
<span>Targets: <span className="font-medium text-foreground tabular-nums">{assignment.targetCount}</span></span>
<span>{t("homework.grade.targets")}: <span className="font-medium text-foreground tabular-nums">{assignment.targetCount}</span></span>
</div>
<div className="flex items-center gap-2 text-muted-foreground">
<CheckCircle2 className="h-4 w-4" aria-hidden="true" />
<span>Submissions: <span className="font-medium text-foreground tabular-nums">{assignment.submissionCount}</span></span>
<span>{t("homework.detail.submissionsLabel")}: <span className="font-medium text-foreground tabular-nums">{assignment.submissionCount}</span></span>
</div>
<div className="flex items-center gap-2 text-muted-foreground">
<BarChart3 className="h-4 w-4" aria-hidden="true" />
<span>Graded: <span className="font-medium text-foreground tabular-nums">{gradedSampleCount}</span></span>
<span>{t("homework.grade.gradedCount")}: <span className="font-medium text-foreground tabular-nums">{gradedSampleCount}</span></span>
</div>
</div>
</div>
<div className="flex-1 p-8 space-y-8 bg-muted/5">
{/* Analytics Section */}
{/* Analytics Section - wrapped with SectionErrorBoundary + Suspense for graceful degradation */}
<section className="space-y-4">
<div className="flex items-center justify-between">
<h2 className="text-lg font-semibold tracking-tight">Performance Analytics</h2>
</div>
<div className="grid gap-6 md:grid-cols-1">
<HomeworkAssignmentQuestionErrorOverviewCard questions={questions} gradedSampleCount={gradedSampleCount} />
<h2 className="text-lg font-semibold tracking-tight">{t("homework.detail.performanceAnalytics")}</h2>
</div>
<SectionErrorBoundary namespace="examHomework">
<Suspense fallback={<AnalyticsSkeleton />}>
<HomeworkAssignmentQuestionErrorOverviewCard questions={questions} gradedSampleCount={gradedSampleCount} />
</Suspense>
</SectionErrorBoundary>
</section>
{/* Content Section */}
<section className="space-y-4">
<div className="flex items-center justify-between">
<h2 className="text-lg font-semibold tracking-tight">Assignment Content</h2>
<h2 className="text-lg font-semibold tracking-tight">{t("homework.detail.assignmentContent")}</h2>
</div>
<HomeworkAssignmentExamContentCard
structure={assignment.structure}
@@ -97,3 +108,17 @@ export default async function HomeworkAssignmentDetailPage({ params }: { params:
</div>
)
}
/**
* Analytics 区块加载骨架屏。
*/
function AnalyticsSkeleton(): ReactNode {
return (
<div className="space-y-3">
<Skeleton className="h-8 w-full" />
{Array.from({ length: 4 }).map((_, i) => (
<Skeleton key={i} className="h-12 w-full" />
))}
</div>
)
}

View File

@@ -5,15 +5,18 @@ import { getTranslations } from "next-intl/server"
import { Button } from "@/shared/components/ui/button"
import { getHomeworkAssignmentById, getHomeworkSubmissions } from "@/modules/homework/data-access"
import { HomeworkBatchGradingView } from "@/modules/homework/components/homework-batch-grading-view"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
export const dynamic = "force-dynamic"
export default async function HomeworkAssignmentSubmissionsPage({ params }: { params: Promise<{ id: string }> }): Promise<JSX.Element> {
const { id } = await params
const ctx = await requirePermission(Permissions.HOMEWORK_GRADE)
const t = await getTranslations("examHomework")
const [assignment, submissions] = await Promise.all([
getHomeworkAssignmentById(id),
getHomeworkSubmissions({ assignmentId: id }),
getHomeworkAssignmentById(id, ctx.dataScope),
getHomeworkSubmissions({ assignmentId: id, scope: ctx.dataScope }),
])
if (!assignment) return notFound()