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,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 { ArrowLeft, Send } from "lucide-react"
|
||||
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
@@ -35,13 +36,14 @@ export function MessageCompose({
|
||||
defaultSubject?: string
|
||||
backHref?: string
|
||||
}) {
|
||||
const t = useTranslations("messages")
|
||||
const router = useRouter()
|
||||
const [isWorking, setIsWorking] = useState(false)
|
||||
const [receiverId, setReceiverId] = useState(defaultReceiverId ?? "")
|
||||
|
||||
const handleSubmit = async (formData: FormData) => {
|
||||
if (!receiverId) {
|
||||
toast.error("Please select a recipient")
|
||||
toast.error(t("messages.selectRecipient"))
|
||||
return
|
||||
}
|
||||
formData.set("receiverId", receiverId)
|
||||
@@ -57,10 +59,10 @@ export function MessageCompose({
|
||||
router.push("/messages")
|
||||
router.refresh()
|
||||
} else {
|
||||
toast.error(res.message || "Failed to send message")
|
||||
toast.error(res.message || t("messages.sendFailed"))
|
||||
}
|
||||
} catch {
|
||||
toast.error("Failed to send message")
|
||||
toast.error(t("messages.sendFailed"))
|
||||
} finally {
|
||||
setIsWorking(false)
|
||||
}
|
||||
@@ -70,21 +72,21 @@ export function MessageCompose({
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<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>
|
||||
<CardTitle>{parentMessageId ? "Reply" : "New Message"}</CardTitle>
|
||||
<CardTitle>{parentMessageId ? t("title.reply") : t("title.newMessage")}</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form action={handleSubmit} className="space-y-6">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="receiverId">To</Label>
|
||||
<Label htmlFor="receiverId">{t("form.to")}</Label>
|
||||
<Select value={receiverId} onValueChange={setReceiverId} disabled={!!defaultReceiverId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select a recipient" />
|
||||
<SelectValue placeholder={t("form.toPlaceholder")} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{recipients.map((r) => (
|
||||
@@ -99,22 +101,22 @@ export function MessageCompose({
|
||||
</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="subject">Subject</Label>
|
||||
<Label htmlFor="subject">{t("form.subject")}</Label>
|
||||
<Input
|
||||
id="subject"
|
||||
name="subject"
|
||||
placeholder="Message subject"
|
||||
placeholder={t("form.subjectPlaceholder")}
|
||||
defaultValue={defaultSubject ?? ""}
|
||||
maxLength={255}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="content">Content</Label>
|
||||
<Label htmlFor="content">{t("form.content")}</Label>
|
||||
<Textarea
|
||||
id="content"
|
||||
name="content"
|
||||
placeholder="Write your message..."
|
||||
placeholder={t("form.contentPlaceholder")}
|
||||
className="min-h-[200px]"
|
||||
required
|
||||
/>
|
||||
@@ -127,15 +129,15 @@ export function MessageCompose({
|
||||
onClick={() => router.push(backHref)}
|
||||
disabled={isWorking}
|
||||
>
|
||||
Cancel
|
||||
{t("actions.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" disabled={isWorking || !receiverId}>
|
||||
{isWorking ? (
|
||||
"Sending..."
|
||||
t("actions.sending")
|
||||
) : (
|
||||
<>
|
||||
<Send className="mr-2 h-4 w-4" />
|
||||
Send
|
||||
{t("actions.send")}
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user