From 47fb72704161b4b58a27c7f5c679fc44618de9a1 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 4 Nov 2025 10:03:32 +0000
Subject: (최겸) 구매 견적 내 RFQ Cancel/Delete, 연동제 적용, MRC Type 개발
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/rfq-last/table/rfq-table-toolbar-actions.tsx | 56 +++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

(limited to 'lib/rfq-last/table/rfq-table-toolbar-actions.tsx')

diff --git a/lib/rfq-last/table/rfq-table-toolbar-actions.tsx b/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
index 148336fb..a6dc1ad4 100644
--- a/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
+++ b/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
@@ -3,11 +3,12 @@
 import * as React from "react";
 import { Table } from "@tanstack/react-table";
 import { Button } from "@/components/ui/button";
-import { Users, RefreshCw, FileDown, Plus, Edit } from "lucide-react";
+import { Users, RefreshCw, FileDown, Plus, Edit, Trash2 } from "lucide-react";
 import { RfqsLastView } from "@/db/schema";
 import { RfqAssignPicDialog } from "./rfq-assign-pic-dialog";
 import { CreateGeneralRfqDialog } from "./create-general-rfq-dialog"; // 추가
 import { UpdateGeneralRfqDialog } from "./update-general-rfq-dialog"; // 수정용
+import { DeleteRfqDialog } from "./delete-rfq-dialog";
 import { Badge } from "@/components/ui/badge";
 import {
   Tooltip,
@@ -29,6 +30,7 @@ export function RfqTableToolbarActions<TData>({
 }: RfqTableToolbarActionsProps<TData>) {
   const [showAssignDialog, setShowAssignDialog] = React.useState(false);
   const [showUpdateDialog, setShowUpdateDialog] = React.useState(false);
+  const [showDeleteDialog, setShowDeleteDialog] = React.useState(false);
   const [selectedRfqForUpdate, setSelectedRfqForUpdate] = React.useState<number | null>(null);
 
   console.log(rfqCategory)
@@ -47,6 +49,9 @@ export function RfqTableToolbarActions<TData>({
     // 수정 가능한 RFQ (general 카테고리에서 RFQ 생성 상태인 항목, 단일 선택만)
     const updatableRfq = rfqCategory === "general" && rows.length === 1 && rows[0].status === "RFQ 생성" ? rows[0] : null;
 
+    // ANFNR이 있는 RFQ만 필터링 (삭제 가능한 RFQ)
+    const deletableRows = rows.filter(row => row.ANFNR && row.ANFNR.trim() !== "");
+
     return {
       ids: rows.map(row => row.id),
       codes: rows.map(row => row.rfqCode || ""),
@@ -61,6 +66,10 @@ export function RfqTableToolbarActions<TData>({
       // 수정 가능한 RFQ 정보
       updatableRfq: updatableRfq,
       canUpdate: updatableRfq !== null,
+      // 삭제 가능한 RFQ 정보
+      deletableRows: deletableRows,
+      deletableCount: deletableRows.length,
+      canDelete: deletableRows.length > 0,
     };
   }, [selectedRows, rfqCategory]);
 
@@ -92,6 +101,13 @@ export function RfqTableToolbarActions<TData>({
     }
   };
 
+  const handleDeleteSuccess = () => {
+    // 테이블 선택 초기화
+    table.toggleAllPageRowsSelected(false);
+    // 데이터 새로고침
+    onRefresh?.();
+  };
+
   return (
     <>
       <div className="flex items-center gap-2">
@@ -125,6 +141,36 @@ export function RfqTableToolbarActions<TData>({
           </TooltipProvider>
         )}
 
+        {/* RFQ 삭제 버튼 - ANFNR이 있는 RFQ가 선택된 경우에만 활성화 */}
+        {selectedRfqData.totalCount > 0 && selectedRfqData.canDelete && (
+          <TooltipProvider>
+            <Tooltip>
+              <TooltipTrigger asChild>
+                <Button
+                  variant="destructive"
+                  size="sm"
+                  onClick={() => setShowDeleteDialog(true)}
+                  className="flex items-center gap-2"
+                >
+                  <Trash2 className="h-4 w-4" />
+                  RFQ 삭제
+                  <Badge variant="secondary" className="ml-1">
+                    {selectedRfqData.deletableCount}건
+                  </Badge>
+                </Button>
+              </TooltipTrigger>
+              <TooltipContent>
+                <p>선택한 RFQ를 삭제합니다 (ANFNR이 있는 RFQ만 삭제 가능)</p>
+                {selectedRfqData.deletableCount !== selectedRfqData.totalCount && (
+                  <p className="text-xs text-muted-foreground mt-1">
+                    전체 {selectedRfqData.totalCount}건 중 {selectedRfqData.deletableCount}건만 삭제 가능합니다
+                  </p>
+                )}
+              </TooltipContent>
+            </Tooltip>
+          </TooltipProvider>
+        )}
+
         {/* 선택된 항목 표시 */}
         {selectedRfqData.totalCount > 0 && (
           <div className="flex items-center gap-2 px-3 py-1.5 bg-muted rounded-md">
@@ -198,6 +244,14 @@ export function RfqTableToolbarActions<TData>({
         rfqId={selectedRfqForUpdate || 0}
         onSuccess={handleUpdateGeneralRfqSuccess}
       />
+
+      {/* RFQ 삭제 다이얼로그 */}
+      <DeleteRfqDialog
+        open={showDeleteDialog}
+        onOpenChange={setShowDeleteDialog}
+        selectedRfqs={selectedRfqData.deletableRows}
+        onSuccess={handleDeleteSuccess}
+      />
     </>
   );
 }
\ No newline at end of file
-- 
cgit v1.2.3

