feat(announcements,messaging): 公告与消息模块审计重构 — i18n + Error Boundary + a11y
- 新增审计报告 docs/architecture/audit/announcements-messages-audit-report.md - 新增中英双语 i18n 字典 announcements.json / messages.json(11/13 个命名空间) - 重构所有 announcements 和 messaging 组件接入 next-intl(useTranslations) - 所有页面 page.tsx 使用 generateMetadata + getTranslations 替代硬编码 metadata - 新增 7 个 error.tsx 错误边界(4 公告 + 3 消息),统一 EmptyState + i18n + 重试 - a11y 改进:announcement-card / message-list / notification-dropdown 添加 aria-label - 同步架构图 004 和 005:i18n.messages 清单 + 已知问题修复记录
This commit is contained in:
24
src/app/(dashboard)/admin/announcements/[id]/error.tsx
Normal file
24
src/app/(dashboard)/admin/announcements/[id]/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function EditAnnouncementError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("announcements")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
@@ -8,13 +9,16 @@ import { getAnnouncementById } from "@/modules/announcements/data-access"
|
||||
import { getGrades } from "@/modules/school/data-access"
|
||||
import { AnnouncementForm } from "@/modules/announcements/components/announcement-form"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "编辑公告 - Next_Edu",
|
||||
description: "更新公告详情",
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("announcements")
|
||||
return {
|
||||
title: t("title.edit"),
|
||||
description: t("description.edit"),
|
||||
}
|
||||
}
|
||||
|
||||
export default async function EditAnnouncementPage({
|
||||
params,
|
||||
}: {
|
||||
@@ -22,6 +26,7 @@ export default async function EditAnnouncementPage({
|
||||
}): Promise<JSX.Element> {
|
||||
await requirePermission(Permissions.ANNOUNCEMENT_MANAGE)
|
||||
const { id } = await params
|
||||
const t = await getTranslations("announcements")
|
||||
|
||||
const [announcement, grades] = await Promise.all([
|
||||
getAnnouncementById(id),
|
||||
@@ -33,8 +38,8 @@ export default async function EditAnnouncementPage({
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">编辑公告</h2>
|
||||
<p className="text-muted-foreground">更新公告详情。</p>
|
||||
<h2 className="text-2xl font-bold tracking-tight">{t("title.edit")}</h2>
|
||||
<p className="text-muted-foreground">{t("description.edit")}</p>
|
||||
</div>
|
||||
<AnnouncementForm
|
||||
mode="edit"
|
||||
|
||||
24
src/app/(dashboard)/admin/announcements/error.tsx
Normal file
24
src/app/(dashboard)/admin/announcements/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AdminAnnouncementsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("announcements")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
@@ -10,13 +11,16 @@ import { AdminAnnouncementsView } from "@/modules/announcements/components/admin
|
||||
import { getSearchParam, type SearchParams } from "@/shared/lib/utils"
|
||||
import type { AnnouncementStatus } from "@/modules/announcements/types"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "公告管理 - Next_Edu",
|
||||
description: "管理系统公告,支持草稿、发布与归档",
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("announcements")
|
||||
return {
|
||||
title: t("title.adminList"),
|
||||
description: t("description.adminList"),
|
||||
}
|
||||
}
|
||||
|
||||
const isValidStatus = (v?: string): v is AnnouncementStatus =>
|
||||
v === "draft" || v === "published" || v === "archived"
|
||||
|
||||
|
||||
24
src/app/(dashboard)/announcements/[id]/error.tsx
Normal file
24
src/app/(dashboard)/announcements/[id]/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AnnouncementDetailError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("announcements")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
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 async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("announcements")
|
||||
return { title: t("title.detail") }
|
||||
}
|
||||
|
||||
export default async function AnnouncementDetailPage({
|
||||
params,
|
||||
}: {
|
||||
|
||||
24
src/app/(dashboard)/announcements/error.tsx
Normal file
24
src/app/(dashboard)/announcements/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function AnnouncementsError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("announcements")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Metadata } from "next"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
@@ -12,8 +13,9 @@ import {
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Announcements",
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("announcements")
|
||||
return { title: t("title.list") }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +78,7 @@ async function resolveAudience(ctx: {
|
||||
}
|
||||
|
||||
export default async function AnnouncementsPage() {
|
||||
const t = await getTranslations("announcements")
|
||||
const ctx = await requirePermission(Permissions.ANNOUNCEMENT_READ)
|
||||
const audience = await resolveAudience(ctx)
|
||||
|
||||
@@ -87,9 +90,9 @@ export default async function AnnouncementsPage() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Announcements</h2>
|
||||
<h2 className="text-2xl font-bold tracking-tight">{t("title.list")}</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Stay up to date with the latest school announcements.
|
||||
{t("description.list")}
|
||||
</p>
|
||||
</div>
|
||||
<AnnouncementList
|
||||
|
||||
24
src/app/(dashboard)/messages/[id]/error.tsx
Normal file
24
src/app/(dashboard)/messages/[id]/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function MessageDetailError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("messages")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import type { Metadata } from "next"
|
||||
import { after } from "next/server"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getMessageById, markMessageAsRead } from "@/modules/messaging/data-access"
|
||||
@@ -7,15 +9,16 @@ import { MessageDetail } from "@/modules/messaging/components/message-detail"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
title: "Message Detail",
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("messages")
|
||||
return { title: t("title.detail") }
|
||||
}
|
||||
|
||||
export default async function MessageDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
}): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
const { id } = await params
|
||||
|
||||
|
||||
24
src/app/(dashboard)/messages/compose/error.tsx
Normal file
24
src/app/(dashboard)/messages/compose/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function ComposeMessageError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("messages")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import type { Metadata } from "next"
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getRecipients } from "@/modules/messaging/data-access"
|
||||
@@ -5,17 +8,22 @@ import { MessageCompose } from "@/modules/messaging/components/message-compose"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
title: "Compose Message",
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("messages")
|
||||
return {
|
||||
title: t("title.compose"),
|
||||
description: t("description.compose"),
|
||||
}
|
||||
}
|
||||
|
||||
export default async function ComposeMessagePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ parentId?: string; receiverId?: string; subject?: string }>
|
||||
}) {
|
||||
}): Promise<JSX.Element> {
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_SEND)
|
||||
const sp = await searchParams
|
||||
const t = await getTranslations("messages")
|
||||
|
||||
const recipients = await getRecipients(ctx.userId, ctx.dataScope)
|
||||
|
||||
@@ -23,8 +31,8 @@ export default async function ComposeMessagePage({
|
||||
<div className="flex h-full flex-col p-8">
|
||||
<div className="mx-auto w-full max-w-3xl space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Compose Message</h2>
|
||||
<p className="text-muted-foreground">Send a message to another user.</p>
|
||||
<h2 className="text-2xl font-bold tracking-tight">{t("title.compose")}</h2>
|
||||
<p className="text-muted-foreground">{t("description.compose")}</p>
|
||||
</div>
|
||||
<MessageCompose
|
||||
recipients={recipients}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function MessagesError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("messages")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title="消息加载失败"
|
||||
description="抱歉,加载消息时发生了意外错误。请稍后重试。"
|
||||
title={t("error.loadFailed")}
|
||||
description={t("error.loadFailedDesc")}
|
||||
action={{
|
||||
label: "重试",
|
||||
label: t("error.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getMessages } from "@/modules/messaging/data-access"
|
||||
@@ -7,11 +9,13 @@ import { NotificationList } from "@/modules/messaging/components/notification-li
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
title: "Messages",
|
||||
export async function generateMetadata() {
|
||||
const t = await getTranslations("messages")
|
||||
return { title: t("title.list") }
|
||||
}
|
||||
|
||||
export default async function MessagesPage() {
|
||||
const t = await getTranslations("messages")
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
|
||||
const [messagesResult, notificationsResult] = await Promise.all([
|
||||
@@ -22,9 +26,9 @@ export default async function MessagesPage() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Messages</h2>
|
||||
<h2 className="text-2xl font-bold tracking-tight">{t("title.list")}</h2>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your inbox and stay updated with notifications.
|
||||
{t("description.list")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user