From c54e2acaed641b7ae2c1a7304b08626f9ca973db Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 17 Sep 2025 05:39:58 +0000 Subject: (임수민) 기본계약 폐기하기, 수정하기 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/dispose-documents-dialog.tsx | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 lib/basic-contract/template/dispose-documents-dialog.tsx (limited to 'lib/basic-contract/template/dispose-documents-dialog.tsx') diff --git a/lib/basic-contract/template/dispose-documents-dialog.tsx b/lib/basic-contract/template/dispose-documents-dialog.tsx new file mode 100644 index 00000000..1154c246 --- /dev/null +++ b/lib/basic-contract/template/dispose-documents-dialog.tsx @@ -0,0 +1,122 @@ +"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} +

+
+
+ ))} +
+
+ + + + + +
+
+ ) +} -- cgit v1.2.3