From f2fafe555b65f9207c2c6e216b7d7b2ff83af866 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 3 Nov 2025 10:15:45 +0000
Subject: (최겸) 구매 PQ/실사 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/rfq-last/table/rfq-table-toolbar-actions.tsx | 59 +++++++++++++++++++++---
 1 file changed, 52 insertions(+), 7 deletions(-)

(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 00c41402..148336fb 100644
--- a/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
+++ b/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
@@ -3,10 +3,11 @@
 import * as React from "react";
 import { Table } from "@tanstack/react-table";
 import { Button } from "@/components/ui/button";
-import { Users, RefreshCw, FileDown, Plus } from "lucide-react";
+import { Users, RefreshCw, FileDown, Plus, Edit } 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 { Badge } from "@/components/ui/badge";
 import {
   Tooltip,
@@ -21,12 +22,14 @@ interface RfqTableToolbarActionsProps<TData> {
   onRefresh?: () => void;
 }
 
-export function RfqTableToolbarActions<TData>({ 
-  table, 
+export function RfqTableToolbarActions<TData>({
+  table,
   rfqCategory = "itb",
-  onRefresh 
+  onRefresh
 }: RfqTableToolbarActionsProps<TData>) {
   const [showAssignDialog, setShowAssignDialog] = React.useState(false);
+  const [showUpdateDialog, setShowUpdateDialog] = React.useState(false);
+  const [selectedRfqForUpdate, setSelectedRfqForUpdate] = React.useState<number | null>(null);
 
   console.log(rfqCategory)
   
@@ -41,6 +44,9 @@ export function RfqTableToolbarActions<TData>({
       (row.status === "RFQ 생성" || row.status === "구매담당지정")
     );
 
+    // 수정 가능한 RFQ (general 카테고리에서 RFQ 생성 상태인 항목, 단일 선택만)
+    const updatableRfq = rfqCategory === "general" && rows.length === 1 && rows[0].status === "RFQ 생성" ? rows[0] : null;
+
     return {
       ids: rows.map(row => row.id),
       codes: rows.map(row => row.rfqCode || ""),
@@ -51,9 +57,12 @@ export function RfqTableToolbarActions<TData>({
       // 담당자 지정 가능한 ITB (상태가 "RFQ 생성" 또는 "구매담당지정"인 ITB)
       assignableItbCount: assignableRows.length,
       assignableIds: assignableRows.map(row => row.id),
-      assignableCodes: assignableRows.map(row => row.rfqCode || "")
+      assignableCodes: assignableRows.map(row => row.rfqCode || ""),
+      // 수정 가능한 RFQ 정보
+      updatableRfq: updatableRfq,
+      canUpdate: updatableRfq !== null,
     };
-  }, [selectedRows]);
+  }, [selectedRows, rfqCategory]);
 
   // 담당자 지정 가능 여부 체크 (상태가 "RFQ 생성" 또는 "구매담당지정"인 ITB가 있는지)
   const canAssignPic = selectedRfqData.assignableItbCount > 0;
@@ -69,6 +78,20 @@ export function RfqTableToolbarActions<TData>({
     onRefresh?.(); // 테이블 데이터 새로고침
   };
 
+  const handleUpdateGeneralRfqSuccess = () => {
+    // 테이블 선택 초기화
+    table.toggleAllPageRowsSelected(false);
+    // 데이터 새로고침
+    onRefresh?.();
+  };
+
+  const handleUpdateClick = () => {
+    if (selectedRfqData.updatableRfq) {
+      setSelectedRfqForUpdate(selectedRfqData.updatableRfq.id);
+      setShowUpdateDialog(true);
+    }
+  };
+
   return (
     <>
       <div className="flex items-center gap-2">
@@ -131,7 +154,21 @@ export function RfqTableToolbarActions<TData>({
         </Button>
 
         {rfqCategory === "general" && (
-          <CreateGeneralRfqDialog onSuccess={handleCreateGeneralRfqSuccess} />
+          <>
+            <CreateGeneralRfqDialog onSuccess={handleCreateGeneralRfqSuccess} />
+            {/* 일반견적 수정 버튼 - 선택된 항목이 1개이고 RFQ 생성 상태일 때만 활성화 */}
+            {selectedRfqData.canUpdate && (
+                    <Button
+                      variant="outline"
+                      size="sm"
+                      onClick={handleUpdateClick}
+                      className="flex items-center gap-2"
+                    >
+                      <Edit className="h-4 w-4" />
+                      일반견적 수정
+                    </Button>
+            )}
+          </>
         )}
         <Button
           variant="outline"
@@ -153,6 +190,14 @@ export function RfqTableToolbarActions<TData>({
         selectedRfqCodes={selectedRfqData.assignableCodes}
         onSuccess={handleAssignSuccess}
       />
+
+      {/* 일반견적 수정 다이얼로그 */}
+      <UpdateGeneralRfqDialog
+        open={showUpdateDialog}
+        onOpenChange={setShowUpdateDialog}
+        rfqId={selectedRfqForUpdate || 0}
+        onSuccess={handleUpdateGeneralRfqSuccess}
+      />
     </>
   );
 }
\ No newline at end of file
-- 
cgit v1.2.3

