From c54e2acaed641b7ae2c1a7304b08626f9ca973db Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
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 (
+    <Dialog open={open} onOpenChange={onOpenChange}>
+      {showTrigger && (
+        <Button variant="outline" size="sm">
+          {React.createElement(actionIcon, { className: "mr-2 h-4 w-4" })}
+          {actionText}하기
+        </Button>
+      )}
+      <DialogContent className="sm:max-w-[425px]">
+        <DialogHeader>
+          <DialogTitle className="flex items-center gap-2">
+            {React.createElement(actionIcon, { className: "h-5 w-5" })}
+            문서 {actionText}
+          </DialogTitle>
+          <DialogDescription>
+            선택한 {documents.length}개의 문서를 {actionText}하시겠습니까?
+            {isDisposeAction 
+              ? ' 폐기된 문서는 복구할 수 있습니다.' 
+              : ' 복구된 문서는 다시 사용할 수 있습니다.'
+            }
+          </DialogDescription>
+        </DialogHeader>
+        
+        <div className="py-4">
+          <div className="space-y-2">
+            {documents.map((doc) => (
+              <div key={doc.id} className="flex items-center p-2 bg-muted rounded">
+                <div>
+                  <p className="font-medium">{doc.templateName}</p>
+                  <p className="text-sm text-muted-foreground">
+                    {doc.fileName} • v{doc.revision}
+                  </p>
+                </div>
+              </div>
+            ))}
+          </div>
+        </div>
+
+        <DialogFooter>
+          <Button
+            variant="outline"
+            onClick={() => onOpenChange(false)}
+            disabled={isLoading}
+          >
+            취소
+          </Button>
+          <Button
+            onClick={handleAction}
+            disabled={isLoading}
+            variant={isDisposeAction ? "destructive" : "default"}
+          >
+            {isLoading ? "처리 중..." : `${actionText}하기`}
+          </Button>
+        </DialogFooter>
+      </DialogContent>
+    </Dialog>
+  )
+}
-- 
cgit v1.2.3

