From c72d0897f7b37843109c86f61d97eba05ba3ca0d Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Fri, 13 Jun 2025 07:08:01 +0000
Subject: (대표님) 20250613 16시 08분 b-rfq, document 등
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/b-rfq/attachment/delete-attachment-dialog.tsx | 182 ++++++++++++++++++++++
 1 file changed, 182 insertions(+)
 create mode 100644 lib/b-rfq/attachment/delete-attachment-dialog.tsx

(limited to 'lib/b-rfq/attachment/delete-attachment-dialog.tsx')

diff --git a/lib/b-rfq/attachment/delete-attachment-dialog.tsx b/lib/b-rfq/attachment/delete-attachment-dialog.tsx
new file mode 100644
index 00000000..b5471520
--- /dev/null
+++ b/lib/b-rfq/attachment/delete-attachment-dialog.tsx
@@ -0,0 +1,182 @@
+"use client"
+
+import * as React from "react"
+import { type Row } from "@tanstack/react-table"
+import { Loader, Trash } from "lucide-react"
+import { toast } from "sonner"
+
+import { useMediaQuery } from "@/hooks/use-media-query"
+import { Button } from "@/components/ui/button"
+import {
+  Dialog,
+  DialogClose,
+  DialogContent,
+  DialogDescription,
+  DialogFooter,
+  DialogHeader,
+  DialogTitle,
+  DialogTrigger,
+} from "@/components/ui/dialog"
+import {
+  Drawer,
+  DrawerClose,
+  DrawerContent,
+  DrawerDescription,
+  DrawerFooter,
+  DrawerHeader,
+  DrawerTitle,
+  DrawerTrigger,
+} from "@/components/ui/drawer"
+import { deleteRfqAttachments } from "../service"
+
+
+// 첨부파일 타입 (실제 타입에 맞게 조정 필요)
+type RfqAttachment = {
+  id: number
+  serialNo: string
+  originalFileName: string
+  attachmentType: string
+  currentRevision: string
+}
+
+interface DeleteAttachmentsDialogProps
+  extends React.ComponentPropsWithoutRef<typeof Dialog> {
+  attachments: Row<RfqAttachment>["original"][]
+  showTrigger?: boolean
+  onSuccess?: () => void
+}
+
+export function DeleteAttachmentsDialog({
+  attachments,
+  showTrigger = true,
+  onSuccess,
+  ...props
+}: DeleteAttachmentsDialogProps) {
+  const [isDeletePending, startDeleteTransition] = React.useTransition()
+  const isDesktop = useMediaQuery("(min-width: 640px)")
+
+  function onDelete() {
+    startDeleteTransition(async () => {
+      const result = await deleteRfqAttachments({
+        ids: attachments.map((attachment) => attachment.id),
+      })
+
+      if (!result.success) {
+        toast.error(result.message)
+        return
+      }
+
+      props.onOpenChange?.(false)
+      toast.success(result.message)
+      onSuccess?.()
+    })
+  }
+
+  const attachmentText = attachments.length === 1 ? "첨부파일" : "첨부파일들"
+  const deleteWarning = `선택된 ${attachments.length}개의 ${attachmentText}과 모든 리비전이 영구적으로 삭제됩니다.`
+
+  if (isDesktop) {
+    return (
+      <Dialog {...props}>
+        {showTrigger ? (
+          <DialogTrigger asChild>
+            <Button variant="outline" size="sm">
+              <Trash className="mr-2 size-4" aria-hidden="true" />
+              삭제 ({attachments.length})
+            </Button>
+          </DialogTrigger>
+        ) : null}
+        <DialogContent>
+          <DialogHeader>
+            <DialogTitle>정말로 삭제하시겠습니까?</DialogTitle>
+            <DialogDescription className="space-y-2">
+              <div>이 작업은 되돌릴 수 없습니다.</div>
+              <div>{deleteWarning}</div>
+              {attachments.length <= 3 && (
+                <div className="mt-3 p-2 bg-gray-50 rounded-md">
+                  <div className="font-medium text-sm">삭제될 파일:</div>
+                  <ul className="text-sm text-gray-600 mt-1">
+                    {attachments.map((attachment) => (
+                      <li key={attachment.id} className="truncate">
+                        • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision})
+                      </li>
+                    ))}
+                  </ul>
+                </div>
+              )}
+            </DialogDescription>
+          </DialogHeader>
+          <DialogFooter className="gap-2 sm:space-x-0">
+            <DialogClose asChild>
+              <Button variant="outline">취소</Button>
+            </DialogClose>
+            <Button
+              aria-label="Delete selected attachments"
+              variant="destructive"
+              onClick={onDelete}
+              disabled={isDeletePending}
+            >
+              {isDeletePending && (
+                <Loader
+                  className="mr-2 size-4 animate-spin"
+                  aria-hidden="true"
+                />
+              )}
+              삭제
+            </Button>
+          </DialogFooter>
+        </DialogContent>
+      </Dialog>
+    )
+  }
+
+  return (
+    <Drawer {...props}>
+      {showTrigger ? (
+        <DrawerTrigger asChild>
+          <Button variant="outline" size="sm">
+            <Trash className="mr-2 size-4" aria-hidden="true" />
+            삭제 ({attachments.length})
+          </Button>
+        </DrawerTrigger>
+      ) : null}
+      <DrawerContent>
+        <DrawerHeader>
+          <DrawerTitle>정말로 삭제하시겠습니까?</DrawerTitle>
+          <DrawerDescription className="space-y-2">
+            <div>이 작업은 되돌릴 수 없습니다.</div>
+            <div>{deleteWarning}</div>
+            {attachments.length <= 3 && (
+              <div className="mt-3 p-2 bg-gray-50 rounded-md">
+                <div className="font-medium text-sm">삭제될 파일:</div>
+                <ul className="text-sm text-gray-600 mt-1">
+                  {attachments.map((attachment) => (
+                    <li key={attachment.id} className="truncate">
+                      • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision})
+                    </li>
+                  ))}
+                </ul>
+              </div>
+            )}
+          </DrawerDescription>
+        </DrawerHeader>
+        <DrawerFooter className="gap-2 sm:space-x-0">
+          <DrawerClose asChild>
+            <Button variant="outline">취소</Button>
+          </DrawerClose>
+          <Button
+            aria-label="Delete selected attachments"
+            variant="destructive"
+            onClick={onDelete}
+            disabled={isDeletePending}
+          >
+            {isDeletePending && (
+              <Loader className="mr-2 size-4 animate-spin" aria-hidden="true" />
+            )}
+            삭제
+          </Button>
+        </DrawerFooter>
+      </DrawerContent>
+    </Drawer>
+  )
+}
\ No newline at end of file
-- 
cgit v1.2.3

