refactor(announcements,messaging,notifications): V1+V2 审计重构 — i18n 命名空间独立 + 通知标题 i18n 化 + 服务端过滤 + 编排下沉 + 表单错误展示 + 架构图同步
V1 改进(已完成): - P0-4/P1-4/P1-5: 通知组件和 CRUD Action 从 messaging 迁移至 notifications 模块 - P1-5: 新增 getMessagesPageData / getAdminAnnouncementsPageData 编排函数 - P1-6: announcements schema 添加 superRefine 条件校验 - P1-7: 新增 useMessageSearch hook(防抖 + 请求竞态取消)+ 客户端分页 UI - P1-9: deleteMessage 事务化 - P2-11: 全模块 trackEvent 埋点 - 全模块 i18n 接入 + Error Boundary + a11y 改进 V2 改进(本次完成): - V2-P0-1: 通知 i18n 命名空间独立(notifications.json),useTranslations 从 "messages" 切换到 "notifications" - V2-P0-2: 公告/消息通知标题 i18n 化,Server Action 中使用 getTranslations 生成通知标题 - V2-P1-1: AnnouncementList 纯服务端过滤,移除客户端 useState/useMemo - V2-P1-2: MessageList 客户端过滤仅在初始数据时执行,搜索结果由服务端按 tab 过滤 - V2-P1-3: 消息详情页编排下沉,新增 getMessageDetailPageData 编排函数 - V2-P1-4: 表单服务端校验错误展示(fieldErrors + aria-invalid) - V2-P2-1: 轮询间隔常量化(POLL_INTERVAL_MS) - V2-P2-2: 架构图同步(004 + 005)
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
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"
|
||||
import { getMessageDetailPageData } from "@/modules/messaging/data-access"
|
||||
import { MessageDetail } from "@/modules/messaging/components/message-detail"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -22,14 +21,9 @@ export default async function MessageDetailPage({
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
const { id } = await params
|
||||
|
||||
const message = await getMessageById(id, ctx.userId)
|
||||
const message = await getMessageDetailPageData(id, ctx.userId)
|
||||
if (!message) notFound()
|
||||
|
||||
// Auto-mark as read when viewed by the receiver (non-blocking)
|
||||
if (!message.isRead && message.receiverId === ctx.userId) {
|
||||
after(() => markMessageAsRead(id, ctx.userId))
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col p-8">
|
||||
<MessageDetail message={message} currentUserId={ctx.userId} />
|
||||
|
||||
@@ -2,10 +2,9 @@ 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"
|
||||
import { getNotifications } from "@/modules/notifications/data-access"
|
||||
import { getMessagesPageData } from "@/modules/messaging/data-access"
|
||||
import { MessageList } from "@/modules/messaging/components/message-list"
|
||||
import { NotificationList } from "@/modules/messaging/components/notification-list"
|
||||
import { NotificationList } from "@/modules/notifications/components/notification-list"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -18,10 +17,8 @@ export default async function MessagesPage() {
|
||||
const t = await getTranslations("messages")
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
|
||||
const [messagesResult, notificationsResult] = await Promise.all([
|
||||
getMessages({ userId: ctx.userId, type: "all", page: 1, pageSize: 50 }),
|
||||
getNotifications(ctx.userId, { page: 1, pageSize: 20 }),
|
||||
])
|
||||
const { messages: messagesResult, notifications: notificationsResult } =
|
||||
await getMessagesPageData(ctx.userId)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
|
||||
Reference in New Issue
Block a user