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:
@@ -2,8 +2,10 @@
|
||||
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { createId } from "@paralleldrive/cuid2"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission, PermissionDeniedError } from "@/shared/lib/auth-guard"
|
||||
import { trackEvent } from "@/shared/lib/track-event"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import type { ActionState } from "@/shared/types/action-state"
|
||||
import { sendBatchNotifications } from "@/modules/notifications"
|
||||
@@ -69,10 +71,14 @@ async function notifyAnnouncementPublished(announcement: Announcement): Promise<
|
||||
const targetUserIds = await resolveTargetUserIds(announcement)
|
||||
if (targetUserIds.length === 0) return
|
||||
|
||||
const t = await getTranslations("announcements")
|
||||
const title = t("notification.publishedTitle", { title: announcement.title })
|
||||
const content = t("notification.publishedContent")
|
||||
|
||||
const payloads: NotificationPayload[] = targetUserIds.map((userId) => ({
|
||||
userId,
|
||||
title: `新公告:${announcement.title}`,
|
||||
content: announcement.content.slice(0, 200),
|
||||
title,
|
||||
content,
|
||||
type: "info",
|
||||
actionUrl: `/announcements/${announcement.id}`,
|
||||
metadata: {
|
||||
@@ -146,6 +152,14 @@ export async function createAnnouncementAction(
|
||||
revalidatePath("/admin/announcements")
|
||||
revalidatePath("/announcements")
|
||||
|
||||
void trackEvent({
|
||||
event: isPublished ? "announcement.published" : "announcement.created",
|
||||
userId: ctx.userId,
|
||||
targetId: id,
|
||||
targetType: "announcement",
|
||||
properties: { type: input.type, status: input.status },
|
||||
})
|
||||
|
||||
return { success: true, message: "Announcement created", data: id }
|
||||
} catch (e) {
|
||||
return handleActionError(e)
|
||||
@@ -215,6 +229,13 @@ export async function updateAnnouncementAction(
|
||||
revalidatePath(`/admin/announcements/${id}`)
|
||||
revalidatePath("/announcements")
|
||||
|
||||
void trackEvent({
|
||||
event: isPublished && !wasPublished ? "announcement.published" : "announcement.updated",
|
||||
targetId: id,
|
||||
targetType: "announcement",
|
||||
properties: { type: input.type, status: input.status, wasPublished },
|
||||
})
|
||||
|
||||
return { success: true, message: "Announcement updated", data: id }
|
||||
} catch (e) {
|
||||
return handleActionError(e)
|
||||
@@ -233,6 +254,13 @@ export async function deleteAnnouncementAction(id: string): Promise<ActionState<
|
||||
revalidatePath("/admin/announcements")
|
||||
revalidatePath("/announcements")
|
||||
|
||||
void trackEvent({
|
||||
event: "announcement.deleted",
|
||||
targetId: id,
|
||||
targetType: "announcement",
|
||||
properties: { type: existing.type, status: existing.status },
|
||||
})
|
||||
|
||||
return { success: true, message: "Announcement deleted" }
|
||||
} catch (e) {
|
||||
return handleActionError(e)
|
||||
@@ -258,6 +286,13 @@ export async function publishAnnouncementAction(id: string): Promise<ActionState
|
||||
revalidatePath(`/admin/announcements/${id}`)
|
||||
revalidatePath("/announcements")
|
||||
|
||||
void trackEvent({
|
||||
event: "announcement.published",
|
||||
targetId: id,
|
||||
targetType: "announcement",
|
||||
properties: { type: existing.type },
|
||||
})
|
||||
|
||||
return { success: true, message: "Announcement published" }
|
||||
} catch (e) {
|
||||
return handleActionError(e)
|
||||
@@ -277,6 +312,13 @@ export async function archiveAnnouncementAction(id: string): Promise<ActionState
|
||||
revalidatePath(`/admin/announcements/${id}`)
|
||||
revalidatePath("/announcements")
|
||||
|
||||
void trackEvent({
|
||||
event: "announcement.archived",
|
||||
targetId: id,
|
||||
targetType: "announcement",
|
||||
properties: { type: existing.type },
|
||||
})
|
||||
|
||||
return { success: true, message: "Announcement archived" }
|
||||
} catch (e) {
|
||||
return handleActionError(e)
|
||||
|
||||
Reference in New Issue
Block a user