From c72d0897f7b37843109c86f61d97eba05ba3ca0d Mon Sep 17 00:00:00 2001 From: dujinkim 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 { + attachments: Row["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 ( + + {showTrigger ? ( + + + + ) : null} + + + 정말로 삭제하시겠습니까? + +
이 작업은 되돌릴 수 없습니다.
+
{deleteWarning}
+ {attachments.length <= 3 && ( +
+
삭제될 파일:
+
    + {attachments.map((attachment) => ( +
  • + • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision}) +
  • + ))} +
+
+ )} +
+
+ + + + + + +
+
+ ) + } + + return ( + + {showTrigger ? ( + + + + ) : null} + + + 정말로 삭제하시겠습니까? + +
이 작업은 되돌릴 수 없습니다.
+
{deleteWarning}
+ {attachments.length <= 3 && ( +
+
삭제될 파일:
+
    + {attachments.map((attachment) => ( +
  • + • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision}) +
  • + ))} +
+
+ )} +
+
+ + + + + + +
+
+ ) +} \ No newline at end of file -- cgit v1.2.3