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",