From bac0228d21b7195065e9cddcc327ae33659c7bcc Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Sun, 1 Jun 2025 13:52:21 +0000
Subject: (대표님) 20250601까지 작업사항
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../items-table/item-table-toolbar-actions.tsx     | 36 ++++++++++++++++------
 1 file changed, 26 insertions(+), 10 deletions(-)

(limited to 'lib/vendors/items-table/item-table-toolbar-actions.tsx')

diff --git a/lib/vendors/items-table/item-table-toolbar-actions.tsx b/lib/vendors/items-table/item-table-toolbar-actions.tsx
index f7bd2bf6..8be67f71 100644
--- a/lib/vendors/items-table/item-table-toolbar-actions.tsx
+++ b/lib/vendors/items-table/item-table-toolbar-actions.tsx
@@ -1,3 +1,4 @@
+// components/vendor-items/item-table-toolbar-actions.tsx
 "use client"
 
 import * as React from "react"
@@ -8,21 +9,26 @@ import { toast } from "sonner"
 import { exportTableToExcel } from "@/lib/export"
 import { Button } from "@/components/ui/button"
 
-
 // 만약 서버 액션이나 API 라우트를 이용해 업로드 처리한다면 import
 import { importTasksExcel } from "@/lib/tasks/service" // 예시
-import {   VendorItemsView } from "@/db/schema/vendors"
+import {
+  VendorItemsView
+} from "@/db/schema/vendors"
 import { AddItemDialog } from "./add-item-dialog"
+import { DeleteVendorItemsDialog } from "./delete-vendor-items-dialog"
 
 interface VendorsTableToolbarActionsProps {
   table: Table<VendorItemsView>
   vendorId: number
 }
 
-export function VendorsTableToolbarActions({ table,vendorId }: VendorsTableToolbarActionsProps) {
+export function VendorsTableToolbarActions({ table, vendorId }: VendorsTableToolbarActionsProps) {
   // 파일 input을 숨기고, 버튼 클릭 시 참조해 클릭하는 방식
   const fileInputRef = React.useRef<HTMLInputElement>(null)
 
+  // 선택된 행들 가져오기
+  const selectedRows = table.getFilteredSelectedRowModel().rows
+
   // 파일이 선택되었을 때 처리
   async function onFileChange(event: React.ChangeEvent<HTMLInputElement>) {
     const file = event.target.files?.[0]
@@ -55,7 +61,6 @@ export function VendorsTableToolbarActions({ table,vendorId }: VendorsTableToolb
 
     } catch (err) {
       toast.error("파일 업로드 중 오류가 발생했습니다.")
-      
     }
   }
 
@@ -66,10 +71,21 @@ export function VendorsTableToolbarActions({ table,vendorId }: VendorsTableToolb
 
   return (
     <div className="flex items-center gap-2">
-
-      <AddItemDialog vendorId={vendorId}/>
-
-      {/** 3) Import 버튼 (파일 업로드) */}
+      <AddItemDialog vendorId={vendorId} />
+
+      {/* 삭제 버튼 - 선택된 행이 있을 때만 표시 */}
+      {selectedRows.length > 0 && (
+        <DeleteVendorItemsDialog
+          vendorId={vendorId}
+          items={selectedRows.map((row) => row.original)}
+          onSuccess={() => {
+            // 삭제 성공 후 선택 해제
+            table.toggleAllPageRowsSelected(false)
+          }}
+        />
+      )}
+
+      {/** Import 버튼 (파일 업로드) */}
       <Button variant="outline" size="sm" className="gap-2" onClick={handleImportClick}>
         <Upload className="size-4" aria-hidden="true" />
         <span className="hidden sm:inline">Import</span>
@@ -86,13 +102,13 @@ export function VendorsTableToolbarActions({ table,vendorId }: VendorsTableToolb
         onChange={onFileChange}
       />
 
-      {/** 4) Export 버튼 */}
+      {/** Export 버튼 */}
       <Button
         variant="outline"
         size="sm"
         onClick={() =>
           exportTableToExcel(table, {
-            filename: "tasks",
+            filename: "vendor-items",
             excludeColumns: ["select", "actions"],
           })
         }
-- 
cgit v1.2.3

