From b84621f9b2b7161a5ad4f0b194264e9df3e65dbf Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 8 Jul 2025 11:23:40 +0000
Subject: (대표님) 20250708 미반영분 커밋
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../initial/initial-rfq-detail-toolbar-actions.tsx | 77 ++++++++++++++++++++--
 1 file changed, 72 insertions(+), 5 deletions(-)

(limited to 'lib/b-rfq/initial/initial-rfq-detail-toolbar-actions.tsx')

diff --git a/lib/b-rfq/initial/initial-rfq-detail-toolbar-actions.tsx b/lib/b-rfq/initial/initial-rfq-detail-toolbar-actions.tsx
index 639d338d..c26bda28 100644
--- a/lib/b-rfq/initial/initial-rfq-detail-toolbar-actions.tsx
+++ b/lib/b-rfq/initial/initial-rfq-detail-toolbar-actions.tsx
@@ -17,6 +17,7 @@ import {
 } from "lucide-react"
 import { AddInitialRfqDialog } from "./add-initial-rfq-dialog"
 import { DeleteInitialRfqDialog } from "./delete-initial-rfq-dialog"
+import { ShortListConfirmDialog } from "./short-list-confirm-dialog"
 import { InitialRfqDetailView } from "@/db/schema"
 import { sendBulkInitialRfqEmails } from "../service"
 
@@ -40,15 +41,26 @@ export function InitialRfqDetailTableToolbarActions({
 
     // 상태 관리
     const [showDeleteDialog, setShowDeleteDialog] = React.useState(false)
+    const [showShortListDialog, setShowShortListDialog] = React.useState(false)
     const [isEmailSending, setIsEmailSending] = React.useState(false)
 
-    const handleBulkEmail = async () => {
+    // 전체 벤더 리스트 가져오기 (ShortList 확정용)
+    const allVendors = table.getRowModel().rows.map(row => row.original)
+
+const handleBulkEmail = async () => {
         if (selectedCount === 0) return
 
         setIsEmailSending(true)
 
         try {
-            const initialRfqIds = selectedDetails.map(detail => detail.initialRfqId);
+            const initialRfqIds = selectedDetails
+                .map(detail => detail.initialRfqId)
+                .filter((id): id is number => id !== null);
+
+            if (initialRfqIds.length === 0) {
+                toast.error("유효한 RFQ ID가 없습니다.")
+                return
+            }
 
             const result = await sendBulkInitialRfqEmails({
                 initialRfqIds,
@@ -113,9 +125,23 @@ export function InitialRfqDetailTableToolbarActions({
 
     // S/L 확정 버튼 클릭
     const handleSlConfirm = () => {
-        if (rfqId) {
-            router.push(`/evcp/b-rfq/${rfqId}`)
+        if (!rfqId || allVendors.length === 0) {
+            toast.error("S/L 확정할 벤더가 없습니다.")
+            return
         }
+
+        // 진행 가능한 상태 확인
+        const validVendors = allVendors.filter(vendor => 
+            vendor.initialRfqStatus === "Init. RFQ Answered" || 
+            vendor.initialRfqStatus === "Init. RFQ Sent"
+        )
+
+        if (validVendors.length === 0) {
+            toast.error("S/L 확정이 가능한 벤더가 없습니다. (RFQ 발송 또는 응답 완료된 벤더만 가능)")
+            return
+        }
+
+        setShowShortListDialog(true)
     }
 
     // 초기 RFQ 추가 성공 시 처리
@@ -146,12 +172,37 @@ export function InitialRfqDetailTableToolbarActions({
         }
     }
 
+    // Short List 확정 성공 시 처리
+    const handleShortListSuccess = () => {
+        // 선택 해제
+        table.toggleAllRowsSelected(false)
+        setShowShortListDialog(false)
+
+        // 데이터 새로고침
+        if (onRefresh) {
+            onRefresh()
+        }
+
+        // 최종 RFQ 페이지로 이동
+        if (rfqId) {
+            toast.success("Short List가 확정되었습니다. 최종 RFQ 페이지로 이동합니다.")
+            setTimeout(() => {
+                router.push(`/evcp/b-rfq/${rfqId}`)
+            }, 1500)
+        }
+    }
+
     // 선택된 항목 중 첫 번째를 기본값으로 사용
     const defaultValues = selectedCount > 0 ? selectedDetails[0] : undefined
 
     const canDelete = selectedDetails.every(detail => detail.initialRfqStatus === "DRAFT")
     const draftCount = selectedDetails.filter(detail => detail.initialRfqStatus === "DRAFT").length
 
+    // S/L 확정 가능한 벤더 수
+    const validForShortList = allVendors.filter(vendor => 
+        vendor.initialRfqStatus === "Init. RFQ Answered" || 
+        vendor.initialRfqStatus === "Init. RFQ Sent"
+    ).length
 
     return (
         <>
@@ -191,9 +242,11 @@ export function InitialRfqDetailTableToolbarActions({
                         size="sm"
                         onClick={handleSlConfirm}
                         className="h-8"
+                        disabled={validForShortList === 0}
+                        title={validForShortList === 0 ? "S/L 확정이 가능한 벤더가 없습니다" : `${validForShortList}개 벤더 중 Short List 선택`}
                     >
                         <CheckCircle2 className="mr-2 h-4 w-4" />
-                        S/L 확정
+                        S/L 확정 ({validForShortList})
                     </Button>
                 )}
 
@@ -215,6 +268,20 @@ export function InitialRfqDetailTableToolbarActions({
                 showTrigger={false}
                 onSuccess={handleDeleteSuccess}
             />
+
+            {/* Short List 확정 다이얼로그 */}
+            {rfqId && (
+                <ShortListConfirmDialog
+                    open={showShortListDialog}
+                    onOpenChange={setShowShortListDialog}
+                    rfqId={rfqId}
+                    vendors={allVendors.filter(vendor => 
+                        vendor.initialRfqStatus === "Init. RFQ Answered" || 
+                        vendor.initialRfqStatus === "Init. RFQ Sent"
+                    )}
+                    onSuccess={handleShortListSuccess}
+                />
+            )}
         </>
     )
 }
\ No newline at end of file
-- 
cgit v1.2.3

