From 89274bffa596ffdfc4275fb8d11cdb02ff9a2d02 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 13 Oct 2025 00:22:54 +0000
Subject: (최겸) 기술영업 import 수정 2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/techsales-rfq/table/rfq-table.tsx | 76 ++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)

(limited to 'lib/techsales-rfq/table/rfq-table.tsx')

diff --git a/lib/techsales-rfq/table/rfq-table.tsx b/lib/techsales-rfq/table/rfq-table.tsx
index e1e511c8..889b87b3 100644
--- a/lib/techsales-rfq/table/rfq-table.tsx
+++ b/lib/techsales-rfq/table/rfq-table.tsx
@@ -30,6 +30,17 @@ import { RFQFilterSheet } from "./rfq-filter-sheet"
 import { TechSalesRfqAttachmentsSheet, ExistingTechSalesAttachment } from "./tech-sales-rfq-attachments-sheet"
 import { RfqItemsViewDialog } from "./rfq-items-view-dialog"
 import UpdateSheet from "./update-rfq-sheet"
+import { deleteTechSalesRfq } from "@/lib/techsales-rfq/service"
+import {
+  AlertDialog,
+  AlertDialogAction,
+  AlertDialogCancel,
+  AlertDialogContent,
+  AlertDialogDescription,
+  AlertDialogFooter,
+  AlertDialogHeader,
+  AlertDialogTitle,
+} from "@/components/ui/alert-dialog"
 // 기본적인 RFQ 타입 정의 (repository selectTechSalesRfqsWithJoin 반환 타입에 맞춤)
 export interface TechSalesRfq {
   id: number
@@ -101,6 +112,11 @@ export function RFQListTable({
   // 아이템 다이얼로그 상태
   const [itemsDialogOpen, setItemsDialogOpen] = React.useState(false)
   const [selectedRfqForItems, setSelectedRfqForItems] = React.useState<TechSalesRfq | null>(null)
+
+  // 삭제 다이얼로그 상태
+  const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false)
+  const [rfqToDelete, setRfqToDelete] = React.useState<TechSalesRfq | null>(null)
+  const [isDeleting, setIsDeleting] = React.useState(false)
   
   // 패널 collapse 상태
   const [panelHeight, setPanelHeight] = React.useState<number>(55)
@@ -255,7 +271,9 @@ export function RFQListTable({
             setUpdateSheetOpen(true);
             break;
         case "delete":
-          console.log("Delete rfq:", rowAction.row.original)
+          // 삭제 다이얼로그 열기
+          setRfqToDelete(rowAction.row.original as TechSalesRfq)
+          setDeleteDialogOpen(true)
           break;
       }
       setRowAction(null)
@@ -334,6 +352,38 @@ export function RFQListTable({
     setItemsDialogOpen(true)
   }, [])
 
+  // RFQ 삭제 처리 함수
+  const handleDeleteRfq = React.useCallback(async () => {
+    if (!rfqToDelete) return
+
+    try {
+      setIsDeleting(true)
+
+      const result = await deleteTechSalesRfq(rfqToDelete.id)
+
+      if (result.error) {
+        toast.error(`삭제 실패: ${result.error}`)
+        return
+      }
+
+      toast.success("RFQ가 성공적으로 삭제되었습니다.")
+
+      // 선택된 RFQ 초기화
+      setSelectedRfq(null)
+      setRfqToDelete(null)
+      setDeleteDialogOpen(false)
+
+      // 테이블 새로고침을 위해 페이지 리로드 또는 데이터 재요청 필요
+      // 현재는 캐시 무효화가 되어 있으므로 자연스럽게 업데이트됨
+
+    } catch (error) {
+      console.error("RFQ 삭제 오류:", error)
+      toast.error("삭제 중 오류가 발생했습니다.")
+    } finally {
+      setIsDeleting(false)
+    }
+  }, [rfqToDelete])
+
   const columns = React.useMemo(
     () => getColumns({ 
       setRowAction,
@@ -647,6 +697,30 @@ export function RFQListTable({
         }}
       />
     )}
+
+      {/* RFQ 삭제 다이얼로그 */}
+      <AlertDialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
+        <AlertDialogContent>
+          <AlertDialogHeader>
+            <AlertDialogTitle>RFQ 삭제 확인</AlertDialogTitle>
+            <AlertDialogDescription>
+              정말로 "{rfqToDelete?.rfqCode || rfqToDelete?.description}" RFQ를 삭제하시겠습니까?
+              <br />
+              <strong>주의:</strong> 이 작업은 되돌릴 수 없습니다. RFQ와 관련된 모든 데이터가 삭제됩니다.
+            </AlertDialogDescription>
+          </AlertDialogHeader>
+          <AlertDialogFooter>
+            <AlertDialogCancel disabled={isDeleting}>취소</AlertDialogCancel>
+            <AlertDialogAction
+              onClick={handleDeleteRfq}
+              disabled={isDeleting}
+              className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
+            >
+              {isDeleting ? "삭제 중..." : "삭제하기"}
+            </AlertDialogAction>
+          </AlertDialogFooter>
+        </AlertDialogContent>
+      </AlertDialog>
     </div>
   )
 }
\ No newline at end of file
-- 
cgit v1.2.3

