lty/qy-lty-admin/components/publish-confirmation-dialog.tsx
2026-03-17 13:17:02 +08:00

110 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import type React from "react"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { AlertCircle, Loader2, Send } from "lucide-react"
type PublishConfirmationDialogProps = {
title: string
description: string
itemName: string
onPublish: () => Promise<void>
trigger?: React.ReactNode
}
export function PublishConfirmationDialog({
title,
description,
itemName,
onPublish,
trigger,
}: PublishConfirmationDialogProps) {
const [open, setOpen] = useState(false)
const [isPublishing, setIsPublishing] = useState(false)
const handlePublish = async () => {
setIsPublishing(true)
try {
await onPublish()
setOpen(false)
} catch (error) {
console.error("发布失败:", error)
// 失败处理已经在onPublish中处理这里不需要额外处理
} finally {
setIsPublishing(false)
}
}
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
{trigger || (
<Button
variant="ghost"
size="icon"
className="hover:bg-green-50 hover:text-green-600"
title="发布歌曲"
>
<Send className="h-4 w-4" />
</Button>
)}
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle className="text-xl font-bold text-green-600 flex items-center">
<AlertCircle className="h-5 w-5 mr-2" />
{title}
</DialogTitle>
<DialogDescription>{description}</DialogDescription>
</DialogHeader>
<div className="py-4">
<p className="text-sm text-gray-700 mb-2">
<span className="font-medium text-green-600">{itemName}</span>
</p>
<div className="p-3 bg-amber-50 border border-amber-200 rounded-md">
<p className="text-sm text-amber-700 font-medium">
</p>
<p className="text-sm text-amber-600 mt-1">
</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)} disabled={isPublishing}>
</Button>
<Button
variant="default"
onClick={handlePublish}
disabled={isPublishing}
className="bg-green-600 hover:bg-green-700 text-white"
>
{isPublishing ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
...
</>
) : (
<>
<Send className="mr-2 h-4 w-4" />
</>
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}