From cf8dac0c6490469dab88a560004b0c07dbd48612 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 18 Sep 2025 00:23:40 +0000 Subject: (대표님) rfq, 계약, 서명 등 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/itb/table/delete-purchase-request-dialog.tsx | 225 +++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 lib/itb/table/delete-purchase-request-dialog.tsx (limited to 'lib/itb/table/delete-purchase-request-dialog.tsx') diff --git a/lib/itb/table/delete-purchase-request-dialog.tsx b/lib/itb/table/delete-purchase-request-dialog.tsx new file mode 100644 index 00000000..2f09cf70 --- /dev/null +++ b/lib/itb/table/delete-purchase-request-dialog.tsx @@ -0,0 +1,225 @@ +// components/purchase-requests/delete-purchase-request-dialog.tsx +"use client" + +import * as React from "react" +import { type PurchaseRequestView } from "@/db/schema/purchase-requests-view" +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 { deletePurchaseRequests } from "../service" + +interface DeletePurchaseRequestDialogProps + extends React.ComponentPropsWithoutRef { + requests?: Row["original"][] | PurchaseRequestView[] + request?: PurchaseRequestView // 단일 삭제용 + showTrigger?: boolean + onSuccess?: () => void +} + +export function DeletePurchaseRequestDialog({ + requests: requestsProp, + request, + showTrigger = true, + onSuccess, + ...props +}: DeletePurchaseRequestDialogProps) { + const [isDeletePending, startDeleteTransition] = React.useTransition() + const isDesktop = useMediaQuery("(min-width: 640px)") + + // 단일 또는 복수 요청 처리 + const requests = requestsProp || (request ? [request] : []) + const isMultiple = requests.length > 1 + + // 삭제 불가능한 상태 체크 + const nonDeletableRequests = requests.filter( + req => req.status !== "작성중" + ) + const canDelete = nonDeletableRequests.length === 0 + + function onDelete() { + if (!canDelete) { + toast.error("작성중 상태의 요청만 삭제할 수 있습니다.") + return + } + + startDeleteTransition(async () => { + const { error } = await deletePurchaseRequests({ + ids: requests.map((req) => req.id), + }) + + if (error) { + toast.error(error) + return + } + + props.onOpenChange?.(false) + toast.success( + isMultiple + ? `${requests.length}개의 구매요청이 삭제되었습니다.` + : "구매요청이 삭제되었습니다." + ) + onSuccess?.() + }) + } + + const dialogContent = ( + <> +
+
+

+ 이 작업은 되돌릴 수 없습니다. + {isMultiple ? ( + <> + 선택한 {requests.length}개의 구매요청이 영구적으로 삭제됩니다. + + ) : ( + <> + 구매요청 {requests[0]?.requestCode}이(가) 영구적으로 삭제됩니다. + + )} +

+
+ + {/* 삭제할 요청 목록 표시 (복수인 경우) */} + {isMultiple && ( +
+

삭제할 구매요청:

+
    + {requests.map((req) => ( +
  • + {req.requestCode} + {" - "} + {req.requestTitle} +
  • + ))} +
+
+ )} + + {/* 삭제 불가능한 요청이 있는 경우 경고 */} + {nonDeletableRequests.length > 0 && ( +
+

+ 삭제할 수 없는 요청: +

+
    + {nonDeletableRequests.map((req) => ( +
  • + {req.requestCode} + {" - 상태: "} + {req.status} +
  • + ))} +
+

+ ※ 작성중 상태의 요청만 삭제할 수 있습니다. +

+
+ )} +
+ + ) + + if (isDesktop) { + return ( + + {showTrigger ? ( + + + + ) : null} + + + 구매요청을 삭제하시겠습니까? + + {dialogContent} + + + + + + + + + + + ) + } + + return ( + + {showTrigger ? ( + + + + ) : null} + + + 구매요청을 삭제하시겠습니까? + + {dialogContent} + + + + + + + + + + + ) +} \ No newline at end of file -- cgit v1.2.3