From a9575387c3a765a1a65ebc179dae16a21af6eb25 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Fri, 12 Sep 2025 08:01:02 +0000
Subject: (임수민) 일반 계약 템플릿 구현 및 basic contract 필터 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../general-contract-template-toolbar-actions.tsx  | 131 +++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 lib/general-contract-template/template/general-contract-template-toolbar-actions.tsx

(limited to 'lib/general-contract-template/template/general-contract-template-toolbar-actions.tsx')

diff --git a/lib/general-contract-template/template/general-contract-template-toolbar-actions.tsx b/lib/general-contract-template/template/general-contract-template-toolbar-actions.tsx
new file mode 100644
index 00000000..03818109
--- /dev/null
+++ b/lib/general-contract-template/template/general-contract-template-toolbar-actions.tsx
@@ -0,0 +1,131 @@
+"use client"
+
+import * as React from "react"
+import { useRouter } from "next/navigation"
+import { Trash2, FileText } from "lucide-react"
+import { toast } from "sonner"
+
+import { Button } from "@/components/ui/button"
+import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"
+import { disposeTemplates } from "../actions"
+import { AddGeneralContractTemplateDialog } from "./add-general-contract-template-dialog"
+
+interface GeneralContractTemplateToolbarActionsProps {
+  selectedRows?: any[]
+  onSelectionChange?: (selectedRows: any[]) => void
+}
+
+export function GeneralContractTemplateToolbarActions({
+  selectedRows = [],
+  onSelectionChange
+}: GeneralContractTemplateToolbarActionsProps) {
+  const router = useRouter()
+  const [isModifyOpen, setIsModifyOpen] = React.useState(false)
+  const [isDisposeOpen, setIsDisposeOpen] = React.useState(false)
+  const [isContractStatusOpen, setIsContractStatusOpen] = React.useState(false)
+
+  // 폐기 버튼 클릭
+  const handleDispose = () => {
+    if (selectedRows.length === 0) {
+      toast.error("폐기할 문서를 선택해주세요.")
+      return
+    }
+
+    setIsDisposeOpen(true)
+  }
+
+  // 계약현황 버튼 클릭
+  const handleContractStatus = () => {
+    if (selectedRows.length === 0) {
+      toast.error("확인할 문서를 선택해주세요.")
+      return
+    }
+
+    if (selectedRows.length > 1) {
+      toast.error("한 번에 하나의 문서만 확인할 수 있습니다.")
+      return
+    }
+
+    // 일반계약관리 페이지로 이동
+    router.push(`/evcp/general-contracts`)
+  }
+
+  // 실제 폐기 처리
+  const handleConfirmDispose = async () => {
+    try {
+      // 폐기할 템플릿 ID들 추출
+      const templateIds = selectedRows.map(row => row.id)
+
+      // Server Action 호출
+      const result = await disposeTemplates(templateIds)
+
+      toast.success(result.message)
+      setIsDisposeOpen(false)
+
+      // 페이지 새로고침 또는 테이블 업데이트
+      window.location.reload()
+    } catch (error) {
+      console.error('폐기 처리 오류:', error)
+      toast.error(error instanceof Error ? error.message : "폐기 처리 중 오류가 발생했습니다.")
+    }
+  }
+
+  return (
+    <>
+      <div className="flex items-center gap-2">
+        {/* 신규등록: 다이얼로그 사용 */}
+        <AddGeneralContractTemplateDialog />
+
+        {/* 계약현황 버튼 */}
+        <Button
+          onClick={handleContractStatus}
+          variant="outline"
+          size="sm"
+          className="border-blue-600 text-blue-600 hover:bg-blue-50"
+        >
+          <FileText className="mr-2 h-4 w-4" />
+          계약현황
+        </Button>
+
+        {/* 폐기 버튼 */}
+        <Button
+          onClick={handleDispose}
+          variant="outline"
+          size="sm"
+          className="border-red-600 text-red-600 hover:bg-red-50"
+        >
+          <Trash2 className="mr-2 h-4 w-4" />
+          폐기
+        </Button>
+      </div>
+
+      {/* 폐기 확인 다이얼로그 */}
+      <Dialog open={isDisposeOpen} onOpenChange={setIsDisposeOpen}>
+        <DialogContent>
+          <DialogHeader>
+            <DialogTitle>문서 폐기 확인</DialogTitle>
+            <DialogDescription>
+              선택된 {selectedRows.length}개의 문서를 폐기하시겠습니까?
+              <br />
+              폐기된 문서는 복구할 수 없습니다.
+            </DialogDescription>
+          </DialogHeader>
+          <div className="flex justify-end gap-2">
+            <Button
+              variant="outline"
+              onClick={() => setIsDisposeOpen(false)}
+            >
+              취소
+            </Button>
+            <Button
+              variant="destructive"
+              onClick={handleConfirmDispose}
+            >
+              폐기
+            </Button>
+          </div>
+        </DialogContent>
+      </Dialog>
+    </>
+  )
+}
-- 
cgit v1.2.3

