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,24 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { RouteErrorBoundary } from "@/shared/components/route-error"
|
||||
|
||||
export default function TeacherAttendanceError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("attendance")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("errors.unexpected")}
|
||||
description={t("errors.unexpected")}
|
||||
action={{
|
||||
label: t("actions.save"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
return <RouteErrorBoundary reset={reset} namespace="attendance" />
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import { PlusCircle, BarChart3, ClipboardList } from "lucide-react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { ListPagination, computePagination, paginate } from "@/shared/components/ui/list-pagination"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { ListPagination, computePagination } from "@/shared/components/ui/list-pagination"
|
||||
import { requirePermission, getAuthContext } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getAttendanceRecords } from "@/modules/attendance/data-access"
|
||||
@@ -36,6 +37,7 @@ export default async function TeacherAttendancePage({
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
const sp = await searchParams
|
||||
await requirePermission(Permissions.ATTENDANCE_READ)
|
||||
const ctx = await getAuthContext()
|
||||
const t = await getTranslations("attendance")
|
||||
|
||||
@@ -55,12 +57,11 @@ export default async function TeacherAttendancePage({
|
||||
])
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
|
||||
// 分页计算
|
||||
// 分页计算:使用后端返回的 total/totalPages,避免基于截断数据计算
|
||||
const { page } = computePagination(sp, PAGE_SIZE)
|
||||
const total = result.items.length
|
||||
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE))
|
||||
const total = result.total
|
||||
const totalPages = result.totalPages
|
||||
const currentPage = Math.min(page, totalPages)
|
||||
const pagedRecords = paginate(result.items, currentPage, PAGE_SIZE)
|
||||
const hasFilters = Boolean(classId || status || date)
|
||||
|
||||
const header = (
|
||||
@@ -103,7 +104,7 @@ export default async function TeacherAttendancePage({
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
<AttendanceRecordList records={pagedRecords} />
|
||||
<AttendanceRecordList records={result.items} />
|
||||
{total > 0 ? (
|
||||
<ListPagination
|
||||
page={currentPage}
|
||||
|
||||
7
src/app/(dashboard)/teacher/attendance/report/error.tsx
Normal file
7
src/app/(dashboard)/teacher/attendance/report/error.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { RouteErrorBoundary } from "@/shared/components/route-error"
|
||||
|
||||
export default function AttendanceReportError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return <RouteErrorBoundary reset={reset} namespace="attendance" />
|
||||
}
|
||||
35
src/app/(dashboard)/teacher/attendance/report/loading.tsx
Normal file
35
src/app/(dashboard)/teacher/attendance/report/loading.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
77
src/app/(dashboard)/teacher/attendance/report/page.tsx
Normal file
77
src/app/(dashboard)/teacher/attendance/report/page.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassAttendanceStats } from "@/modules/attendance/data-access-stats"
|
||||
import { AttendanceReportPrint } from "@/modules/attendance/components/attendance-report-print"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AttendanceReportPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.ATTENDANCE_READ)
|
||||
const t = await getTranslations("attendance")
|
||||
const sp = await searchParams
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const startDate = getParam(sp, "startDate")
|
||||
const endDate = getParam(sp, "endDate")
|
||||
// L-8:报告类型(weekly 默认 / monthly)
|
||||
const reportType = getParam(sp, "reportType") === "monthly" ? "monthly" : "weekly"
|
||||
|
||||
const classes = await getTeacherClasses()
|
||||
|
||||
if (classes.length === 0) {
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("report.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("report.description")}</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
title={t("stats.noClasses")}
|
||||
description={t("stats.noClassesDescription")}
|
||||
icon={BarChart3}
|
||||
className="border-none shadow-none"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const targetClassId = classId ?? classes[0].id
|
||||
|
||||
const summary = await getClassAttendanceStats(
|
||||
targetClassId,
|
||||
startDate,
|
||||
endDate
|
||||
)
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
const targetClass = classes.find((c) => c.id === targetClassId)
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("report.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("report.description")}</p>
|
||||
</div>
|
||||
|
||||
<AttendanceReportPrint
|
||||
summary={summary}
|
||||
classes={classOptions}
|
||||
currentClassId={targetClassId}
|
||||
currentClassName={targetClass?.name ?? ""}
|
||||
startDate={startDate ?? ""}
|
||||
endDate={endDate ?? ""}
|
||||
reportType={reportType}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
7
src/app/(dashboard)/teacher/attendance/sheet/error.tsx
Normal file
7
src/app/(dashboard)/teacher/attendance/sheet/error.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { RouteErrorBoundary } from "@/shared/components/route-error"
|
||||
|
||||
export default function AttendanceSheetError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return <RouteErrorBoundary reset={reset} namespace="attendance" />
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassStudentsForAttendance } from "@/modules/attendance/data-access"
|
||||
import { AttendanceSheet } from "@/modules/attendance/components/attendance-sheet"
|
||||
@@ -12,6 +14,7 @@ export default async function AttendanceSheetPage({
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.ATTENDANCE_MANAGE)
|
||||
const t = await getTranslations("attendance")
|
||||
const sp = await searchParams
|
||||
|
||||
|
||||
7
src/app/(dashboard)/teacher/attendance/stats/error.tsx
Normal file
7
src/app/(dashboard)/teacher/attendance/stats/error.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { RouteErrorBoundary } from "@/shared/components/route-error"
|
||||
|
||||
export default function AttendanceStatsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return <RouteErrorBoundary reset={reset} namespace="attendance" />
|
||||
}
|
||||
@@ -1,13 +1,20 @@
|
||||
import type { JSX } from "react"
|
||||
import Link from "next/link"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getTeacherClasses } from "@/modules/classes/data-access"
|
||||
import { getClassAttendanceStats } from "@/modules/attendance/data-access-stats"
|
||||
import { getClassAttendanceStats, getClassAttendanceWarnings, getAttendanceTrend } from "@/modules/attendance/data-access-stats"
|
||||
import { AttendanceStatsCard } from "@/modules/attendance/components/attendance-stats-card"
|
||||
import { AttendanceRecordList } from "@/modules/attendance/components/attendance-record-list"
|
||||
import { AttendanceStatsClassSelector } from "@/modules/attendance/components/attendance-stats-class-selector"
|
||||
import { AttendanceWarningsCard } from "@/modules/attendance/components/attendance-warnings-card"
|
||||
import { AttendanceTrendChart } from "@/modules/attendance/components/attendance-trend-chart"
|
||||
import type { TrendGranularity } from "@/modules/attendance/trend-compute"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getParam, type SearchParams } from "@/shared/lib/search-params"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
import { BarChart3, FileText } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -16,12 +23,19 @@ export default async function AttendanceStatsPage({
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.ATTENDANCE_READ)
|
||||
const t = await getTranslations("attendance")
|
||||
const sp = await searchParams
|
||||
|
||||
const classId = getParam(sp, "classId")
|
||||
const startDate = getParam(sp, "startDate")
|
||||
const endDate = getParam(sp, "endDate")
|
||||
// L-4:趋势粒度(默认 weekly)
|
||||
const granularityParam = getParam(sp, "granularity")
|
||||
const granularity: TrendGranularity =
|
||||
granularityParam === "daily" || granularityParam === "monthly"
|
||||
? granularityParam
|
||||
: "weekly"
|
||||
|
||||
const classes = await getTeacherClasses()
|
||||
|
||||
@@ -44,19 +58,28 @@ export default async function AttendanceStatsPage({
|
||||
|
||||
const targetClassId = classId ?? classes[0].id
|
||||
|
||||
const summary = await getClassAttendanceStats(
|
||||
targetClassId,
|
||||
startDate,
|
||||
endDate
|
||||
)
|
||||
// 并行获取统计、预警、趋势三个独立查询
|
||||
const [summary, warnings, trend] = await Promise.all([
|
||||
getClassAttendanceStats(targetClassId, startDate, endDate),
|
||||
getClassAttendanceWarnings(targetClassId, startDate, endDate),
|
||||
getAttendanceTrend(targetClassId, granularity, startDate, endDate),
|
||||
])
|
||||
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name }))
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("title.teacherStats")}</h1>
|
||||
<p className="text-muted-foreground">{t("description.teacherStats")}</p>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("title.teacherStats")}</h1>
|
||||
<p className="text-muted-foreground">{t("description.teacherStats")}</p>
|
||||
</div>
|
||||
<Button asChild variant="outline">
|
||||
<Link href={`/teacher/attendance/report?classId=${targetClassId}${startDate ? `&startDate=${startDate}` : ""}${endDate ? `&endDate=${endDate}` : ""}`}>
|
||||
<FileText className="mr-2 h-4 w-4" />
|
||||
{t("report.title")}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<AttendanceStatsClassSelector
|
||||
@@ -69,6 +92,8 @@ export default async function AttendanceStatsPage({
|
||||
{summary ? (
|
||||
<>
|
||||
<AttendanceStatsCard stats={summary.stats} />
|
||||
<AttendanceWarningsCard summary={warnings} />
|
||||
<AttendanceTrendChart summary={trend} granularity={granularity} />
|
||||
<div>
|
||||
<h2 className="mb-4 text-lg font-semibold">{t("stats.studentRecords")}</h2>
|
||||
<AttendanceRecordList records={summary.studentRecords} />
|
||||
|
||||
Reference in New Issue
Block a user