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:
@@ -4,21 +4,13 @@ import { useState } from "react"
|
||||
import Link from "next/link"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { toast } from "sonner"
|
||||
import { useTranslations } from "next-intl"
|
||||
import { ArrowLeft, Mail, Reply, Trash2 } from "lucide-react"
|
||||
|
||||
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 {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/shared/components/ui/alert-dialog"
|
||||
import { ConfirmDeleteDialog } from "@/shared/components/ui/confirm-delete-dialog"
|
||||
import { formatDate } from "@/shared/lib/utils"
|
||||
import { usePermission } from "@/shared/hooks/use-permission"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
@@ -35,6 +27,7 @@ export function MessageDetail({
|
||||
currentUserId: string
|
||||
backHref?: string
|
||||
}) {
|
||||
const t = useTranslations("messages")
|
||||
const router = useRouter()
|
||||
const [isWorking, setIsWorking] = useState(false)
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
@@ -44,7 +37,7 @@ export function MessageDetail({
|
||||
|
||||
const isReceived = message.receiverId === currentUserId
|
||||
const counterpart = isReceived ? message.senderName : message.receiverName
|
||||
const counterpartLabel = isReceived ? "From" : "To"
|
||||
const counterpartLabel = isReceived ? t("meta.from") : t("meta.to")
|
||||
|
||||
const handleDelete = async () => {
|
||||
setIsWorking(true)
|
||||
@@ -55,10 +48,10 @@ export function MessageDetail({
|
||||
router.push("/messages")
|
||||
router.refresh()
|
||||
} else {
|
||||
toast.error(res.message || "Failed to delete")
|
||||
toast.error(res.message || t("messages.deleteFailed"))
|
||||
}
|
||||
} catch {
|
||||
toast.error("Failed to delete")
|
||||
toast.error(t("messages.deleteFailed"))
|
||||
} finally {
|
||||
setIsWorking(false)
|
||||
setDeleteOpen(false)
|
||||
@@ -75,26 +68,26 @@ export function MessageDetail({
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Button asChild variant="ghost" size="icon">
|
||||
<Button asChild variant="ghost" size="icon" aria-label={t("actions.back")}>
|
||||
<Link href={backHref}>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
<h2 className="text-2xl font-bold tracking-tight">Message</h2>
|
||||
<h2 className="text-2xl font-bold tracking-tight">{t("title.detail")}</h2>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{canSend ? (
|
||||
<Button asChild variant="outline">
|
||||
<Link href={replyHref ?? "#"}>
|
||||
<Reply className="mr-2 h-4 w-4" />
|
||||
Reply
|
||||
{t("actions.reply")}
|
||||
</Link>
|
||||
</Button>
|
||||
) : null}
|
||||
{canDelete ? (
|
||||
<Button onClick={() => setDeleteOpen(true)} disabled={isWorking} variant="destructive">
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete
|
||||
{t("actions.delete")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -103,26 +96,26 @@ export function MessageDetail({
|
||||
<Card>
|
||||
<CardHeader className="space-y-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Mail className="text-muted-foreground h-4 w-4" />
|
||||
<Mail className="text-muted-foreground h-4 w-4" aria-hidden="true" />
|
||||
{isReceived && !message.isRead ? (
|
||||
<Badge variant="default">New</Badge>
|
||||
<Badge variant="default">{t("status.new")}</Badge>
|
||||
) : isReceived ? (
|
||||
<Badge variant="secondary">Read</Badge>
|
||||
<Badge variant="secondary">{t("status.read")}</Badge>
|
||||
) : (
|
||||
<Badge variant="outline">Sent</Badge>
|
||||
<Badge variant="outline">{t("status.sent")}</Badge>
|
||||
)}
|
||||
</div>
|
||||
<CardTitle className="text-2xl">{message.subject ?? "(no subject)"}</CardTitle>
|
||||
<CardTitle className="text-2xl">{message.subject ?? t("meta.noSubject")}</CardTitle>
|
||||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
||||
<span>
|
||||
{counterpartLabel}: <span className="font-medium">{counterpart ?? "Unknown"}</span>
|
||||
{counterpartLabel}: <span className="font-medium">{counterpart ?? t("meta.unknown")}</span>
|
||||
</span>
|
||||
<span>·</span>
|
||||
<span>{formatDate(message.createdAt)}</span>
|
||||
{message.readAt && isReceived ? (
|
||||
<>
|
||||
<span>·</span>
|
||||
<span>Read {formatDate(message.readAt)}</span>
|
||||
<span>{t("meta.readAt", { date: formatDate(message.readAt) })}</span>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -132,22 +125,14 @@ export function MessageDetail({
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete message</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will permanently delete the message "{message.subject ?? "(no subject)"}".
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isWorking}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} disabled={isWorking}>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<ConfirmDeleteDialog
|
||||
open={deleteOpen}
|
||||
onOpenChange={setDeleteOpen}
|
||||
title={t("empty.deleteTitle")}
|
||||
description={t("empty.deleteDesc", { subject: message.subject ?? t("meta.noSubject") })}
|
||||
onConfirm={handleDelete}
|
||||
isWorking={isWorking}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user