- 新增审计报告 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 清单 + 已知问题修复记录
111 lines
3.2 KiB
TypeScript
111 lines
3.2 KiB
TypeScript
"use client"
|
|
|
|
import { useMemo, useState } from "react"
|
|
import Link from "next/link"
|
|
import { useRouter } from "next/navigation"
|
|
import { Plus, Megaphone } from "lucide-react"
|
|
import { useTranslations } from "next-intl"
|
|
|
|
import { Button } from "@/shared/components/ui/button"
|
|
import { EmptyState } from "@/shared/components/ui/empty-state"
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/shared/components/ui/select"
|
|
|
|
import { AnnouncementCard } from "./announcement-card"
|
|
import type { Announcement, AnnouncementStatus } from "../types"
|
|
|
|
type Filter = "all" | AnnouncementStatus
|
|
|
|
export function AnnouncementList({
|
|
announcements,
|
|
canManage,
|
|
createHref,
|
|
detailHrefBuilder,
|
|
initialStatus,
|
|
}: {
|
|
announcements: Announcement[]
|
|
canManage?: boolean
|
|
createHref?: string
|
|
detailHrefBuilder?: (id: string) => string
|
|
initialStatus?: Filter
|
|
}) {
|
|
const t = useTranslations("announcements")
|
|
const router = useRouter()
|
|
const [filter, setFilter] = useState<Filter>(initialStatus ?? "all")
|
|
|
|
const filterOptions: { value: Filter; label: string }[] = [
|
|
{ value: "all", label: t("filter.all") },
|
|
{ value: "published", label: t("filter.published") },
|
|
{ value: "draft", label: t("filter.draft") },
|
|
{ value: "archived", label: t("filter.archived") },
|
|
]
|
|
|
|
const filtered = useMemo(() => {
|
|
if (filter === "all") return announcements
|
|
return announcements.filter((a) => a.status === filter)
|
|
}, [announcements, filter])
|
|
|
|
const handleFilterChange = (value: string) => {
|
|
setFilter(value as Filter)
|
|
const params = new URLSearchParams()
|
|
if (value !== "all") params.set("status", value)
|
|
const qs = params.toString()
|
|
router.replace(qs ? `?${qs}` : "?")
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<Select value={filter} onValueChange={handleFilterChange}>
|
|
<SelectTrigger className="w-[180px]">
|
|
<SelectValue placeholder={t("filter.placeholder")} />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{filterOptions.map((opt) => (
|
|
<SelectItem key={opt.value} value={opt.value}>
|
|
{opt.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
{canManage && createHref ? (
|
|
<Button asChild>
|
|
<Link href={createHref}>
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
{t("actions.new")}
|
|
</Link>
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
|
|
{filtered.length === 0 ? (
|
|
<EmptyState
|
|
title={t("empty.noAnnouncements")}
|
|
description={
|
|
announcements.length === 0
|
|
? t("empty.noAnnouncementsDesc")
|
|
: t("empty.noMatch")
|
|
}
|
|
icon={Megaphone}
|
|
className="h-auto border-none shadow-none"
|
|
/>
|
|
) : (
|
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
|
|
{filtered.map((a) => (
|
|
<AnnouncementCard
|
|
key={a.id}
|
|
announcement={a}
|
|
href={detailHrefBuilder ? detailHrefBuilder(a.id) : undefined}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|