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:
@@ -2,6 +2,8 @@ import { notFound } from "next/navigation"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getAnnouncementById } from "@/modules/announcements/data-access"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
import { AnnouncementForm } from "@/modules/announcements/components/announcement-form"
|
||||
@@ -18,6 +20,7 @@ export default async function EditAnnouncementPage({
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.ANNOUNCEMENT_MANAGE)
|
||||
const { id } = await params
|
||||
|
||||
const [announcement, grades] = await Promise.all([
|
||||
|
||||
40
src/app/(dashboard)/admin/announcements/loading.tsx
Normal file
40
src/app/(dashboard)/admin/announcements/loading.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminAnnouncementsLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
<Skeleton className="h-9 w-40" />
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<Skeleton className="h-9 w-[180px]" />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2 space-y-0">
|
||||
<Skeleton className="h-5 w-3/4" />
|
||||
<Skeleton className="h-5 w-16" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-2/3" />
|
||||
<div className="flex items-center gap-2 pt-2">
|
||||
<Skeleton className="h-5 w-16" />
|
||||
<Skeleton className="h-3 w-32" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getAnnouncements } from "@/modules/announcements/data-access"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
import { getAdminClasses } from "@/modules/classes/data-access"
|
||||
import { AdminAnnouncementsView } from "@/modules/announcements/components/admin-announcements-view"
|
||||
import { getSearchParam, type SearchParams } from "@/shared/lib/utils"
|
||||
import type { AnnouncementStatus } from "@/modules/announcements/types"
|
||||
@@ -22,19 +25,22 @@ export default async function AdminAnnouncementsPage({
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.ANNOUNCEMENT_MANAGE)
|
||||
const sp = await searchParams
|
||||
const statusParam = getSearchParam(sp, "status")
|
||||
const status = isValidStatus(statusParam) ? statusParam : undefined
|
||||
|
||||
const [announcements, grades] = await Promise.all([
|
||||
const [announcements, grades, classes] = await Promise.all([
|
||||
getAnnouncements({ status }),
|
||||
getGrades(),
|
||||
getAdminClasses(),
|
||||
])
|
||||
|
||||
return (
|
||||
<AdminAnnouncementsView
|
||||
announcements={announcements}
|
||||
grades={grades.map((g) => ({ id: g.id, name: g.name }))}
|
||||
classes={classes.map((c) => ({ id: c.id, name: c.name }))}
|
||||
initialStatus={status}
|
||||
/>
|
||||
)
|
||||
|
||||
10
src/app/(dashboard)/admin/layout.tsx
Normal file
10
src/app/(dashboard)/admin/layout.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
|
||||
export default async function AdminLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}): Promise<React.ReactNode> {
|
||||
await getAuthContext()
|
||||
return <>{children}</>
|
||||
}
|
||||
22
src/app/(dashboard)/admin/scheduling/auto/error.tsx
Normal file
22
src/app/(dashboard)/admin/scheduling/auto/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminSchedulingAutoError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/scheduling/auto/loading.tsx
Normal file
24
src/app/(dashboard)/admin/scheduling/auto/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminSchedulingAutoLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import { CalendarClock, ClipboardList, Settings2 } from "lucide-react"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { getAdminClassesForScheduling } from "@/modules/scheduling/data-access"
|
||||
@@ -16,6 +18,7 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminSchedulingAutoPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHEDULE_AUTO)
|
||||
const classes = await getAdminClassesForScheduling()
|
||||
const classOptions = classes.map((c) => ({ id: c.id, name: c.name, grade: c.grade }))
|
||||
|
||||
|
||||
22
src/app/(dashboard)/admin/scheduling/changes/error.tsx
Normal file
22
src/app/(dashboard)/admin/scheduling/changes/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminSchedulingChangesError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/scheduling/changes/loading.tsx
Normal file
24
src/app/(dashboard)/admin/scheduling/changes/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminSchedulingChangesLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
22
src/app/(dashboard)/admin/scheduling/rules/error.tsx
Normal file
22
src/app/(dashboard)/admin/scheduling/rules/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminSchedulingRulesError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/scheduling/rules/loading.tsx
Normal file
24
src/app/(dashboard)/admin/scheduling/rules/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminSchedulingRulesLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import {
|
||||
getAdminClassesForScheduling,
|
||||
@@ -17,6 +19,7 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminSchedulingRulesPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHEDULE_ADJUST)
|
||||
const [classes, existingRules] = await Promise.all([
|
||||
getAdminClassesForScheduling(),
|
||||
getSchedulingRules(),
|
||||
|
||||
22
src/app/(dashboard)/admin/school/academic-year/error.tsx
Normal file
22
src/app/(dashboard)/admin/school/academic-year/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminAcademicYearError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/school/academic-year/loading.tsx
Normal file
24
src/app/(dashboard)/admin/school/academic-year/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminAcademicYearLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { AcademicYearClient } from "@/modules/school/components/academic-year-view"
|
||||
import { getAcademicYears } from "@/modules/school/data-access"
|
||||
|
||||
@@ -12,6 +14,7 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminAcademicYearPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHOOL_MANAGE)
|
||||
const years = await getAcademicYears()
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
|
||||
22
src/app/(dashboard)/admin/school/classes/error.tsx
Normal file
22
src/app/(dashboard)/admin/school/classes/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminClassesError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/school/classes/loading.tsx
Normal file
24
src/app/(dashboard)/admin/school/classes/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminClassesLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getAdminClasses, getTeacherOptions } from "@/modules/classes/data-access"
|
||||
import { getGrades, getSchools } from "@/modules/school/data-access"
|
||||
import { AdminClassesClient } from "@/modules/classes/components/admin-classes-view"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
@@ -12,7 +15,13 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminSchoolClassesPage(): Promise<JSX.Element> {
|
||||
const [classes, teachers] = await Promise.all([getAdminClasses(), getTeacherOptions()])
|
||||
await requirePermission(Permissions.SCHOOL_MANAGE)
|
||||
const [classes, teachers, schools, grades] = await Promise.all([
|
||||
getAdminClasses(),
|
||||
getTeacherOptions(),
|
||||
getSchools(),
|
||||
getGrades(),
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
@@ -20,7 +29,7 @@ export default async function AdminSchoolClassesPage(): Promise<JSX.Element> {
|
||||
<h2 className="text-2xl font-bold tracking-tight">班级管理</h2>
|
||||
<p className="text-muted-foreground">管理班级并分配教师。</p>
|
||||
</div>
|
||||
<AdminClassesClient classes={classes} teachers={teachers} />
|
||||
<AdminClassesClient classes={classes} teachers={teachers} schools={schools} grades={grades} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
22
src/app/(dashboard)/admin/school/departments/error.tsx
Normal file
22
src/app/(dashboard)/admin/school/departments/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminDepartmentsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/school/departments/loading.tsx
Normal file
24
src/app/(dashboard)/admin/school/departments/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminDepartmentsLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { DepartmentsClient } from "@/modules/school/components/departments-view"
|
||||
import { getDepartments } from "@/modules/school/data-access"
|
||||
|
||||
@@ -12,6 +14,7 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminDepartmentsPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHOOL_MANAGE)
|
||||
const departments = await getDepartments()
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
|
||||
22
src/app/(dashboard)/admin/school/grades/error.tsx
Normal file
22
src/app/(dashboard)/admin/school/grades/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminGradesError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
import { BarChart3 } from "lucide-react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
import { getGradeHomeworkInsights } from "@/modules/classes/data-access"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
@@ -25,6 +27,7 @@ export default async function AdminGradeInsightsPage({
|
||||
}: {
|
||||
searchParams: Promise<SearchParams>
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHOOL_MANAGE)
|
||||
const params = await searchParams
|
||||
const gradeId = getSearchParam(params, "gradeId")
|
||||
const selected = gradeId && gradeId !== "all" ? gradeId : ""
|
||||
|
||||
24
src/app/(dashboard)/admin/school/grades/loading.tsx
Normal file
24
src/app/(dashboard)/admin/school/grades/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminGradesLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { GradesClient } from "@/modules/school/components/grades-view"
|
||||
import { getGrades, getSchools, getStaffOptions } from "@/modules/school/data-access"
|
||||
|
||||
@@ -12,6 +14,7 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminGradesPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHOOL_MANAGE)
|
||||
const [grades, schools, staff] = await Promise.all([getGrades(), getSchools(), getStaffOptions()])
|
||||
|
||||
return (
|
||||
|
||||
22
src/app/(dashboard)/admin/school/schools/error.tsx
Normal file
22
src/app/(dashboard)/admin/school/schools/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminSchoolsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/school/schools/loading.tsx
Normal file
24
src/app/(dashboard)/admin/school/schools/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminSchoolsLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { SchoolsClient } from "@/modules/school/components/schools-view"
|
||||
import { getSchools } from "@/modules/school/data-access"
|
||||
|
||||
@@ -12,6 +14,7 @@ export const metadata: Metadata = {
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AdminSchoolsPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.SCHOOL_MANAGE)
|
||||
const schools = await getSchools()
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
|
||||
22
src/app/(dashboard)/admin/users/import/error.tsx
Normal file
22
src/app/(dashboard)/admin/users/import/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminUsersImportError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/admin/users/import/loading.tsx
Normal file
24
src/app/(dashboard)/admin/users/import/loading.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AdminUsersImportLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import type { JSX } from "react"
|
||||
import Link from "next/link"
|
||||
import { ArrowLeft, Users, FileSpreadsheet, Info } from "lucide-react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import {
|
||||
@@ -22,7 +24,8 @@ export const metadata: Metadata = {
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default function UserImportPage(): JSX.Element {
|
||||
export default async function UserImportPage(): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.USER_MANAGE)
|
||||
return (
|
||||
<div className="h-full flex-1 flex-col space-y-6 p-8 md:flex">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
|
||||
36
src/app/(dashboard)/announcements/[id]/page.tsx
Normal file
36
src/app/(dashboard)/announcements/[id]/page.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getAnnouncementById } from "@/modules/announcements/data-access"
|
||||
import { AnnouncementDetail } from "@/modules/announcements/components/announcement-detail"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Announcement - Next_Edu",
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export default async function AnnouncementDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}): Promise<JSX.Element> {
|
||||
const { id } = await params
|
||||
await requirePermission(Permissions.ANNOUNCEMENT_READ)
|
||||
|
||||
const announcement = await getAnnouncementById(id)
|
||||
if (!announcement) notFound()
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<AnnouncementDetail
|
||||
announcement={announcement}
|
||||
canManage={false}
|
||||
backHref="/announcements"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
src/app/(dashboard)/announcements/loading.tsx
Normal file
37
src/app/(dashboard)/announcements/loading.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function AnnouncementsLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<Skeleton className="h-9 w-[180px]" />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2 space-y-0">
|
||||
<Skeleton className="h-5 w-3/4" />
|
||||
<Skeleton className="h-5 w-16" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="h-4 w-2/3" />
|
||||
<div className="flex items-center gap-2 pt-2">
|
||||
<Skeleton className="h-5 w-16" />
|
||||
<Skeleton className="h-3 w-32" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,17 +1,88 @@
|
||||
import type { Metadata } from "next"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getAnnouncements } from "@/modules/announcements/data-access"
|
||||
import { AnnouncementList } from "@/modules/announcements/components/announcement-list"
|
||||
import {
|
||||
getStudentActiveClassId,
|
||||
getStudentActiveGradeId,
|
||||
getClassGradeId,
|
||||
} from "@/modules/classes/data-access"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
export const metadata: Metadata = {
|
||||
title: "Announcements",
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前用户身份解析受众信息(gradeId / classId)。
|
||||
* - admin:返回 null(管理端可见所有公告)
|
||||
* - student / teacher:使用首个 classId 并查询其 gradeId
|
||||
* - grade_head / teaching_head:使用首个 gradeId
|
||||
* - parent:使用首个孩子的活跃班级信息
|
||||
* - 其他:返回 null(仅显示 school 类型公告由 audience.gradeId/classId 均缺失时的兜底处理)
|
||||
*/
|
||||
async function resolveAudience(ctx: {
|
||||
userId: string
|
||||
dataScope:
|
||||
| { type: "all" }
|
||||
| { type: "owned"; userId: string }
|
||||
| { type: "class_members"; classIds: string[] }
|
||||
| { type: "grade_managed"; gradeIds: string[] }
|
||||
| { type: "class_taught"; classIds: string[]; subjectIds?: string[] }
|
||||
| { type: "children"; childrenIds: string[] }
|
||||
}): Promise<{ gradeId?: string; classId?: string } | null> {
|
||||
const { dataScope } = ctx
|
||||
|
||||
if (dataScope.type === "all") return null
|
||||
|
||||
if (dataScope.type === "grade_managed") {
|
||||
const gradeId = dataScope.gradeIds[0]
|
||||
return gradeId ? { gradeId } : null
|
||||
}
|
||||
|
||||
if (dataScope.type === "class_members" || dataScope.type === "class_taught") {
|
||||
const classId = dataScope.classIds[0]
|
||||
if (!classId) return null
|
||||
const gradeId = await getClassGradeId(classId)
|
||||
return { classId, gradeId: gradeId ?? undefined }
|
||||
}
|
||||
|
||||
if (dataScope.type === "children") {
|
||||
const childId = dataScope.childrenIds[0]
|
||||
if (!childId) return null
|
||||
const [classId, gradeId] = await Promise.all([
|
||||
getStudentActiveClassId(childId),
|
||||
getStudentActiveGradeId(childId),
|
||||
])
|
||||
return {
|
||||
classId: classId ?? undefined,
|
||||
gradeId: gradeId ?? undefined,
|
||||
}
|
||||
}
|
||||
|
||||
// owned / 其他:尝试用当前 userId 查询(兼容 student 角色直接访问)
|
||||
const [classId, gradeId] = await Promise.all([
|
||||
getStudentActiveClassId(ctx.userId),
|
||||
getStudentActiveGradeId(ctx.userId),
|
||||
])
|
||||
if (!classId && !gradeId) return null
|
||||
return {
|
||||
classId: classId ?? undefined,
|
||||
gradeId: gradeId ?? undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export default async function AnnouncementsPage() {
|
||||
await requirePermission(Permissions.ANNOUNCEMENT_READ)
|
||||
const announcements = await getAnnouncements({ status: "published" })
|
||||
const ctx = await requirePermission(Permissions.ANNOUNCEMENT_READ)
|
||||
const audience = await resolveAudience(ctx)
|
||||
|
||||
const announcements = await getAnnouncements({
|
||||
status: "published",
|
||||
audience: audience ?? undefined,
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
@@ -21,7 +92,10 @@ export default async function AnnouncementsPage() {
|
||||
Stay up to date with the latest school announcements.
|
||||
</p>
|
||||
</div>
|
||||
<AnnouncementList announcements={announcements} />
|
||||
<AnnouncementList
|
||||
announcements={announcements}
|
||||
detailHrefBuilder={(id) => `/announcements/${id}`}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
22
src/app/(dashboard)/dashboard/error.tsx
Normal file
22
src/app/(dashboard)/dashboard/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function DashboardError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
38
src/app/(dashboard)/dashboard/loading.tsx
Normal file
38
src/app/(dashboard)/dashboard/loading.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function DashboardLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="pb-2">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-8 w-16" />
|
||||
<Skeleton className="mt-2 h-3 w-28" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
43
src/app/(dashboard)/messages/[id]/loading.tsx
Normal file
43
src/app/(dashboard)/messages/[id]/loading.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
|
||||
export default function MessageDetailLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col p-8">
|
||||
<div className="mx-auto w-full max-w-3xl space-y-6">
|
||||
<div className="flex items-center gap-4">
|
||||
<Skeleton className="h-9 w-24" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-7 w-64" />
|
||||
<Skeleton className="h-4 w-48" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="space-y-2">
|
||||
<Skeleton className="h-5 w-3/4" />
|
||||
<div className="flex items-center gap-2">
|
||||
<Skeleton className="h-3 w-24" />
|
||||
<Skeleton className="h-3 w-32" />
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-4 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<Button variant="outline" disabled>
|
||||
<Skeleton className="h-4 w-20" />
|
||||
</Button>
|
||||
<Button disabled>
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
40
src/app/(dashboard)/messages/compose/loading.tsx
Normal file
40
src/app/(dashboard)/messages/compose/loading.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function ComposeLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col p-8">
|
||||
<div className="mx-auto w-full max-w-3xl space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-16" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-20" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-16" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<Skeleton className="h-10 w-24" />
|
||||
<Skeleton className="h-10 w-28" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
22
src/app/(dashboard)/messages/error.tsx
Normal file
22
src/app/(dashboard)/messages/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function MessagesError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="消息加载失败"
|
||||
description="抱歉,加载消息时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
36
src/app/(dashboard)/messages/loading.tsx
Normal file
36
src/app/(dashboard)/messages/loading.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function MessagesLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Skeleton className="h-10 w-48" />
|
||||
<Skeleton className="h-10 w-28" />
|
||||
</div>
|
||||
<Skeleton className="h-10 w-full" />
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2 space-y-0 pb-3">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-4 w-48" />
|
||||
<Skeleton className="h-3 w-32" />
|
||||
</div>
|
||||
<Skeleton className="h-3 w-20" />
|
||||
</CardHeader>
|
||||
<CardContent className="pt-0">
|
||||
<Skeleton className="h-4 w-full" />
|
||||
<Skeleton className="mt-1 h-4 w-3/4" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
22
src/app/(dashboard)/parent/dashboard/error.tsx
Normal file
22
src/app/(dashboard)/parent/dashboard/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function ParentDashboardError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
50
src/app/(dashboard)/parent/dashboard/loading.tsx
Normal file
50
src/app/(dashboard)/parent/dashboard/loading.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-9 w-48" />
|
||||
<Skeleton className="h-4 w-56" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Skeleton className="h-9 w-28" />
|
||||
<Skeleton className="h-9 w-28" />
|
||||
<Skeleton className="h-9 w-28" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="pb-2">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-8 w-16" />
|
||||
<Skeleton className="mt-2 h-3 w-28" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<Skeleton className="h-16 w-full" />
|
||||
<Skeleton className="h-16 w-full" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import { Users } from "lucide-react"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = { title: "Dashboard - Next_Edu" }
|
||||
|
||||
export default async function ParentDashboardPage() {
|
||||
const ctx = await requireAuth()
|
||||
|
||||
|
||||
22
src/app/(dashboard)/profile/error.tsx
Normal file
22
src/app/(dashboard)/profile/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function ProfileError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,个人资料页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
36
src/app/(dashboard)/profile/loading.tsx
Normal file
36
src/app/(dashboard)/profile/loading.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function ProfileLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-40" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Skeleton className="h-20 w-20 rounded-full" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-5 w-40" />
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
{Array.from({ length: 2 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 4 }).map((_, j) => (
|
||||
<Skeleton key={j} className="h-10 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { StudentTodayScheduleCard } from "@/modules/dashboard/components/student
|
||||
import { StudentUpcomingAssignmentsCard } from "@/modules/dashboard/components/student-dashboard/student-upcoming-assignments-card"
|
||||
import { getStudentDashboardGrades, getStudentHomeworkAssignments } from "@/modules/homework/data-access"
|
||||
import { getUserProfile } from "@/modules/users/data-access"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/shared/components/ui/avatar"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
@@ -129,6 +130,19 @@ export default async function ProfilePage() {
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Avatar className="h-20 w-20">
|
||||
{userProfile.image ? <AvatarImage src={userProfile.image} alt={userProfile.name ?? "User avatar"} /> : null}
|
||||
<AvatarFallback className="text-xl font-semibold">
|
||||
{(userProfile.name ?? userProfile.email).slice(0, 2).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="space-y-1">
|
||||
<div className="text-xl font-semibold tracking-tight">{userProfile.name ?? "-"}</div>
|
||||
<div className="text-sm text-muted-foreground">{userProfile.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
|
||||
22
src/app/(dashboard)/settings/error.tsx
Normal file
22
src/app/(dashboard)/settings/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function SettingsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,设置页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
31
src/app/(dashboard)/settings/loading.tsx
Normal file
31
src/app/(dashboard)/settings/loading.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function SettingsLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-8 p-8">
|
||||
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-40" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
<Skeleton className="h-10 w-40" />
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-10 w-full max-w-md" />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { requireAuth } from "@/shared/lib/auth-guard"
|
||||
import { AdminSettingsView } from "@/modules/settings/components/admin-settings-view"
|
||||
import { SettingsView } from "@/modules/settings/components/settings-view"
|
||||
import { StudentSettingsView } from "@/modules/settings/components/student-settings-view"
|
||||
import { TeacherSettingsView } from "@/modules/settings/components/teacher-settings-view"
|
||||
import { ParentSettingsView } from "@/modules/settings/components/parent-settings-view"
|
||||
import { getUserProfile } from "@/modules/users/data-access"
|
||||
import { getNotificationPreferences } from "@/modules/notifications/preferences"
|
||||
|
||||
@@ -25,10 +26,20 @@ export default async function SettingsPage() {
|
||||
const notificationPrefs = await getNotificationPreferences(userId)
|
||||
|
||||
if (roles.includes("admin")) {
|
||||
return <AdminSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
return (
|
||||
<SettingsView
|
||||
description="Manage your admin preferences and account access."
|
||||
backHref="/admin/dashboard"
|
||||
user={userProfile}
|
||||
notificationPreferences={notificationPrefs}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (roles.includes("student")) {
|
||||
return <StudentSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
}
|
||||
if (roles.includes("parent")) {
|
||||
return <ParentSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
}
|
||||
return <TeacherSettingsView user={userProfile} notificationPreferences={notificationPrefs} />
|
||||
}
|
||||
|
||||
22
src/app/(dashboard)/settings/security/error.tsx
Normal file
22
src/app/(dashboard)/settings/security/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function SecuritySettingsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,安全设置页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
src/app/(dashboard)/settings/security/loading.tsx
Normal file
37
src/app/(dashboard)/settings/security/loading.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function SecuritySettingsLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-40" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
|
||||
<div className="max-w-2xl space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-40" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-10 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-4 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import type { StudentHomeworkProgressStatus } from "@/modules/homework/types"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = { title: "Dashboard - Next_Edu" }
|
||||
|
||||
const toWeekday = (d: Date): 1 | 2 | 3 | 4 | 5 | 6 | 7 => {
|
||||
// getDay() 返回 0(周日)-6(周六),转换为 1-7(周一为 1)
|
||||
const WEEKDAY_MAP = [7, 1, 2, 3, 4, 5, 6] as const
|
||||
@@ -85,10 +87,6 @@ export default async function StudentDashboardPage() {
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Dashboard</h2>
|
||||
<p className="text-muted-foreground">Welcome back, {student.name}.</p>
|
||||
</div>
|
||||
<StudentDashboard
|
||||
studentName={student.name}
|
||||
enrolledClassCount={classes.length}
|
||||
|
||||
22
src/app/(dashboard)/teacher/dashboard/error.tsx
Normal file
22
src/app/(dashboard)/teacher/dashboard/error.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function TeacherDashboardError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="页面加载失败"
|
||||
description="抱歉,页面加载时发生了意外错误。请稍后重试。"
|
||||
action={{
|
||||
label: "重试",
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
38
src/app/(dashboard)/teacher/dashboard/loading.tsx
Normal file
38
src/app/(dashboard)/teacher/dashboard/loading.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function TeacherDashboardLoading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-64" />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardHeader className="pb-2">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Skeleton className="h-8 w-16" />
|
||||
<Skeleton className="mt-2 h-3 w-28" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<Skeleton className="h-5 w-32" />
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-12 w-full" />
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = { title: "Dashboard - Next_Edu" }
|
||||
|
||||
export default async function TeacherDashboardPage(): Promise<JSX.Element> {
|
||||
await getAuthContext()
|
||||
const teacherId = await getTeacherIdForMutations()
|
||||
|
||||
@@ -6,6 +6,13 @@ import { createId } from "@paralleldrive/cuid2"
|
||||
import { requirePermission, PermissionDeniedError } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import type { ActionState } from "@/shared/types/action-state"
|
||||
import { sendBatchNotifications } from "@/modules/notifications"
|
||||
import type { NotificationPayload } from "@/modules/notifications"
|
||||
import { getAllUserIds, getUserIdsByGradeId } from "@/modules/users/data-access"
|
||||
import {
|
||||
getStudentIdsByClassId,
|
||||
getTeacherIdsByClassIds,
|
||||
} from "@/modules/classes/data-access"
|
||||
|
||||
import { CreateAnnouncementSchema, UpdateAnnouncementSchema } from "./schema"
|
||||
import {
|
||||
@@ -27,6 +34,60 @@ function handleActionError(e: unknown): ActionState<never> {
|
||||
return { success: false, message: "Unexpected error" }
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据公告类型解析目标用户 ID 列表。
|
||||
* - school: 全校所有用户
|
||||
* - grade: 该年级下所有用户
|
||||
* - class: 该班级学生 + 任课教师 + 班主任
|
||||
*/
|
||||
async function resolveTargetUserIds(announcement: Announcement): Promise<string[]> {
|
||||
if (announcement.type === "school") {
|
||||
return getAllUserIds()
|
||||
}
|
||||
|
||||
if (announcement.type === "grade" && announcement.targetGradeId) {
|
||||
return getUserIdsByGradeId(announcement.targetGradeId)
|
||||
}
|
||||
|
||||
if (announcement.type === "class" && announcement.targetClassId) {
|
||||
const [studentIds, teacherIds] = await Promise.all([
|
||||
getStudentIdsByClassId(announcement.targetClassId),
|
||||
getTeacherIdsByClassIds([announcement.targetClassId]),
|
||||
])
|
||||
return Array.from(new Set([...studentIds, ...teacherIds]))
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布公告后向目标用户批量发送通知。
|
||||
* 通知发送失败不影响公告发布本身,仅记录日志。
|
||||
*/
|
||||
async function notifyAnnouncementPublished(announcement: Announcement): Promise<void> {
|
||||
try {
|
||||
const targetUserIds = await resolveTargetUserIds(announcement)
|
||||
if (targetUserIds.length === 0) return
|
||||
|
||||
const payloads: NotificationPayload[] = targetUserIds.map((userId) => ({
|
||||
userId,
|
||||
title: `新公告:${announcement.title}`,
|
||||
content: announcement.content.slice(0, 200),
|
||||
type: "info",
|
||||
actionUrl: `/announcements/${announcement.id}`,
|
||||
metadata: {
|
||||
announcementId: announcement.id,
|
||||
announcementType: announcement.type,
|
||||
},
|
||||
}))
|
||||
|
||||
await sendBatchNotifications(payloads)
|
||||
} catch (error) {
|
||||
// 通知发送失败不阻塞公告发布流程,仅记录错误
|
||||
console.error("Failed to send announcement notifications:", error)
|
||||
}
|
||||
}
|
||||
|
||||
export async function createAnnouncementAction(
|
||||
prevState: ActionState<string> | null,
|
||||
formData: FormData
|
||||
@@ -74,6 +135,14 @@ export async function createAnnouncementAction(
|
||||
publishedAt,
|
||||
})
|
||||
|
||||
// 如果创建时直接发布,触发通知(失败不阻塞)
|
||||
if (isPublished) {
|
||||
const created = await getAnnouncementById(id)
|
||||
if (created) {
|
||||
await notifyAnnouncementPublished(created)
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/admin/announcements")
|
||||
revalidatePath("/announcements")
|
||||
|
||||
@@ -114,6 +183,7 @@ export async function updateAnnouncementAction(
|
||||
|
||||
const input = parsed.data
|
||||
const isPublished = input.status === "published"
|
||||
const wasPublished = existing.status === "published"
|
||||
const publishedAt = isPublished
|
||||
? existing.publishedAt
|
||||
? new Date(existing.publishedAt)
|
||||
@@ -133,6 +203,14 @@ export async function updateAnnouncementAction(
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
|
||||
// 当公告从非发布状态变为发布状态时,触发通知(失败不阻塞)
|
||||
if (isPublished && !wasPublished) {
|
||||
const updated = await getAnnouncementById(id)
|
||||
if (updated) {
|
||||
await notifyAnnouncementPublished(updated)
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/admin/announcements")
|
||||
revalidatePath(`/admin/announcements/${id}`)
|
||||
revalidatePath("/announcements")
|
||||
@@ -173,6 +251,9 @@ export async function publishAnnouncementAction(id: string): Promise<ActionState
|
||||
: new Date()
|
||||
await publishAnnouncementById(id, publishedAt)
|
||||
|
||||
// 发布成功后触发通知(失败不阻塞)
|
||||
await notifyAnnouncementPublished(existing)
|
||||
|
||||
revalidatePath("/admin/announcements")
|
||||
revalidatePath(`/admin/announcements/${id}`)
|
||||
revalidatePath("/announcements")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "server-only"
|
||||
|
||||
import { cache } from "react"
|
||||
import { and, desc, eq } from "drizzle-orm"
|
||||
import { and, desc, eq, or } from "drizzle-orm"
|
||||
|
||||
import { db } from "@/shared/db"
|
||||
import { announcements, users } from "@/shared/db/schema"
|
||||
@@ -61,6 +61,25 @@ export const getAnnouncements = cache(
|
||||
conditions.push(eq(announcements.type, params.type))
|
||||
}
|
||||
|
||||
// 受众过滤:当提供 audience 时,仅返回对该受众可见的公告
|
||||
// (type = 'school') OR (type = 'grade' AND target_grade_id = audience.gradeId)
|
||||
// OR (type = 'class' AND target_class_id = audience.classId)
|
||||
if (params?.audience) {
|
||||
const { gradeId, classId } = params.audience
|
||||
const gradeClause = gradeId
|
||||
? and(eq(announcements.type, "grade"), eq(announcements.targetGradeId, gradeId))
|
||||
: undefined
|
||||
const classClause = classId
|
||||
? and(eq(announcements.type, "class"), eq(announcements.targetClassId, classId))
|
||||
: undefined
|
||||
const orClauses = [
|
||||
eq(announcements.type, "school"),
|
||||
gradeClause,
|
||||
classClause,
|
||||
].filter((c): c is NonNullable<typeof c> => c !== undefined)
|
||||
conditions.push(or(...orClauses))
|
||||
}
|
||||
|
||||
const rows = await db
|
||||
.select({
|
||||
id: announcements.id,
|
||||
|
||||
@@ -24,6 +24,17 @@ export type GetAnnouncementsParams = {
|
||||
type?: AnnouncementType
|
||||
page?: number
|
||||
pageSize?: number
|
||||
/**
|
||||
* 受众过滤(用户端使用):当提供时,仅返回对该受众可见的公告。
|
||||
* - school 类型公告:对所有受众可见
|
||||
* - grade 类型公告:仅当 targetGradeId 与 audience.gradeId 匹配时可见
|
||||
* - class 类型公告:仅当 targetClassId 与 audience.classId 匹配时可见
|
||||
* 未提供时(管理端)返回所有公告。
|
||||
*/
|
||||
audience?: {
|
||||
gradeId?: string
|
||||
classId?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface AnnouncementInsertData {
|
||||
|
||||
@@ -39,9 +39,13 @@ import { formatDate } from "@/shared/lib/utils"
|
||||
export function AdminClassesClient({
|
||||
classes,
|
||||
teachers,
|
||||
schools,
|
||||
grades,
|
||||
}: {
|
||||
classes: AdminClassListItem[]
|
||||
teachers: TeacherOption[]
|
||||
schools: { id: string; name: string }[]
|
||||
grades: { id: string; name: string; school: { id: string; name: string } }[]
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const [isWorking, setIsWorking] = useState(false)
|
||||
@@ -50,18 +54,34 @@ export function AdminClassesClient({
|
||||
const [deleteItem, setDeleteItem] = useState<AdminClassListItem | null>(null)
|
||||
|
||||
const defaultTeacherId = useMemo(() => teachers[0]?.id ?? "", [teachers])
|
||||
const defaultSchoolId = useMemo(() => schools[0]?.id ?? "", [schools])
|
||||
const [createTeacherId, setCreateTeacherId] = useState(defaultTeacherId)
|
||||
const [createSchoolId, setCreateSchoolId] = useState(defaultSchoolId)
|
||||
const [createGradeId, setCreateGradeId] = useState("")
|
||||
const [editTeacherId, setEditTeacherId] = useState("")
|
||||
const [editSchoolId, setEditSchoolId] = useState("")
|
||||
const [editGradeId, setEditGradeId] = useState("")
|
||||
const [editSubjectTeachers, setEditSubjectTeachers] = useState<Array<{ subject: string; teacherId: string | null }>>([])
|
||||
|
||||
const createGrades = useMemo(() => grades.filter((g) => g.school.id === createSchoolId), [grades, createSchoolId])
|
||||
const editGrades = useMemo(() => grades.filter((g) => g.school.id === editSchoolId), [grades, editSchoolId])
|
||||
const selectedCreateSchool = schools.find((s) => s.id === createSchoolId)
|
||||
const selectedCreateGrade = grades.find((g) => g.id === createGradeId)
|
||||
const selectedEditSchool = schools.find((s) => s.id === editSchoolId)
|
||||
const selectedEditGrade = grades.find((g) => g.id === editGradeId)
|
||||
|
||||
useEffect(() => {
|
||||
if (!createOpen) return
|
||||
setCreateTeacherId(defaultTeacherId)
|
||||
}, [createOpen, defaultTeacherId])
|
||||
setCreateSchoolId(defaultSchoolId)
|
||||
setCreateGradeId("")
|
||||
}, [createOpen, defaultTeacherId, defaultSchoolId])
|
||||
|
||||
useEffect(() => {
|
||||
if (!editItem) return
|
||||
setEditTeacherId(editItem.teacher.id)
|
||||
setEditSchoolId(editItem.schoolId ?? "")
|
||||
setEditGradeId(editItem.gradeId ?? "")
|
||||
setEditSubjectTeachers(
|
||||
DEFAULT_CLASS_SUBJECTS.map((s) => ({
|
||||
subject: s,
|
||||
@@ -227,10 +247,30 @@ export function AdminClassesClient({
|
||||
</DialogHeader>
|
||||
<form action={handleCreate} className="space-y-4">
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="create-school-name" className="text-right">
|
||||
School
|
||||
</Label>
|
||||
<Input id="create-school-name" name="schoolName" className="col-span-3" placeholder="e.g. First Primary School" />
|
||||
<Label className="text-right">School</Label>
|
||||
<div className="col-span-3">
|
||||
<Select
|
||||
value={createSchoolId}
|
||||
onValueChange={(v) => {
|
||||
setCreateSchoolId(v)
|
||||
setCreateGradeId("")
|
||||
}}
|
||||
disabled={schools.length === 0}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={schools.length === 0 ? "No schools" : "Select a school"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{schools.map((s) => (
|
||||
<SelectItem key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input type="hidden" name="schoolId" value={createSchoolId} />
|
||||
<input type="hidden" name="schoolName" value={selectedCreateSchool?.name ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
@@ -241,10 +281,27 @@ export function AdminClassesClient({
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="create-grade" className="text-right">
|
||||
Grade
|
||||
</Label>
|
||||
<Input id="create-grade" name="grade" className="col-span-3" placeholder="e.g. Grade 10" />
|
||||
<Label className="text-right">Grade</Label>
|
||||
<div className="col-span-3">
|
||||
<Select
|
||||
value={createGradeId}
|
||||
onValueChange={setCreateGradeId}
|
||||
disabled={createGrades.length === 0}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={createGrades.length === 0 ? "No grades" : "Select a grade"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{createGrades.map((g) => (
|
||||
<SelectItem key={g.id} value={g.id}>
|
||||
{g.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input type="hidden" name="gradeId" value={createGradeId} />
|
||||
<input type="hidden" name="grade" value={selectedCreateGrade?.name ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
@@ -284,7 +341,7 @@ export function AdminClassesClient({
|
||||
<Button type="button" variant="outline" onClick={() => setCreateOpen(false)} disabled={isWorking}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isWorking || teachers.length === 0 || !createTeacherId}>
|
||||
<Button type="submit" disabled={isWorking || teachers.length === 0 || !createTeacherId || !createGradeId}>
|
||||
Create
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
@@ -306,15 +363,30 @@ export function AdminClassesClient({
|
||||
{editItem ? (
|
||||
<form action={handleUpdate} className="space-y-4">
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="edit-school-name" className="text-right">
|
||||
School
|
||||
</Label>
|
||||
<Input
|
||||
id="edit-school-name"
|
||||
name="schoolName"
|
||||
className="col-span-3"
|
||||
defaultValue={editItem.schoolName ?? ""}
|
||||
/>
|
||||
<Label className="text-right">School</Label>
|
||||
<div className="col-span-3">
|
||||
<Select
|
||||
value={editSchoolId}
|
||||
onValueChange={(v) => {
|
||||
setEditSchoolId(v)
|
||||
setEditGradeId("")
|
||||
}}
|
||||
disabled={schools.length === 0}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={schools.length === 0 ? "No schools" : "Select a school"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{schools.map((s) => (
|
||||
<SelectItem key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input type="hidden" name="schoolId" value={editSchoolId} />
|
||||
<input type="hidden" name="schoolName" value={selectedEditSchool?.name ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
@@ -325,10 +397,27 @@ export function AdminClassesClient({
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="edit-grade" className="text-right">
|
||||
Grade
|
||||
</Label>
|
||||
<Input id="edit-grade" name="grade" className="col-span-3" defaultValue={editItem.grade} />
|
||||
<Label className="text-right">Grade</Label>
|
||||
<div className="col-span-3">
|
||||
<Select
|
||||
value={editGradeId}
|
||||
onValueChange={setEditGradeId}
|
||||
disabled={editGrades.length === 0}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={editGrades.length === 0 ? "No grades" : "Select a grade"} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{editGrades.map((g) => (
|
||||
<SelectItem key={g.id} value={g.id}>
|
||||
{g.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input type="hidden" name="gradeId" value={editGradeId} />
|
||||
<input type="hidden" name="grade" value={selectedEditGrade?.name ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
|
||||
@@ -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)}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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's {today}. Here'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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -18,11 +18,13 @@ import {
|
||||
markMessageAsRead,
|
||||
deleteMessage,
|
||||
getRecipients,
|
||||
getUnreadMessageCount,
|
||||
} from "./data-access"
|
||||
import {
|
||||
getNotifications,
|
||||
markNotificationAsRead,
|
||||
markAllNotificationsAsRead,
|
||||
getUnreadNotificationCount,
|
||||
} from "@/modules/notifications/data-access"
|
||||
import {
|
||||
getNotificationPreferences,
|
||||
@@ -129,7 +131,7 @@ export async function deleteMessageAction(messageId: string): Promise<ActionStat
|
||||
}
|
||||
|
||||
export async function getMessagesAction(
|
||||
params: { type: MessageType; page?: number; pageSize?: number }
|
||||
params: { type: MessageType; page?: number; pageSize?: number; keyword?: string }
|
||||
): Promise<ActionState<{ items: Message[]; total: number; page: number; pageSize: number; totalPages: number }>> {
|
||||
try {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
@@ -179,6 +181,30 @@ export async function getRecipientsAction(): Promise<ActionState<RecipientOption
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUnreadMessageCountAction(): Promise<ActionState<number>> {
|
||||
try {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
const count = await getUnreadMessageCount(ctx.userId)
|
||||
return { success: true, data: count }
|
||||
} catch (e) {
|
||||
if (e instanceof PermissionDeniedError) return { success: false, message: e.message }
|
||||
if (e instanceof Error) return { success: false, message: e.message }
|
||||
return { success: false, message: "Unexpected error" }
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUnreadNotificationCountAction(): Promise<ActionState<number>> {
|
||||
try {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
const count = await getUnreadNotificationCount(ctx.userId)
|
||||
return { success: true, data: count }
|
||||
} catch (e) {
|
||||
if (e instanceof PermissionDeniedError) return { success: false, message: e.message }
|
||||
if (e instanceof Error) return { success: false, message: e.message }
|
||||
return { success: false, message: "Unexpected error" }
|
||||
}
|
||||
}
|
||||
|
||||
export async function getNotificationsAction(
|
||||
params?: { page?: number; pageSize?: number; unreadOnly?: boolean }
|
||||
): Promise<ActionState<{ items: Notification[]; total: number; page: number; pageSize: number; totalPages: number }>> {
|
||||
@@ -242,6 +268,13 @@ export async function updateNotificationPreferencesAction(
|
||||
|
||||
// 从 FormData 中解析布尔值(checkbox 提交 "on" 或不提交)
|
||||
const parseBool = (key: string): boolean => formData.get(key) === "on"
|
||||
// 从 FormData 中解析时间字符串("HH:mm"),空字符串转为 null
|
||||
const parseTime = (key: string): string | null => {
|
||||
const v = formData.get(key)
|
||||
if (typeof v !== "string") return null
|
||||
const trimmed = v.trim()
|
||||
return trimmed.length > 0 ? trimmed : null
|
||||
}
|
||||
|
||||
const parsed = UpdateNotificationPreferencesSchema.safeParse({
|
||||
emailEnabled: parseBool("emailEnabled"),
|
||||
@@ -252,6 +285,9 @@ export async function updateNotificationPreferencesAction(
|
||||
announcementNotifications: parseBool("announcementNotifications"),
|
||||
messageNotifications: parseBool("messageNotifications"),
|
||||
attendanceNotifications: parseBool("attendanceNotifications"),
|
||||
quietHoursEnabled: parseBool("quietHoursEnabled"),
|
||||
quietHoursStart: parseTime("quietHoursStart"),
|
||||
quietHoursEnd: parseTime("quietHoursEnd"),
|
||||
})
|
||||
|
||||
if (!parsed.success) {
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
"use client"
|
||||
|
||||
import { useMemo, useState } from "react"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import Link from "next/link"
|
||||
import { Mail, MailOpen, Plus, Send, Inbox } from "lucide-react"
|
||||
import { Mail, MailOpen, Plus, Send, Inbox, Search, Loader2 } from "lucide-react"
|
||||
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Tabs, TabsList, TabsTrigger } from "@/shared/components/ui/tabs"
|
||||
import { cn, formatDate } from "@/shared/lib/utils"
|
||||
import { usePermission } from "@/shared/hooks/use-permission"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
|
||||
import { getMessagesAction } from "../actions"
|
||||
import type { Message, MessageType } from "../types"
|
||||
|
||||
type Tab = "inbox" | "sent"
|
||||
@@ -27,13 +29,49 @@ export function MessageList({
|
||||
initialType?: MessageType
|
||||
}) {
|
||||
const [tab, setTab] = useState<Tab>(initialType === "sent" ? "sent" : "inbox")
|
||||
const [keyword, setKeyword] = useState("")
|
||||
const [searchResults, setSearchResults] = useState<{ kw: string; tab: Tab; items: Message[] } | null>(null)
|
||||
const { hasPermission } = usePermission()
|
||||
const canSend = hasPermission(Permissions.MESSAGE_SEND)
|
||||
|
||||
// 防抖搜索:keyword 或 tab 变化时调用 getMessagesAction
|
||||
useEffect(() => {
|
||||
const kw = keyword.trim()
|
||||
if (kw.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
let cancelled = false
|
||||
const timer = setTimeout(async () => {
|
||||
if (cancelled) return
|
||||
const res = await getMessagesAction({ type: tab, keyword: kw })
|
||||
if (cancelled) return
|
||||
if (res.success && res.data) {
|
||||
setSearchResults({ kw, tab, items: res.data.items })
|
||||
}
|
||||
}, 400)
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [keyword, tab])
|
||||
|
||||
// 当前搜索结果是否匹配最新的 keyword 和 tab
|
||||
const currentResults = searchResults && searchResults.kw === keyword.trim() && searchResults.tab === tab
|
||||
? searchResults.items
|
||||
: null
|
||||
|
||||
// 搜索中:keyword 非空且尚无匹配结果
|
||||
const searching = keyword.trim().length > 0 && currentResults === null
|
||||
|
||||
// 当 keyword 为空时使用 prop messages,否则使用搜索结果
|
||||
const displayMessages = currentResults ?? messages
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (tab === "inbox") return messages.filter((m) => m.receiverId === currentUserId)
|
||||
return messages.filter((m) => m.senderId === currentUserId)
|
||||
}, [messages, tab, currentUserId])
|
||||
if (tab === "inbox") return displayMessages.filter((m) => m.receiverId === currentUserId)
|
||||
return displayMessages.filter((m) => m.senderId === currentUserId)
|
||||
}, [displayMessages, tab, currentUserId])
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -60,6 +98,21 @@ export function MessageList({
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* 搜索框 */}
|
||||
<div className="relative">
|
||||
<Search className="text-muted-foreground absolute left-3 top-1/2 size-4 -translate-y-1/2" />
|
||||
<Input
|
||||
type="search"
|
||||
placeholder="Search messages by subject or content..."
|
||||
value={keyword}
|
||||
onChange={(e) => setKeyword(e.target.value)}
|
||||
className="pl-9"
|
||||
/>
|
||||
{searching ? (
|
||||
<Loader2 className="text-muted-foreground absolute right-3 top-1/2 size-4 -translate-y-1/2 animate-spin" />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{filtered.length === 0 ? (
|
||||
<EmptyState
|
||||
title={tab === "inbox" ? "Inbox is empty" : "No sent messages"}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { cn, formatDate } from "@/shared/lib/utils"
|
||||
|
||||
import {
|
||||
getNotificationsAction,
|
||||
getUnreadNotificationCountAction,
|
||||
markAllNotificationsAsReadAction,
|
||||
markNotificationAsReadAction,
|
||||
} from "../actions"
|
||||
@@ -40,16 +41,35 @@ export function NotificationDropdown() {
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
void (async () => {
|
||||
|
||||
const fetchNotifications = async () => {
|
||||
const res = await getNotificationsAction({ pageSize: 10 })
|
||||
if (!active) return
|
||||
if (res.success && res.data) {
|
||||
setNotifications(res.data.items)
|
||||
setUnreadCount(res.data.items.filter((n) => !n.isRead).length)
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
const fetchUnreadCount = async () => {
|
||||
const res = await getUnreadNotificationCountAction()
|
||||
if (!active) return
|
||||
if (res.success && typeof res.data === "number") {
|
||||
setUnreadCount(res.data)
|
||||
}
|
||||
}
|
||||
|
||||
void fetchNotifications()
|
||||
void fetchUnreadCount()
|
||||
|
||||
// 每 30 秒轮询刷新通知和未读计数
|
||||
const timer = setInterval(() => {
|
||||
void fetchNotifications()
|
||||
void fetchUnreadCount()
|
||||
}, 30_000)
|
||||
|
||||
return () => {
|
||||
active = false
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
51
src/modules/messaging/components/unread-message-badge.tsx
Normal file
51
src/modules/messaging/components/unread-message-badge.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
|
||||
import { getUnreadMessageCountAction } from "../actions"
|
||||
|
||||
/**
|
||||
* 未读消息计数徽章
|
||||
*
|
||||
* 在侧边栏 Messages 导航项旁显示未读私信数。
|
||||
* 每 60 秒轮询一次以保持计数更新。
|
||||
*/
|
||||
export function UnreadMessageBadge() {
|
||||
const [count, setCount] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
|
||||
const fetchCount = async () => {
|
||||
const res = await getUnreadMessageCountAction()
|
||||
if (!active) return
|
||||
if (res.success && typeof res.data === "number") {
|
||||
setCount(res.data)
|
||||
}
|
||||
}
|
||||
|
||||
void fetchCount()
|
||||
|
||||
const timer = setInterval(() => {
|
||||
void fetchCount()
|
||||
}, 60_000)
|
||||
|
||||
return () => {
|
||||
active = false
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [])
|
||||
|
||||
if (count <= 0) return null
|
||||
|
||||
return (
|
||||
<Badge
|
||||
variant="destructive"
|
||||
className="ml-auto flex h-5 min-w-5 items-center justify-center px-1.5 text-[10px]"
|
||||
>
|
||||
{count > 99 ? "99+" : count}
|
||||
</Badge>
|
||||
)
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import "server-only"
|
||||
|
||||
import { cache } from "react"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
import { and, count, desc, eq, inArray, or, type SQL } from "drizzle-orm"
|
||||
import { and, count, desc, eq, inArray, isNull, like, or, type SQL } from "drizzle-orm"
|
||||
|
||||
import { db } from "@/shared/db"
|
||||
import {
|
||||
@@ -86,13 +86,28 @@ export const getMessages = cache(
|
||||
const offset = (page - 1) * pageSize
|
||||
|
||||
const conds: SQL[] = []
|
||||
if (params.type === "inbox") conds.push(eq(messages.receiverId, params.userId))
|
||||
else if (params.type === "sent") conds.push(eq(messages.senderId, params.userId))
|
||||
else {
|
||||
const cond = or(eq(messages.receiverId, params.userId), eq(messages.senderId, params.userId))
|
||||
if (params.type === "inbox") {
|
||||
conds.push(eq(messages.receiverId, params.userId))
|
||||
conds.push(isNull(messages.receiverDeletedAt))
|
||||
} else if (params.type === "sent") {
|
||||
conds.push(eq(messages.senderId, params.userId))
|
||||
conds.push(isNull(messages.senderDeletedAt))
|
||||
} else {
|
||||
// all: 仅返回当前用户未删除的消息(发送方未删 或 接收方未删)
|
||||
const cond = or(
|
||||
and(eq(messages.receiverId, params.userId), isNull(messages.receiverDeletedAt)),
|
||||
and(eq(messages.senderId, params.userId), isNull(messages.senderDeletedAt))
|
||||
)
|
||||
if (cond) conds.push(cond)
|
||||
}
|
||||
|
||||
// 关键词搜索(匹配 subject 或 content)
|
||||
if (params.keyword && params.keyword.trim().length > 0) {
|
||||
const kw = `%${params.keyword.trim()}%`
|
||||
const kwCond = or(like(messages.subject, kw), like(messages.content, kw))
|
||||
if (kwCond) conds.push(kwCond)
|
||||
}
|
||||
|
||||
const where = and(...conds)
|
||||
const [rows, [totalRow]] = await Promise.all([
|
||||
db.select().from(messages).where(where).orderBy(desc(messages.createdAt)).limit(pageSize).offset(offset),
|
||||
@@ -111,7 +126,15 @@ export const getMessageById = cache(
|
||||
const [row] = await db
|
||||
.select()
|
||||
.from(messages)
|
||||
.where(and(eq(messages.id, id), or(eq(messages.senderId, userId), eq(messages.receiverId, userId))))
|
||||
.where(
|
||||
and(
|
||||
eq(messages.id, id),
|
||||
or(
|
||||
and(eq(messages.senderId, userId), isNull(messages.senderDeletedAt)),
|
||||
and(eq(messages.receiverId, userId), isNull(messages.receiverDeletedAt))
|
||||
)
|
||||
)
|
||||
)
|
||||
.limit(1)
|
||||
if (!row) return null
|
||||
const nameMap = await resolveUserNames([row.senderId, row.receiverId])
|
||||
@@ -155,16 +178,23 @@ export async function markMessageAsRead(id: string, userId: string): Promise<voi
|
||||
}
|
||||
|
||||
export async function deleteMessage(id: string, userId: string): Promise<void> {
|
||||
const now = new Date()
|
||||
// 软删除:发送方删除设置 senderDeletedAt,接收方删除设置 receiverDeletedAt,互不影响
|
||||
await db
|
||||
.delete(messages)
|
||||
.where(and(eq(messages.id, id), or(eq(messages.senderId, userId), eq(messages.receiverId, userId))))
|
||||
.update(messages)
|
||||
.set({ senderDeletedAt: now })
|
||||
.where(and(eq(messages.id, id), eq(messages.senderId, userId)))
|
||||
await db
|
||||
.update(messages)
|
||||
.set({ receiverDeletedAt: now })
|
||||
.where(and(eq(messages.id, id), eq(messages.receiverId, userId)))
|
||||
}
|
||||
|
||||
export const getUnreadMessageCount = cache(async (userId: string): Promise<number> => {
|
||||
const [row] = await db
|
||||
.select({ value: count() })
|
||||
.from(messages)
|
||||
.where(and(eq(messages.receiverId, userId), eq(messages.isRead, false)))
|
||||
.where(and(eq(messages.receiverId, userId), eq(messages.isRead, false), isNull(messages.receiverDeletedAt)))
|
||||
return Number(row?.value ?? 0)
|
||||
})
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export const MessageIdSchema = z.object({
|
||||
|
||||
export type MessageIdInput = z.infer<typeof MessageIdSchema>
|
||||
|
||||
/** 校验通知偏好更新表单(8 个布尔字段,来自 checkbox FormData) */
|
||||
/** 校验通知偏好更新表单(8 个布尔字段 + 免打扰时段,来自 checkbox/FormData) */
|
||||
export const UpdateNotificationPreferencesSchema = z.object({
|
||||
emailEnabled: z.boolean(),
|
||||
smsEnabled: z.boolean(),
|
||||
@@ -34,6 +34,9 @@ export const UpdateNotificationPreferencesSchema = z.object({
|
||||
announcementNotifications: z.boolean(),
|
||||
messageNotifications: z.boolean(),
|
||||
attendanceNotifications: z.boolean(),
|
||||
quietHoursEnabled: z.boolean(),
|
||||
quietHoursStart: z.string().trim().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "Invalid time format").nullable().optional(),
|
||||
quietHoursEnd: z.string().trim().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "Invalid time format").nullable().optional(),
|
||||
})
|
||||
|
||||
export type UpdateNotificationPreferencesFormInput = z.infer<
|
||||
|
||||
@@ -33,6 +33,7 @@ export interface GetMessagesParams {
|
||||
type: MessageType
|
||||
page?: number
|
||||
pageSize?: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateMessageInput {
|
||||
|
||||
@@ -39,6 +39,9 @@ const mapRow = (
|
||||
announcementNotifications: row.announcementNotifications,
|
||||
messageNotifications: row.messageNotifications,
|
||||
attendanceNotifications: row.attendanceNotifications,
|
||||
quietHoursEnabled: row.quietHoursEnabled,
|
||||
quietHoursStart: row.quietHoursStart,
|
||||
quietHoursEnd: row.quietHoursEnd,
|
||||
createdAt: toIso(row.createdAt),
|
||||
updatedAt: toIso(row.updatedAt),
|
||||
})
|
||||
@@ -53,6 +56,9 @@ const DEFAULTS = {
|
||||
announcementNotifications: true,
|
||||
messageNotifications: true,
|
||||
attendanceNotifications: true,
|
||||
quietHoursEnabled: false,
|
||||
quietHoursStart: null,
|
||||
quietHoursEnd: null,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +139,9 @@ export async function upsertNotificationPreferences(
|
||||
if (input.announcementNotifications !== undefined) updateData.announcementNotifications = input.announcementNotifications
|
||||
if (input.messageNotifications !== undefined) updateData.messageNotifications = input.messageNotifications
|
||||
if (input.attendanceNotifications !== undefined) updateData.attendanceNotifications = input.attendanceNotifications
|
||||
if (input.quietHoursEnabled !== undefined) updateData.quietHoursEnabled = input.quietHoursEnabled
|
||||
if (input.quietHoursStart !== undefined) updateData.quietHoursStart = input.quietHoursStart
|
||||
if (input.quietHoursEnd !== undefined) updateData.quietHoursEnd = input.quietHoursEnd
|
||||
|
||||
if (Object.keys(updateData).length === 0) {
|
||||
return mapRow(existing)
|
||||
@@ -165,6 +174,9 @@ export async function upsertNotificationPreferences(
|
||||
announcementNotifications: input.announcementNotifications ?? DEFAULTS.announcementNotifications,
|
||||
messageNotifications: input.messageNotifications ?? DEFAULTS.messageNotifications,
|
||||
attendanceNotifications: input.attendanceNotifications ?? DEFAULTS.attendanceNotifications,
|
||||
quietHoursEnabled: input.quietHoursEnabled ?? DEFAULTS.quietHoursEnabled,
|
||||
quietHoursStart: input.quietHoursStart ?? DEFAULTS.quietHoursStart,
|
||||
quietHoursEnd: input.quietHoursEnd ?? DEFAULTS.quietHoursEnd,
|
||||
})
|
||||
|
||||
const [created] = await db
|
||||
|
||||
@@ -95,6 +95,9 @@ export interface NotificationPreferences {
|
||||
announcementNotifications: boolean
|
||||
messageNotifications: boolean
|
||||
attendanceNotifications: boolean
|
||||
quietHoursEnabled: boolean
|
||||
quietHoursStart: string | null
|
||||
quietHoursEnd: string | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
@@ -109,6 +112,9 @@ export interface UpdateNotificationPreferencesInput {
|
||||
announcementNotifications?: boolean
|
||||
messageNotifications?: boolean
|
||||
attendanceNotifications?: boolean
|
||||
quietHoursEnabled?: boolean
|
||||
quietHoursStart?: string | null
|
||||
quietHoursEnd?: string | null
|
||||
}
|
||||
|
||||
/** SMS 渠道配置 */
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
import * as React from "react"
|
||||
import { useActionState } from "react"
|
||||
import { useFormStatus } from "react-dom"
|
||||
import { Loader2, Save, Bell, Mail, MessageSquare, Megaphone, GraduationCap, BookOpen, CalendarCheck } from "lucide-react"
|
||||
import { Loader2, Save, Bell, Mail, MessageSquare, Megaphone, GraduationCap, BookOpen, CalendarCheck, Moon } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Input } from "@/shared/components/ui/input"
|
||||
import { Switch } from "@/shared/components/ui/switch"
|
||||
import { Label } from "@/shared/components/ui/label"
|
||||
import { Separator } from "@/shared/components/ui/separator"
|
||||
import { cn } from "@/shared/lib/utils"
|
||||
import { updateNotificationPreferencesAction } from "@/modules/messaging/actions"
|
||||
import type { NotificationPreferences } from "@/modules/notifications/types"
|
||||
|
||||
@@ -131,6 +133,11 @@ export function NotificationPreferencesForm({ preferences }: NotificationPrefere
|
||||
messageNotifications: preferences.messageNotifications,
|
||||
attendanceNotifications: preferences.attendanceNotifications,
|
||||
})
|
||||
const [quietHours, setQuietHours] = React.useState({
|
||||
quietHoursEnabled: preferences.quietHoursEnabled,
|
||||
quietHoursStart: preferences.quietHoursStart ?? "",
|
||||
quietHoursEnd: preferences.quietHoursEnd ?? "",
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
if (state?.success) {
|
||||
@@ -148,6 +155,10 @@ export function NotificationPreferencesForm({ preferences }: NotificationPrefere
|
||||
setCategories((prev) => ({ ...prev, [key]: !prev[key] }))
|
||||
}
|
||||
|
||||
const toggleQuietHours = () => {
|
||||
setQuietHours((prev) => ({ ...prev, quietHoursEnabled: !prev.quietHoursEnabled }))
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -250,6 +261,80 @@ export function NotificationPreferencesForm({ preferences }: NotificationPrefere
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* 免打扰时段 */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h4 className="text-sm font-medium">Quiet Hours</h4>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Suppress non-urgent notifications during a specified time period each day.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex h-9 w-9 items-center justify-center rounded-md bg-muted">
|
||||
<Moon className="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="quietHoursEnabled" className="text-sm font-medium cursor-pointer">
|
||||
Enable Quiet Hours
|
||||
</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
When enabled, only urgent notifications will be delivered during the specified hours.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="quietHoursEnabled"
|
||||
checked={quietHours.quietHoursEnabled}
|
||||
onChange={toggleQuietHours}
|
||||
className="sr-only"
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Switch
|
||||
id="quietHoursEnabled"
|
||||
checked={quietHours.quietHoursEnabled}
|
||||
onCheckedChange={toggleQuietHours}
|
||||
aria-label="Enable Quiet Hours"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className={cn(
|
||||
"grid gap-4 sm:grid-cols-2 transition-opacity",
|
||||
!quietHours.quietHoursEnabled && "pointer-events-none opacity-50"
|
||||
)}>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="quietHoursStart" className="text-xs font-medium">
|
||||
Start Time
|
||||
</Label>
|
||||
<Input
|
||||
id="quietHoursStart"
|
||||
name="quietHoursStart"
|
||||
type="time"
|
||||
value={quietHours.quietHoursStart}
|
||||
onChange={(e) => setQuietHours((prev) => ({ ...prev, quietHoursStart: e.target.value }))}
|
||||
disabled={!quietHours.quietHoursEnabled}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="quietHoursEnd" className="text-xs font-medium">
|
||||
End Time
|
||||
</Label>
|
||||
<Input
|
||||
id="quietHoursEnd"
|
||||
name="quietHoursEnd"
|
||||
type="time"
|
||||
value={quietHours.quietHoursEnd}
|
||||
onChange={(e) => setQuietHours((prev) => ({ ...prev, quietHoursEnd: e.target.value }))}
|
||||
disabled={!quietHours.quietHoursEnabled}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardFooter className="flex justify-end border-t px-6 py-4">
|
||||
<SubmitButton />
|
||||
|
||||
65
src/modules/settings/components/parent-settings-view.tsx
Normal file
65
src/modules/settings/components/parent-settings-view.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
"use client"
|
||||
|
||||
import Link from "next/link"
|
||||
import { LayoutDashboard, GraduationCap, CalendarDays, ClipboardList } from "lucide-react"
|
||||
|
||||
import { SettingsView } from "@/modules/settings/components/settings-view"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { UserProfile } from "@/modules/users/data-access"
|
||||
import type { NotificationPreferences } from "@/modules/notifications/types"
|
||||
|
||||
interface ParentSettingsViewProps {
|
||||
user: UserProfile
|
||||
notificationPreferences: NotificationPreferences
|
||||
}
|
||||
|
||||
export function ParentSettingsView({ user, notificationPreferences }: ParentSettingsViewProps) {
|
||||
const generalExtra = (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Quick links</CardTitle>
|
||||
<CardDescription>Common places you may want to visit.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-wrap gap-2">
|
||||
<Button asChild variant="outline">
|
||||
<Link href="/profile">Profile</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline" className="gap-2">
|
||||
<Link href="/parent/dashboard">
|
||||
<LayoutDashboard className="h-4 w-4" />
|
||||
Dashboard
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline" className="gap-2">
|
||||
<Link href="/parent/children">
|
||||
<GraduationCap className="h-4 w-4" />
|
||||
Children
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline" className="gap-2">
|
||||
<Link href="/parent/grades">
|
||||
<ClipboardList className="h-4 w-4" />
|
||||
Grades
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline" className="gap-2">
|
||||
<Link href="/parent/attendance">
|
||||
<CalendarDays className="h-4 w-4" />
|
||||
Attendance
|
||||
</Link>
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
|
||||
return (
|
||||
<SettingsView
|
||||
description="Manage your preferences and family account access."
|
||||
backHref="/parent/dashboard"
|
||||
user={user}
|
||||
notificationPreferences={notificationPreferences}
|
||||
generalExtra={generalExtra}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
} from "@/shared/lib/password-policy"
|
||||
import type { ActionState } from "@/shared/types/action-state"
|
||||
|
||||
const STRENGTH_META: Record<PasswordStrength, { value: number; label: string; barClass: string }> = {
|
||||
weak: { value: 33, label: "Weak", barClass: "h-2 [&>div]:bg-red-500" },
|
||||
medium: { value: 66, label: "Medium", barClass: "h-2 [&>div]:bg-yellow-500" },
|
||||
strong: { value: 100, label: "Strong", barClass: "h-2 [&>div]:bg-green-500" },
|
||||
const STRENGTH_META: Record<PasswordStrength, { value: number; label: string; barClassName: string; indicatorClassName: string }> = {
|
||||
weak: { value: 33, label: "Weak", barClassName: "h-2", indicatorClassName: "bg-red-500" },
|
||||
medium: { value: 66, label: "Medium", barClassName: "h-2", indicatorClassName: "bg-yellow-500" },
|
||||
strong: { value: 100, label: "Strong", barClassName: "h-2", indicatorClassName: "bg-green-500" },
|
||||
}
|
||||
|
||||
function SubmitButton() {
|
||||
@@ -130,7 +130,7 @@ export function PasswordChangeForm() {
|
||||
<span className="text-muted-foreground">Password strength</span>
|
||||
<span className="font-medium">{meta.label}</span>
|
||||
</div>
|
||||
<Progress value={meta.value} className={meta.barClass} />
|
||||
<Progress value={meta.value} className={meta.barClassName} indicatorClassName={meta.indicatorClassName} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
"use client"
|
||||
|
||||
import Link from "next/link"
|
||||
import type { ReactNode } from "react"
|
||||
import { User, Palette, Lock, Bell } from "lucide-react"
|
||||
import { useRouter, useSearchParams } from "next/navigation"
|
||||
import { Suspense, type ReactNode } from "react"
|
||||
import { User, Palette, Lock, Bell, Sparkles } from "lucide-react"
|
||||
import { signOut } from "next-auth/react"
|
||||
|
||||
import { ThemePreferencesCard } from "@/modules/settings/components/theme-preferences-card"
|
||||
import { ProfileSettingsForm } from "@/modules/settings/components/profile-settings-form"
|
||||
import { PasswordChangeForm } from "@/modules/settings/components/password-change-form"
|
||||
import { NotificationPreferencesForm } from "@/modules/settings/components/notification-preferences-form"
|
||||
import { AiProviderSettingsCard } from "@/modules/settings/components/ai-provider-settings-card"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/shared/components/ui/tabs"
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/shared/components/ui/alert-dialog"
|
||||
import { UserProfile } from "@/modules/users/data-access"
|
||||
import type { NotificationPreferences } from "@/modules/notifications/types"
|
||||
import { usePermission } from "@/shared/hooks/use-permission"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
|
||||
interface SettingsViewProps {
|
||||
/** 页面副标题描述 */
|
||||
@@ -28,24 +43,52 @@ interface SettingsViewProps {
|
||||
generalExtra?: ReactNode
|
||||
}
|
||||
|
||||
const VALID_TABS = ["general", "notifications", "appearance", "security", "ai"] as const
|
||||
type TabValue = (typeof VALID_TABS)[number]
|
||||
|
||||
function isTabValue(value: string | null): value is TabValue {
|
||||
return value !== null && (VALID_TABS as readonly string[]).includes(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一设置页视图
|
||||
*
|
||||
* 消除 admin / teacher / student 三个设置视图的重复布局:
|
||||
* 消除 admin / teacher / student / parent 四个设置视图的重复布局:
|
||||
* - 相同的页面头部(标题 + 描述 + 返回按钮)
|
||||
* - 相同的 4 个标签页(General / Notifications / Appearance / Security)
|
||||
* - 相同的标签页(General / Notifications / Appearance / Security / AI)
|
||||
* - 相同的 Notifications / Appearance / Security 标签页内容
|
||||
* - 相同的 Session 卡片(登出)
|
||||
*
|
||||
* 角色差异通过 `description`、`backHref` 和 `generalExtra` 三个 props 注入。
|
||||
* 当前激活的标签页通过 URL `?tab=` 参数持久化。
|
||||
*/
|
||||
export function SettingsView({
|
||||
function SettingsViewInner({
|
||||
description,
|
||||
backHref,
|
||||
user,
|
||||
notificationPreferences,
|
||||
generalExtra,
|
||||
}: SettingsViewProps) {
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const { hasPermission } = usePermission()
|
||||
|
||||
const tabParam = searchParams.get("tab")
|
||||
const activeTab: TabValue = isTabValue(tabParam) ? tabParam : "general"
|
||||
|
||||
const handleTabChange = (value: string) => {
|
||||
const params = new URLSearchParams(searchParams.toString())
|
||||
if (value === "general") {
|
||||
params.delete("tab")
|
||||
} else {
|
||||
params.set("tab", value)
|
||||
}
|
||||
const query = params.toString()
|
||||
router.push(query ? `?${query}` : "?", { scroll: false })
|
||||
}
|
||||
|
||||
const canConfigureAi = hasPermission(Permissions.AI_CONFIGURE)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-8 p-8">
|
||||
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center">
|
||||
@@ -60,7 +103,7 @@ export function SettingsView({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Tabs defaultValue="general" className="w-full">
|
||||
<Tabs value={activeTab} onValueChange={handleTabChange} className="w-full">
|
||||
<TabsList className="w-full justify-start">
|
||||
<TabsTrigger value="general" className="gap-2">
|
||||
<User className="h-4 w-4" />
|
||||
@@ -78,6 +121,12 @@ export function SettingsView({
|
||||
<Lock className="h-4 w-4" />
|
||||
Security
|
||||
</TabsTrigger>
|
||||
{canConfigureAi ? (
|
||||
<TabsTrigger value="ai" className="gap-2">
|
||||
<Sparkles className="h-4 w-4" />
|
||||
AI
|
||||
</TabsTrigger>
|
||||
) : null}
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="general" className="mt-6 space-y-6">
|
||||
@@ -105,13 +154,43 @@ export function SettingsView({
|
||||
<div className="text-sm font-medium">Sign out</div>
|
||||
<div className="text-sm text-muted-foreground">Return to the login screen.</div>
|
||||
</div>
|
||||
<Button variant="outline" onClick={() => signOut({ callbackUrl: "/login" })}>
|
||||
Log out
|
||||
</Button>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline">Log out</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Confirm sign out</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Are you sure you want to sign out? You will be returned to the login screen.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={() => signOut({ callbackUrl: "/login" })}>
|
||||
Sign out
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
|
||||
{canConfigureAi ? (
|
||||
<TabsContent value="ai" className="mt-6 space-y-6">
|
||||
<AiProviderSettingsCard />
|
||||
</TabsContent>
|
||||
) : null}
|
||||
</Tabs>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function SettingsView(props: SettingsViewProps) {
|
||||
return (
|
||||
<Suspense fallback={null}>
|
||||
<SettingsViewInner {...props} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,11 @@ import { cn } from "@/shared/lib/utils"
|
||||
|
||||
const Progress = React.forwardRef<
|
||||
React.ElementRef<typeof ProgressPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
|
||||
>(({ className, value, ...props }, ref) => (
|
||||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & {
|
||||
/** Optional className applied to the inner indicator element. */
|
||||
indicatorClassName?: string
|
||||
}
|
||||
>(({ className, value, indicatorClassName, ...props }, ref) => (
|
||||
<ProgressPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
@@ -18,7 +21,7 @@ const Progress = React.forwardRef<
|
||||
{...props}
|
||||
>
|
||||
<ProgressPrimitive.Indicator
|
||||
className="h-full w-full flex-1 bg-primary transition-all"
|
||||
className={cn("h-full w-full flex-1 bg-primary transition-all", indicatorClassName)}
|
||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||
/>
|
||||
</ProgressPrimitive.Root>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
int,
|
||||
primaryKey,
|
||||
index,
|
||||
uniqueIndex,
|
||||
json,
|
||||
mysqlEnum,
|
||||
boolean,
|
||||
@@ -377,6 +378,52 @@ export const classSubjectTeachers = mysqlTable("class_subject_teachers", {
|
||||
}).onDelete("cascade"),
|
||||
}));
|
||||
|
||||
/**
|
||||
* 班级邀请码表(v3 新增,对标 Google Classroom / 钉钉教育 / 智学网)。
|
||||
*
|
||||
* 设计要点:
|
||||
* - 独立表而非挂在 classes 表上,支持有效期/次数/审计/多码并存
|
||||
* - 6 位字母数字(剔除歧义字符 0/O/1/I/L),空间 22^6 ≈ 1.13 亿
|
||||
* - status 枚举:active/disabled/expired/exhausted
|
||||
* - max_uses NULL=无限;expires_at NULL=永久
|
||||
* - 软删除:revoke 时设置 status=disabled + revoked_at,不物理删除(审计需要)
|
||||
*
|
||||
* 与 classes.invitationCode 的关系:
|
||||
* - 新表上线后,enrollStudentByInvitationCode / enrollTeacherByInvitationCode 优先查新表
|
||||
* - classes.invitationCode 保留作为 fallback,下个版本移除
|
||||
*/
|
||||
export const classInvitationCodeStatusEnum = mysqlEnum("class_invitation_code_status", [
|
||||
"active",
|
||||
"disabled",
|
||||
"expired",
|
||||
"exhausted",
|
||||
]);
|
||||
|
||||
export const classInvitationCodes = mysqlTable("class_invitation_codes", {
|
||||
id: id("id").primaryKey(),
|
||||
classId: varchar("class_id", { length: 128 }).notNull().references(() => classes.id, { onDelete: "cascade" }),
|
||||
code: varchar("code", { length: 8 }).notNull().unique(),
|
||||
status: classInvitationCodeStatusEnum.default("active").notNull(),
|
||||
maxUses: int("max_uses"),
|
||||
usedCount: int("used_count").default(0).notNull(),
|
||||
expiresAt: timestamp("expires_at"),
|
||||
createdBy: varchar("created_by", { length: 128 }).notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
|
||||
revokedAt: timestamp("revoked_at"),
|
||||
revokedBy: varchar("revoked_by", { length: 128 }),
|
||||
note: varchar("note", { length: 255 }),
|
||||
}, (table) => ({
|
||||
codeIdx: uniqueIndex("class_invitation_codes_code_idx").on(table.code),
|
||||
classIdx: index("class_invitation_codes_class_idx").on(table.classId),
|
||||
statusExpiresIdx: index("class_invitation_codes_status_expires_idx").on(table.status, table.expiresAt),
|
||||
classFk: foreignKey({
|
||||
columns: [table.classId],
|
||||
foreignColumns: [classes.id],
|
||||
name: "cic_c_fk",
|
||||
}).onDelete("cascade"),
|
||||
}));
|
||||
|
||||
export const classEnrollments = mysqlTable("class_enrollments", {
|
||||
classId: varchar("class_id", { length: 128 }).notNull(),
|
||||
studentId: varchar("student_id", { length: 128 }).notNull(),
|
||||
@@ -514,7 +561,7 @@ export const submissionAnswers = mysqlTable("submission_answers", {
|
||||
|
||||
export const homeworkAssignments = mysqlTable("homework_assignments", {
|
||||
id: id("id").primaryKey(),
|
||||
sourceExamId: varchar("source_exam_id", { length: 128 }).notNull(),
|
||||
sourceExamId: varchar("source_exam_id", { length: 128 }),
|
||||
title: varchar("title", { length: 255 }).notNull(),
|
||||
description: text("description"),
|
||||
structure: json("structure"),
|
||||
@@ -904,6 +951,9 @@ export const messages = mysqlTable("messages", {
|
||||
isRead: boolean("is_read").default(false).notNull(),
|
||||
readAt: timestamp("read_at", { mode: "date" }),
|
||||
parentMessageId: varchar("parent_message_id", { length: 128 }), // 回复链
|
||||
// 软删除:发送方/接收方各自独立删除,互不影响
|
||||
senderDeletedAt: timestamp("sender_deleted_at", { mode: "date" }),
|
||||
receiverDeletedAt: timestamp("receiver_deleted_at", { mode: "date" }),
|
||||
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
|
||||
}, (table) => ({
|
||||
senderIdx: index("messages_sender_idx").on(table.senderId),
|
||||
@@ -944,6 +994,10 @@ export const notificationPreferences = mysqlTable("notification_preferences", {
|
||||
announcementNotifications: boolean("announcement_notifications").default(true).notNull(),
|
||||
messageNotifications: boolean("message_notifications").default(true).notNull(),
|
||||
attendanceNotifications: boolean("attendance_notifications").default(true).notNull(),
|
||||
// 免打扰时段(格式 "HH:mm",如 "22:00")
|
||||
quietHoursEnabled: boolean("quiet_hours_enabled").default(false).notNull(),
|
||||
quietHoursStart: varchar("quiet_hours_start", { length: 5 }),
|
||||
quietHoursEnd: varchar("quiet_hours_end", { length: 5 }),
|
||||
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().onUpdateNow().notNull(),
|
||||
}, (table) => ({
|
||||
|
||||
Reference in New Issue
Block a user