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,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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -4,12 +4,14 @@ import { getExams } from "@/modules/exams/data-access"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { FileQuestion } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function CreateHomeworkAssignmentPage(): Promise<JSX.Element> {
|
||||
const { dataScope } = await getAuthContext()
|
||||
const t = await getTranslations("examHomework")
|
||||
const [exams, classes] = await Promise.all([getExams({ scope: dataScope }), getTeacherClasses()])
|
||||
const options = exams.map((e) => ({ id: e.id, title: e.title }))
|
||||
|
||||
@@ -17,17 +19,17 @@ export default async function CreateHomeworkAssignmentPage(): Promise<JSX.Elemen
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Create Assignment</h1>
|
||||
<p className="text-muted-foreground">快速发布文本作业或从考试派生。</p>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("homework.form.createTitle")}</h1>
|
||||
<p className="text-muted-foreground">{t("homework.form.createDescription")}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{classes.length === 0 ? (
|
||||
<EmptyState
|
||||
title="No classes available"
|
||||
description="Create a class first, then publish homework to that class."
|
||||
title={t("homework.form.noClassesAvailable")}
|
||||
description={t("homework.form.noClassesDescription")}
|
||||
icon={FileQuestion}
|
||||
action={{ label: "Go to Classes", href: "/teacher/classes/my" }}
|
||||
action={{ label: t("homework.form.goToClasses"), href: "/teacher/classes/my" }}
|
||||
/>
|
||||
) : (
|
||||
<HomeworkAssignmentForm exams={options} classes={classes} />
|
||||
|
||||
28
src/app/(dashboard)/teacher/homework/assignments/error.tsx
Normal file
28
src/app/(dashboard)/teacher/homework/assignments/error.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
/**
|
||||
* teacher/homework/assignments/error.tsx
|
||||
* 作业列表错误边界(教师视图)。
|
||||
*/
|
||||
export default function AssignmentsListError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("examHomework")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("homework.error.notFound")}
|
||||
description={t("homework.error.loadFailed")}
|
||||
action={{
|
||||
label: t("common.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
27
src/app/(dashboard)/teacher/homework/assignments/loading.tsx
Normal file
27
src/app/(dashboard)/teacher/homework/assignments/loading.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
/**
|
||||
* teacher/homework/assignments/loading.tsx
|
||||
* 作业列表骨架屏(教师视图):标题 + 表格行骨架。
|
||||
*/
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-28" />
|
||||
</div>
|
||||
<div className="rounded-md border bg-card">
|
||||
<div className="p-4 space-y-3">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { PenTool, PlusCircle, AlertCircle } from "lucide-react"
|
||||
import { getTeacherIdForMutations } from "@/modules/classes/data-access"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -29,6 +31,7 @@ export default async function AssignmentsPage({ searchParams }: { searchParams:
|
||||
const t = await getTranslations("examHomework")
|
||||
const sp = await searchParams
|
||||
const rawClassId = getParam(sp, "classId")
|
||||
const ctx = await requirePermission(Permissions.HOMEWORK_CREATE)
|
||||
const creatorId = await getTeacherIdForMutations()
|
||||
|
||||
// Only fetch classes list when a class filter is active — needed to resolve
|
||||
@@ -36,7 +39,7 @@ export default async function AssignmentsPage({ searchParams }: { searchParams:
|
||||
// avoid an unnecessary DB round-trip.
|
||||
const filteredClassId = rawClassId && rawClassId !== "all" ? rawClassId : null
|
||||
const [assignments, classes] = await Promise.all([
|
||||
getHomeworkAssignments({ creatorId, classId: filteredClassId ?? undefined }),
|
||||
getHomeworkAssignments({ creatorId, classId: filteredClassId ?? undefined, scope: ctx.dataScope }),
|
||||
filteredClassId ? getTeacherClasses() : Promise.resolve([]),
|
||||
])
|
||||
const hasAssignments = assignments.length > 0
|
||||
|
||||
Reference in New Issue
Block a user