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:
@@ -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'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>
|
||||
|
||||
Reference in New Issue
Block a user