feat(messaging,announcements): 前端 UI 集成星标/草稿/置顶/已读回执
- 消息星标:MessageList 卡片星标按钮(乐观更新+回滚)、MessageDetail 头部星标切换 - 消息草稿:MessageCompose 自动保存(2s 防抖)+ 手动保存按钮 + 状态指示器 + 发送后清理草稿 - 公告置顶:AnnouncementCard 管理端置顶按钮、AnnouncementDetail 置顶切换、置顶 Badge - 公告已读回执:用户端详情页自动标记已读 + 已读/未读 Badge、管理端已读人数显示 - i18n:新增 announcements.meta.readCount 翻译键
This commit is contained in:
@@ -5,17 +5,17 @@ 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 { ArrowLeft, Mail, Reply, Star, 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 { ConfirmDeleteDialog } from "@/shared/components/ui/confirm-delete-dialog"
|
||||
import { formatDate } from "@/shared/lib/utils"
|
||||
import { cn, formatDate } from "@/shared/lib/utils"
|
||||
import { usePermission } from "@/shared/hooks/use-permission"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
|
||||
import { deleteMessageAction } from "../actions"
|
||||
import { deleteMessageAction, toggleMessageStarAction } from "../actions"
|
||||
import type { Message } from "../types"
|
||||
|
||||
export function MessageDetail({
|
||||
@@ -31,6 +31,8 @@ export function MessageDetail({
|
||||
const router = useRouter()
|
||||
const [isWorking, setIsWorking] = useState(false)
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
const [isStarred, setIsStarred] = useState(message.isStarred)
|
||||
const [isTogglingStar, setIsTogglingStar] = useState(false)
|
||||
const { hasPermission } = usePermission()
|
||||
const canSend = hasPermission(Permissions.MESSAGE_SEND)
|
||||
const canDelete = hasPermission(Permissions.MESSAGE_DELETE)
|
||||
@@ -58,6 +60,29 @@ export function MessageDetail({
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggleStar = async () => {
|
||||
setIsTogglingStar(true)
|
||||
const prevStarred = isStarred
|
||||
// 乐观更新
|
||||
setIsStarred(!prevStarred)
|
||||
try {
|
||||
const res = await toggleMessageStarAction(message.id)
|
||||
if (res.success) {
|
||||
toast.success(t("messages.starToggled"))
|
||||
} else {
|
||||
// 回滚
|
||||
setIsStarred(prevStarred)
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch {
|
||||
// 回滚
|
||||
setIsStarred(prevStarred)
|
||||
toast.error(t("messages.sendFailed"))
|
||||
} finally {
|
||||
setIsTogglingStar(false)
|
||||
}
|
||||
}
|
||||
|
||||
const replyHref = canSend
|
||||
? `/messages/compose?parentId=${message.id}&receiverId=${isReceived ? message.senderId : message.receiverId}&subject=${encodeURIComponent(
|
||||
message.subject?.startsWith("Re:") ? message.subject : `Re: ${message.subject ?? ""}`
|
||||
@@ -76,6 +101,16 @@ export function MessageDetail({
|
||||
<h2 className="text-2xl font-bold tracking-tight">{t("title.detail")}</h2>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
onClick={handleToggleStar}
|
||||
disabled={isTogglingStar}
|
||||
variant={isStarred ? "default" : "outline"}
|
||||
>
|
||||
<Star
|
||||
className={cn("mr-2 h-4 w-4", isStarred && "fill-current")}
|
||||
/>
|
||||
{isStarred ? t("actions.unstar") : t("actions.star")}
|
||||
</Button>
|
||||
{canSend ? (
|
||||
<Button asChild variant="outline">
|
||||
<Link href={replyHref ?? "#"}>
|
||||
@@ -104,6 +139,12 @@ export function MessageDetail({
|
||||
) : (
|
||||
<Badge variant="outline">{t("status.sent")}</Badge>
|
||||
)}
|
||||
{isStarred ? (
|
||||
<span className="inline-flex items-center gap-1 text-xs text-yellow-600">
|
||||
<Star className="h-3.5 w-3.5 fill-yellow-400 text-yellow-400" aria-hidden="true" />
|
||||
{t("actions.star")}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<CardTitle className="text-2xl">{message.subject ?? t("meta.noSubject")}</CardTitle>
|
||||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
||||
|
||||
Reference in New Issue
Block a user