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:
30
src/app/(dashboard)/parent/practice/error.tsx
Normal file
30
src/app/(dashboard)/parent/practice/error.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
"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"
|
||||
|
||||
export default function ParentPracticeError({
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string }
|
||||
reset: () => void
|
||||
}): JSX.Element {
|
||||
const t = useTranslations("practice")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("errors.pageErrorTitleParent")}
|
||||
description={t("errors.pageErrorParent")}
|
||||
action={{
|
||||
label: t("errors.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
33
src/app/(dashboard)/parent/practice/loading.tsx
Normal file
33
src/app/(dashboard)/parent/practice/loading.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { JSX } from "react"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function ParentPracticeLoading(): JSX.Element {
|
||||
return (
|
||||
<div className="space-y-8 p-6 md:p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
{/* 默认按多子女布局骨架 */}
|
||||
<div className="space-y-8">
|
||||
{Array.from({ length: 2 }).map((_, i) => (
|
||||
<div key={i} className="space-y-4">
|
||||
<div className="border-b pb-2">
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4 md:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, j) => (
|
||||
<Skeleton key={j} className="h-20 w-full rounded-md" />
|
||||
))}
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{Array.from({ length: 4 }).map((_, j) => (
|
||||
<Skeleton key={j} className="h-20 w-full rounded-md" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
127
src/app/(dashboard)/parent/practice/page.tsx
Normal file
127
src/app/(dashboard)/parent/practice/page.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { Target, Users } from "lucide-react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { WidgetBoundary } from "@/shared/components/widget-boundary"
|
||||
|
||||
import { getPracticeSessions, getPracticeStats } from "@/modules/adaptive-practice/data-access"
|
||||
import { PracticeHistory } from "@/modules/adaptive-practice/components/practice-history"
|
||||
import { PracticeStatsCards } from "@/modules/adaptive-practice/components/practice-stats-cards"
|
||||
import { PracticeServiceProvider } from "@/modules/adaptive-practice/services/practice-service"
|
||||
import type { PracticeSessionSummary, PracticeStats } from "@/modules/adaptive-practice/types"
|
||||
import { getUserNamesByIds } from "@/modules/users/data-access"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
interface ChildPracticeItem {
|
||||
studentId: string
|
||||
studentName: string
|
||||
stats: PracticeStats
|
||||
sessions: PracticeSessionSummary[]
|
||||
}
|
||||
|
||||
export default async function ParentPracticePage(): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.ADAPTIVE_PRACTICE_READ)
|
||||
const t = await getTranslations("practice")
|
||||
|
||||
// 家长 dataScope 必须为 children;否则提示无关联子女
|
||||
if (ctx.dataScope.type !== "children" || ctx.dataScope.childrenIds.length === 0) {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-6 md:p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("parent.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("parent.description")}</p>
|
||||
</div>
|
||||
<EmptyState
|
||||
icon={Users}
|
||||
title={t("parent.noChild")}
|
||||
description={t("parent.noChildDescription")}
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const childrenIds = ctx.dataScope.childrenIds
|
||||
|
||||
// 并行查询:姓名映射 + 每个子女的统计与历史
|
||||
// 使用 allSettled 容错:单个子女查询失败不影响其他子女展示
|
||||
// 注意:nameMapPromise 与 childResults 并行启动,但类型上分离以利于类型收窄
|
||||
const nameMapPromise = getUserNamesByIds(childrenIds)
|
||||
const childResults = await Promise.allSettled(
|
||||
childrenIds.map(async (id) => {
|
||||
const [stats, sessionsResult] = await Promise.all([
|
||||
getPracticeStats(id),
|
||||
getPracticeSessions(id, { pageSize: 20 }),
|
||||
])
|
||||
return { studentId: id, stats, sessions: sessionsResult.data }
|
||||
}),
|
||||
)
|
||||
const nameMap = await nameMapPromise
|
||||
|
||||
// 过滤掉 rejected 的查询结果
|
||||
const validItems: ChildPracticeItem[] = []
|
||||
for (const r of childResults) {
|
||||
if (r.status !== "fulfilled") continue
|
||||
const { studentId, stats, sessions } = r.value
|
||||
const studentName = nameMap.get(studentId)?.name ?? t("parent.noChildSelected")
|
||||
validItems.push({ studentId, studentName, stats, sessions })
|
||||
}
|
||||
|
||||
// 单子女:直接展示;多子女:按卡片分组
|
||||
const isSingleChild = validItems.length === 1
|
||||
|
||||
return (
|
||||
<PracticeServiceProvider>
|
||||
<div className="flex h-full flex-col space-y-8 p-6 md:p-8">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{t("parent.title")}</h1>
|
||||
<p className="text-muted-foreground">{t("parent.description")}</p>
|
||||
</div>
|
||||
|
||||
{isSingleChild ? (
|
||||
<>
|
||||
<WidgetBoundary title={t("parent.stats")} skeletonHeight={160}>
|
||||
<PracticeStatsCards stats={validItems[0]!.stats} />
|
||||
</WidgetBoundary>
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-lg font-semibold">{t("parent.history")}</h2>
|
||||
<WidgetBoundary title={t("parent.history")} skeletonHeight={300}>
|
||||
{/* 家长无会话详情页,仅展示只读卡片 */}
|
||||
<PracticeHistory sessions={validItems[0]!.sessions} />
|
||||
</WidgetBoundary>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="space-y-8">
|
||||
{validItems.map((item) => (
|
||||
<WidgetBoundary
|
||||
key={item.studentId}
|
||||
title={`${t("parent.stats")} · ${item.studentName}`}
|
||||
skeletonHeight={300}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2 border-b pb-2">
|
||||
<Target className="h-5 w-5 text-primary" aria-hidden="true" />
|
||||
<h3 className="text-lg font-semibold">{item.studentName}</h3>
|
||||
</div>
|
||||
<PracticeStatsCards stats={item.stats} />
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium text-muted-foreground">
|
||||
{t("parent.history")}
|
||||
</h4>
|
||||
{/* 家长无会话详情页,仅展示只读卡片 */}
|
||||
<PracticeHistory sessions={item.sessions} />
|
||||
</div>
|
||||
</div>
|
||||
</WidgetBoundary>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PracticeServiceProvider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user