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:
SpecialX
2026-06-22 16:02:07 +08:00
parent 21c1e7a286
commit fde711ce46
30 changed files with 1085 additions and 261 deletions

View File

@@ -4,6 +4,7 @@ import { useState } from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { toast } from "sonner"
import { useTranslations } from "next-intl"
import { Bell, CheckCheck, MessageSquare, Megaphone, PenTool, GraduationCap } from "lucide-react"
import { Badge } from "@/shared/components/ui/badge"
@@ -22,14 +23,8 @@ const TYPE_ICON: Record<NotificationType, typeof Bell> = {
grade: GraduationCap,
}
const TYPE_LABEL: Record<NotificationType, string> = {
message: "Message",
announcement: "Announcement",
homework: "Homework",
grade: "Grade",
}
export function NotificationList({ notifications }: { notifications: Notification[] }) {
const t = useTranslations("messages")
const router = useRouter()
const [isWorking, setIsWorking] = useState(false)
const hasUnread = notifications.some((n) => !n.isRead)
@@ -42,10 +37,10 @@ export function NotificationList({ notifications }: { notifications: Notificatio
toast.success(res.message)
router.refresh()
} else {
toast.error(res.message || "Failed to mark all as read")
toast.error(res.message || t("messages.markReadFailed"))
}
} catch {
toast.error("Failed to mark all as read")
toast.error(t("messages.markReadFailed"))
} finally {
setIsWorking(false)
}
@@ -58,7 +53,7 @@ export function NotificationList({ notifications }: { notifications: Notificatio
router.refresh()
}
} catch {
toast.error("Failed to mark as read")
toast.error(t("messages.markReadFailed"))
}
}
@@ -66,21 +61,21 @@ export function NotificationList({ notifications }: { notifications: Notificatio
<div className="space-y-6">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<h2 className="text-2xl font-bold tracking-tight">Notifications</h2>
<p className="text-muted-foreground text-sm">Stay updated on your latest activities.</p>
<h2 className="text-2xl font-bold tracking-tight">{t("title.notifications")}</h2>
<p className="text-muted-foreground text-sm">{t("description.notifications")}</p>
</div>
{hasUnread ? (
<Button onClick={handleMarkAllRead} disabled={isWorking} variant="outline">
<CheckCheck className="mr-2 h-4 w-4" />
Mark all as read
{t("actions.markAllRead")}
</Button>
) : null}
</div>
{notifications.length === 0 ? (
<EmptyState
title="No notifications"
description="You have no notifications yet."
title={t("empty.noNotifications")}
description={t("empty.noNotificationsDesc")}
icon={Bell}
className="h-auto border-none shadow-none"
/>
@@ -95,14 +90,14 @@ export function NotificationList({ notifications }: { notifications: Notificatio
>
<CardContent className="flex items-start gap-3 py-4">
<div className="bg-muted flex size-9 shrink-0 items-center justify-center rounded-full">
<Icon className="h-4 w-4" />
<Icon className="h-4 w-4" aria-hidden="true" />
</div>
<div className="min-w-0 flex-1 space-y-1">
<div className="flex items-center gap-2">
<span className={cn("text-sm", !n.isRead ? "font-semibold" : "font-medium")}>
{n.title}
</span>
{!n.isRead ? <Badge variant="default" className="text-xs">New</Badge> : null}
{!n.isRead ? <Badge variant="default" className="text-xs">{t("status.new")}</Badge> : null}
</div>
{n.content ? (
<p className="text-muted-foreground line-clamp-2 text-sm whitespace-pre-wrap">
@@ -111,7 +106,7 @@ export function NotificationList({ notifications }: { notifications: Notificatio
) : null}
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<Badge variant="outline" className="text-xs">
{TYPE_LABEL[n.type]}
{t(`notificationType.${n.type}`)}
</Badge>
<span>{formatDate(n.createdAt)}</span>
{!n.isRead ? (
@@ -119,13 +114,14 @@ export function NotificationList({ notifications }: { notifications: Notificatio
type="button"
onClick={() => handleMarkRead(n.id)}
className="text-primary hover:underline"
aria-label={t("actions.markRead")}
>
Mark as read
{t("actions.markRead")}
</button>
) : null}
{n.link ? (
<Link href={n.link} className="ml-auto text-primary hover:underline">
View
{t("actions.view")}
</Link>
) : null}
</div>