From bcd462d6e60871b86008e072f4b914138fc5c328 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Mon, 11 Aug 2025 09:34:40 +0000
Subject: (김준회) 리치텍스트에디터 (결재템플릿을 위한 공통컴포넌트),
 command-menu 에러 수정, 결재 템플릿 관리, 결재선 관리, ECC RFQ+PR Item 수신시
 비즈니스테이블(ProcurementRFQ) 데이터 적재, WSDL 오류 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/delete-approval-template-dialog.tsx      | 123 +++++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 lib/approval-template/table/delete-approval-template-dialog.tsx

(limited to 'lib/approval-template/table/delete-approval-template-dialog.tsx')

diff --git a/lib/approval-template/table/delete-approval-template-dialog.tsx b/lib/approval-template/table/delete-approval-template-dialog.tsx
new file mode 100644
index 00000000..9fa0a078
--- /dev/null
+++ b/lib/approval-template/table/delete-approval-template-dialog.tsx
@@ -0,0 +1,123 @@
+"use client"
+
+import * as React from "react"
+import { Loader, Trash } from "lucide-react"
+import { toast } from "sonner"
+
+import { Button } from "@/components/ui/button"
+import {
+  Dialog,
+  DialogContent,
+  DialogDescription,
+  DialogFooter,
+  DialogHeader,
+  DialogTitle,
+  DialogTrigger,
+} from "@/components/ui/dialog"
+import { type ApprovalTemplate } from "@/lib/approval-template/service"
+
+import { deleteApprovalTemplate } from "../service"
+
+interface DeleteApprovalTemplateDialogProps extends React.ComponentPropsWithRef<typeof Dialog> {
+  templates: ApprovalTemplate[]
+  showTrigger?: boolean
+  onSuccess?: () => void
+}
+
+export function DeleteApprovalTemplateDialog({
+  templates,
+  showTrigger = true,
+  onSuccess,
+  ...props
+}: DeleteApprovalTemplateDialogProps) {
+  const [isDeletePending, startDeleteTransition] = React.useTransition()
+
+  const isMultiple = templates.length > 1
+  const templateName = isMultiple ? `${templates.length}개 템플릿` : templates[0]?.name
+
+  function onDelete() {
+    startDeleteTransition(async () => {
+      if (templates.length === 0) return
+
+      // 여러 개면 순차 삭제 (간단히 처리)
+      for (const t of templates) {
+        const result = await deleteApprovalTemplate(t.id)
+        if (result.error) {
+          toast.error(result.error)
+          return
+        }
+      }
+
+      props.onOpenChange?.(false)
+      onSuccess?.()
+      toast.success(
+        isMultiple ? `${templates.length}개 템플릿이 삭제되었습니다` : "템플릿이 삭제되었습니다",
+      )
+
+      // 새로고침으로 반영
+      window.location.reload()
+    })
+  }
+
+  return (
+    <Dialog {...props}>
+      {showTrigger && (
+        <DialogTrigger asChild>
+          <Button
+            variant="outline"
+            size="sm"
+            className="text-destructive hover:text-destructive"
+          >
+            <Trash className="mr-2 size-4" aria-hidden="true" />
+            삭제
+          </Button>
+        </DialogTrigger>
+      )}
+      <DialogContent>
+        <DialogHeader>
+          <DialogTitle>템플릿 삭제 확인</DialogTitle>
+          <DialogDescription>
+            정말로 <strong>{templateName}</strong>을(를) 삭제하시겠습니까?
+            {!isMultiple && (
+              <>
+                <br />이 작업은 되돌릴 수 없습니다.
+              </>
+            )}
+          </DialogDescription>
+        </DialogHeader>
+
+        {templates.length > 0 && (
+          <div className="rounded-lg bg-muted p-3 max-h-40 overflow-y-auto">
+            <h4 className="text-sm font-medium mb-2">삭제될 템플릿</h4>
+            <div className="space-y-1">
+              {templates.map((t) => (
+                <div key={t.id} className="text-xs text-muted-foreground">
+                  <div className="font-medium">{t.name}</div>
+                  <div>ID: <code className="bg-background px-1 rounded">{t.id}</code></div>
+                </div>
+              ))}
+            </div>
+          </div>
+        )}
+
+        <DialogFooter>
+          <Button
+            variant="outline"
+            onClick={() => props.onOpenChange?.(false)}
+            disabled={isDeletePending}
+          >
+            취소
+          </Button>
+          <Button
+            variant="destructive"
+            onClick={onDelete}
+            disabled={isDeletePending}
+          >
+            {isDeletePending && <Loader className="mr-2 size-4 animate-spin" aria-hidden="true" />}
+            {isMultiple ? `${templates.length}개 삭제` : "삭제"}
+          </Button>
+        </DialogFooter>
+      </DialogContent>
+    </Dialog>
+  )
+}
-- 
cgit v1.2.3

