fix: patch P0 security vulnerabilities and critical UX issues across 6 modules

Security: Add admin/layout.tsx auth guard; Add requirePermission() to 12 admin pages

Dashboard: Fix StudentStatsGrid rendering; Fix teacher greeting; Add loading/error boundaries; Fix col-span; Add metadata

Announcements: Fix audience filtering; Add user detail page; Trigger notifications on publish; Pass classes data; Add loading.tsx

Messages: Implement soft delete; Add unread badge with polling; Add notification dropdown polling; Add keyword search; Add quiet hours DND

Management: Add loading/error for 9 admin routes; Fix admin-classes-view to use Select for school/grade

Profile/Settings: Add loading/error; Fix parent role routing; Create ParentSettingsView; Integrate AiProviderSettingsCard; Add Tab URL persistence; Add logout confirm; Add avatar; Fix Progress arbitrary class

Schema: Add senderDeletedAt/receiverDeletedAt to messages; Add quietHours to notificationPreferences; Add uniqueIndex import

Docs: Update architecture docs 004/005
This commit is contained in:
SpecialX
2026-06-22 13:57:31 +08:00
parent 5ff7ab9e72
commit a4d096a6fc
81 changed files with 2145 additions and 124 deletions

View File

@@ -1,11 +1,13 @@
import { PenTool, TriangleAlert, Trophy, TrendingUp } from "lucide-react"
import { BookOpen, CheckCircle, PenTool, TriangleAlert, Trophy, TrendingUp } from "lucide-react"
import { StatCard } from "@/shared/components/ui/stat-card"
import type { StudentRanking } from "@/modules/homework/types"
export function StudentStatsGrid({
enrolledClassCount,
dueSoonCount,
overdueCount,
gradedCount,
ranking,
}: {
enrolledClassCount: number
@@ -16,12 +18,21 @@ export function StudentStatsGrid({
}) {
return (
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
<StatCard
title="Enrolled Classes"
value={String(enrolledClassCount)}
description="Active enrollments"
icon={BookOpen}
href="/student/learning/courses"
color="text-emerald-500"
valueClassName="text-emerald-500 tabular-nums"
/>
<StatCard
title="Average Score"
value={ranking ? `${Math.round(ranking.percentage)}%` : "-"}
description={ranking ? "Overall performance" : "No grades yet"}
icon={TrendingUp}
href="/student/learning/assignments"
href="/student/grades"
color="text-blue-500"
valueClassName={ranking ? "text-blue-500 tabular-nums" : "tabular-nums"}
/>
@@ -30,10 +41,19 @@ export function StudentStatsGrid({
value={ranking ? `${ranking.rank}/${ranking.classSize}` : "-"}
description={ranking ? "Current position" : "No ranking yet"}
icon={Trophy}
href="/student/learning/assignments"
href="/student/grades"
color="text-purple-500"
valueClassName={ranking ? "text-purple-500 tabular-nums" : "tabular-nums"}
/>
<StatCard
title="Graded"
value={String(gradedCount)}
description="Completed assignments"
icon={CheckCircle}
href="/student/learning/assignments"
color="text-green-500"
valueClassName="text-green-500 tabular-nums"
/>
<StatCard
title="Due Soon"
value={String(dueSoonCount)}

View File

@@ -1,20 +1,59 @@
"use client"
import { useMemo } from "react"
import Link from "next/link"
import { CalendarDays, CalendarX } from "lucide-react"
import { Button } from "@/shared/components/ui/button"
import { Badge } from "@/shared/components/ui/badge"
import { ScheduleList } from "@/shared/components/schedule/schedule-list"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { cn } from "@/shared/lib/utils"
import type { StudentTodayScheduleItem } from "@/modules/dashboard/types"
/**
* Parse "HH:MM" time string into minutes since midnight for comparison.
*/
const timeToMinutes = (t: string): number => {
const [h, m] = t.split(":").map(Number)
return (h ?? 0) * 60 + (m ?? 0)
}
export function StudentTodayScheduleCard({ items }: { items: StudentTodayScheduleItem[] }) {
const hasSchedule = items.length > 0
// Compute current/next class status based on client time
const { currentId, nextId } = useMemo(() => {
const now = new Date()
const nowMin = now.getHours() * 60 + now.getMinutes()
let currentId: string | null = null
let nextId: string | null = null
for (const item of items) {
const start = timeToMinutes(item.startTime)
const end = timeToMinutes(item.endTime)
if (nowMin >= start && nowMin < end) {
currentId = item.id
break
}
if (nowMin < start) {
nextId = item.id
break
}
}
return { currentId, nextId }
}, [items])
return (
<Card className="lg:col-span-3">
<CardHeader>
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle className="flex items-center gap-2">
<CalendarDays className="h-4 w-4 text-muted-foreground" />
Today&apos;s Schedule
</CardTitle>
<Button asChild variant="outline" size="sm">
<Link href="/student/schedule">View all</Link>
</Button>
</CardHeader>
<CardContent>
{!hasSchedule ? (
@@ -29,6 +68,30 @@ export function StudentTodayScheduleCard({ items }: { items: StudentTodaySchedul
items={items}
variant="separator"
spacingClassName="space-y-4"
renderTrailing={(item) => {
const isCurrent = item.id === currentId
const isNext = item.id === nextId
if (isCurrent) {
return (
<Badge className="shrink-0 bg-emerald-500 text-white hover:bg-emerald-500">
In Progress
</Badge>
)
}
if (isNext) {
return (
<Badge variant="outline" className="shrink-0 border-primary text-primary">
Up Next
</Badge>
)
}
return item.className ? (
<Badge variant="secondary" className="shrink-0">
{item.className}
</Badge>
) : null
}}
className={cn(currentId && "[&_div:first-child]:bg-emerald-50/50")}
/>
)}
</CardContent>

View File

@@ -5,23 +5,14 @@ import { Badge } from "@/shared/components/ui/badge"
import { Button } from "@/shared/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { StatusBadge } from "@/shared/components/ui/status-badge"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/shared/components/ui/table"
import { formatDate, cn } from "@/shared/lib/utils"
import type { StudentHomeworkAssignmentListItem } from "@/modules/homework/types"
const getStatusVariant = (status: string): "default" | "secondary" | "outline" => {
if (status === "graded") return "default"
if (status === "submitted") return "secondary"
if (status === "in_progress") return "secondary"
return "outline"
}
const getStatusLabel = (status: string) => {
if (status === "graded") return "Graded"
if (status === "submitted") return "Submitted"
if (status === "in_progress") return "In progress"
return "Not started"
}
import {
STUDENT_HOMEWORK_PROGRESS_VARIANT,
STUDENT_HOMEWORK_PROGRESS_LABEL,
} from "@/modules/homework/types"
const getActionLabel = (status: string) => {
if (status === "graded") return "Review"
@@ -51,7 +42,7 @@ export function StudentUpcomingAssignmentsCard({ upcomingAssignments }: { upcomi
const hasAssignments = upcomingAssignments.length > 0
return (
<Card className="lg:col-span-4">
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle className="text-base flex items-center gap-2">
<PenTool className="h-4 w-4 text-muted-foreground" />
@@ -99,9 +90,11 @@ export function StudentUpcomingAssignmentsCard({ upcomingAssignments }: { upcomi
</div>
</TableCell>
<TableCell>
<Badge variant={getStatusVariant(a.progressStatus)} className="capitalize">
{getStatusLabel(a.progressStatus)}
</Badge>
<StatusBadge
status={a.progressStatus}
variantMap={STUDENT_HOMEWORK_PROGRESS_VARIANT}
labelMap={STUDENT_HOMEWORK_PROGRESS_LABEL}
/>
</TableCell>
<TableCell className={cn(
"text-muted-foreground",

View File

@@ -1,3 +1,6 @@
"use client"
import { formatLongDate } from "@/shared/lib/utils"
import { TeacherQuickActions } from "./teacher-quick-actions"
interface TeacherDashboardHeaderProps {
@@ -5,18 +8,18 @@ interface TeacherDashboardHeaderProps {
}
export function TeacherDashboardHeader({ teacherName }: TeacherDashboardHeaderProps) {
const today = new Date().toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
})
const today = formatLongDate(new Date())
const hour = new Date().getHours()
let greeting = "欢迎回来"
if (hour < 12) greeting = "早上好"
else if (hour < 18) greeting = "下午好"
else greeting = "晚上好"
return (
<div className="flex flex-col justify-between space-y-4 md:flex-row md:items-center md:space-y-0">
<div>
<h2 className="text-2xl font-bold tracking-tight">Good morning, {teacherName}</h2>
<p className="text-muted-foreground">It&apos;s {today}. Here&apos;s your daily overview.</p>
<h2 className="text-2xl font-bold tracking-tight">{greeting}{teacherName}</h2>
<p className="text-muted-foreground"> {today}</p>
</div>
<TeacherQuickActions />
</div>

View File

@@ -7,6 +7,7 @@ import { RecentSubmissions } from "./recent-submissions"
import { TeacherSchedule } from "./teacher-schedule"
import { TeacherStats } from "./teacher-stats"
import { TeacherGradeTrends } from "./teacher-grade-trends"
import { TeacherTodoCard, type TeacherTodoItem } from "./teacher-todo-card"
const toWeekday = (d: Date): 1 | 2 | 3 | 4 | 5 | 6 | 7 => {
const day = d.getDay()
@@ -32,16 +33,12 @@ export function TeacherDashboardView({ data }: { data: TeacherDashboardData }) {
const submittedSubmissions = data.submissions.filter((s) => Boolean(s.submittedAt))
const toGradeCount = submittedSubmissions.filter((s) => s.status === "submitted").length
// Filter for submissions that actually need grading (status === "submitted")
// If we have less than 5 to grade, maybe also show some recently graded ones?
// For now, let's stick to "Needs Grading" as it's more useful.
const submissionsToGrade = submittedSubmissions
.filter(s => s.status === "submitted")
.sort((a, b) => new Date(a.submittedAt!).getTime() - new Date(b.submittedAt!).getTime()) // Oldest first? Or Newest? Usually oldest first for queue.
.sort((a, b) => (a.submittedAt ? new Date(a.submittedAt).getTime() : 0) - (b.submittedAt ? new Date(b.submittedAt).getTime() : 0))
.slice(0, 6);
// Calculate stats for the dashboard
const activeAssignmentsCount = data.assignments.filter(a => a.status === "published").length
const totalTrendScore = data.gradeTrends.reduce((acc, curr) => acc + curr.averageScore, 0)
@@ -51,6 +48,13 @@ export function TeacherDashboardView({ data }: { data: TeacherDashboardData }) {
const totalPotentialSubmissions = data.gradeTrends.reduce((acc, curr) => acc + curr.totalStudents, 0)
const submissionRate = totalPotentialSubmissions > 0 ? (totalSubmissions / totalPotentialSubmissions) * 100 : 0
// 待办聚合
const todoItems: TeacherTodoItem[] = [
{ label: "待批改作业", count: toGradeCount, href: "/teacher/homework/submissions", variant: toGradeCount > 0 ? "urgent" : "normal" },
{ label: "今日待考勤", count: todayScheduleItems.length, href: "/teacher/attendance/sheet", variant: "info" },
{ label: "进行中作业", count: activeAssignmentsCount, href: "/teacher/homework/assignments", variant: "normal" },
]
return (
<div className="flex h-full flex-col space-y-6 p-8">
<TeacherDashboardHeader teacherName={data.teacherName} />
@@ -63,18 +67,25 @@ export function TeacherDashboardView({ data }: { data: TeacherDashboardData }) {
/>
<div className="grid gap-6 lg:grid-cols-12">
{/* 移动端优先展示:今日课表 → 待办 → 待批改 */}
<div className="flex flex-col gap-6 lg:col-span-8">
<div className="lg:hidden">
<TeacherSchedule items={todayScheduleItems} />
</div>
<TeacherTodoCard items={todoItems} />
<TeacherGradeTrends trends={data.gradeTrends} />
<RecentSubmissions
submissions={submissionsToGrade}
title="Needs Grading"
emptyTitle="All caught up!"
emptyDescription="You have no pending submissions to grade."
title="待批改"
emptyTitle="全部批改完成!"
emptyDescription="暂无待批改的提交。"
/>
</div>
<div className="flex flex-col gap-6 lg:col-span-4">
<TeacherSchedule items={todayScheduleItems} />
<div className="hidden lg:block">
<TeacherSchedule items={todayScheduleItems} />
</div>
<TeacherHomeworkCard assignments={data.assignments} />
<TeacherClassesCard classes={data.classes} />
</div>