From c92ddd6bae8e187cccfddb37373460ebea0ade27 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 1 Dec 2025 01:21:52 +0000
Subject: (최겸) 구매 입찰 SAP 삭제(취소) 개발
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../list/biddings-table-toolbar-actions.tsx        | 38 +++++++++++++++++++---
 1 file changed, 33 insertions(+), 5 deletions(-)

(limited to 'lib/bidding/list/biddings-table-toolbar-actions.tsx')

diff --git a/lib/bidding/list/biddings-table-toolbar-actions.tsx b/lib/bidding/list/biddings-table-toolbar-actions.tsx
index a3851630..33368218 100644
--- a/lib/bidding/list/biddings-table-toolbar-actions.tsx
+++ b/lib/bidding/list/biddings-table-toolbar-actions.tsx
@@ -3,7 +3,7 @@
 import * as React from "react"
 import { type Table } from "@tanstack/react-table"
 import {
-  Send, Download, FileSpreadsheet
+  Send, Download, FileSpreadsheet, Trash
 } from "lucide-react"
 import { toast } from "sonner"
 import { useSession } from "next-auth/react"
@@ -21,6 +21,8 @@ import { BiddingCreateDialog } from "@/components/bidding/create/bidding-create-
 import { useForm } from "react-hook-form"
 import { zodResolver } from "@hookform/resolvers/zod"
 import { createBiddingSchema } from "@/lib/bidding/validation"
+import { deleteBidding } from "@/lib/bidding/delete-action"
+import { BiddingDeleteDialog } from "./biddings-delete-dialog"
 
 interface BiddingsTableToolbarActionsProps {
   table: Table<BiddingListItem>
@@ -30,7 +32,8 @@ export function BiddingsTableToolbarActions({ table }: BiddingsTableToolbarActio
   const { data: session } = useSession()
   const [isExporting, setIsExporting] = React.useState(false)
   const [isTransmissionDialogOpen, setIsTransmissionDialogOpen] = React.useState(false)
-
+  const [isDeleteDialogOpen, setIsDeleteDialogOpen] = React.useState(false)
+  
   const userId = session?.user?.id ? Number(session.user.id) : 1
 
   // 입찰 생성 폼
@@ -83,8 +86,11 @@ export function BiddingsTableToolbarActions({ table }: BiddingsTableToolbarActio
 
   // 업체선정이 완료된 입찰만 전송 가능
   const canTransmit = true
-  console.log(canTransmit, 'canTransmit')
-  console.log(selectedBiddings, 'selectedBiddings')
+  
+  // 삭제 가능 여부: 선택된 항목이 정확히 1개이고, '입찰생성' 상태여야 함
+  const canDelete = React.useMemo(() => {
+    return selectedBiddings.length === 1 && selectedBiddings[0].status === 'bidding_generated'
+  }, [selectedBiddings])
 
   return (
     <>
@@ -94,7 +100,6 @@ export function BiddingsTableToolbarActions({ table }: BiddingsTableToolbarActio
           // 성공 시 테이블 새로고침 등 추가 작업
           // window.location.reload()
         }} />
-
         {/* 전송하기 (업체선정 완료된 입찰만) */}
         <Button
           variant="default"
@@ -106,6 +111,21 @@ export function BiddingsTableToolbarActions({ table }: BiddingsTableToolbarActio
           <Send className="size-4" aria-hidden="true" />
           <span className="hidden sm:inline">전송하기</span>
         </Button>
+        {/* 삭제 버튼 */}
+
+          <Button
+            variant="destructive"
+            size="sm"
+            onClick={() => setIsDeleteDialogOpen(true)}
+            disabled={!canDelete}
+            className="gap-2"
+          >
+            <Trash className="size-4" aria-hidden="true" />
+            <span className="hidden sm:inline">삭제</span>
+          </Button>
+
+
+
       </div>
 
       {/* 전송 다이얼로그 */}
@@ -115,6 +135,14 @@ export function BiddingsTableToolbarActions({ table }: BiddingsTableToolbarActio
         bidding={selectedBiddings[0]}
         userId={userId}
       />
+      
+      {/* 삭제 다이얼로그 */}
+      <BiddingDeleteDialog
+        open={isDeleteDialogOpen}
+        onOpenChange={setIsDeleteDialogOpen}
+        bidding={selectedBiddings[0]}
+        onSuccess={() => table.resetRowSelection()}
+      />
     </>
   )
 }
\ No newline at end of file
-- 
cgit v1.2.3

