"use client" import * as React from "react" import { toast } from "sonner" import { Trash2, RotateCcw } from "lucide-react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { BasicContractTemplate } from "@/db/schema" import { disposeDocuments, restoreDocuments } from "../actions" interface DisposeDocumentsDialogProps { open: boolean onOpenChange: (open: boolean) => void documents: BasicContractTemplate[] showTrigger?: boolean onSuccess?: () => void } export function DisposeDocumentsDialog({ open, onOpenChange, documents, showTrigger = true, onSuccess, }: DisposeDocumentsDialogProps) { const [isLoading, setIsLoading] = React.useState(false) const isDisposeAction = documents.some(doc => doc.status === 'ACTIVE') const actionText = isDisposeAction ? '폐기' : '복구' const actionIcon = isDisposeAction ? Trash2 : RotateCcw const handleAction = async () => { if (documents.length === 0) return setIsLoading(true) try { const documentIds = documents.map(doc => doc.id) if (isDisposeAction) { await disposeDocuments(documentIds) toast.success(`${documents.length}개의 문서가 폐기되었습니다.`) } else { await restoreDocuments(documentIds) toast.success(`${documents.length}개의 문서가 복구되었습니다.`) } onSuccess?.() onOpenChange(false) } catch (error) { console.error(`${actionText} 처리 오류:`, error) toast.error(`${actionText} 처리 중 오류가 발생했습니다.`) } finally { setIsLoading(false) } } return ( {showTrigger && ( )} {React.createElement(actionIcon, { className: "h-5 w-5" })} 문서 {actionText} 선택한 {documents.length}개의 문서를 {actionText}하시겠습니까? {isDisposeAction ? ' 폐기된 문서는 복구할 수 있습니다.' : ' 복구된 문서는 다시 사용할 수 있습니다.' }
{documents.map((doc) => (

{doc.templateName}

{doc.fileName} • v{doc.revision}

))}
) }