From a8674e6b91fb4d356c311fad0251878de154da53 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 24 Nov 2025 11:16:32 +0000
Subject: (최겸) 구매 입찰 수정(폐찰, 낙찰 결재 기능 추가 등)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../bidding/manage/create-pre-quote-rfq-dialog.tsx | 62 +++++++++++++++-------
 1 file changed, 42 insertions(+), 20 deletions(-)

(limited to 'components/bidding/manage/create-pre-quote-rfq-dialog.tsx')

diff --git a/components/bidding/manage/create-pre-quote-rfq-dialog.tsx b/components/bidding/manage/create-pre-quote-rfq-dialog.tsx
index c49f6232..cdcf1ef1 100644
--- a/components/bidding/manage/create-pre-quote-rfq-dialog.tsx
+++ b/components/bidding/manage/create-pre-quote-rfq-dialog.tsx
@@ -51,8 +51,8 @@ import { MaterialGroupSelectorDialogSingle } from "@/components/common/material/
 import { MaterialSearchItem } from "@/lib/material/material-group-service"
 import { MaterialSelectorDialogSingle } from "@/components/common/selectors/material/material-selector-dialog-single"
 import { MaterialSearchItem as SAPMaterialSearchItem } from "@/components/common/selectors/material/material-service"
-import { ProcurementManagerSelector } from "@/components/common/selectors/procurement-manager"
-import type { ProcurementManagerWithUser } from "@/components/common/selectors/procurement-manager/procurement-manager-service"
+import { PurchaseGroupCodeSelector } from "@/components/common/selectors/purchase-group-code/purchase-group-code-selector"
+import { getBiddingById } from "@/lib/bidding/service"
 
 // 아이템 스키마
 const itemSchema = z.object({
@@ -122,7 +122,7 @@ export function CreatePreQuoteRfqDialog({
   const [isLoading, setIsLoading] = React.useState(false)
   const [previewCode, setPreviewCode] = React.useState("")
   const [isLoadingPreview, setIsLoadingPreview] = React.useState(false)
-  const [selectedManager, setSelectedManager] = React.useState<ProcurementManagerWithUser | undefined>(undefined)
+  const [selectedBidPic, setSelectedBidPic] = React.useState<any | undefined>(undefined)
   const { data: session } = useSession()
 
   const userId = React.useMemo(() => {
@@ -170,6 +170,29 @@ export function CreatePreQuoteRfqDialog({
     name: "items",
   })
 
+  // 입찰담당자 정보 로드
+  React.useEffect(() => {
+    const loadBiddingInfo = async () => {
+      if (!biddingId || !open) return
+
+      try {
+        const bidding = await getBiddingById(biddingId)
+        if (bidding && bidding.bidPicId) {
+          // 입찰담당자 정보를 로드하는 로직 추가 필요
+          // 현재는 임시로 bidPicId를 사용
+          setSelectedBidPic({
+            USER_ID: bidding.bidPicId,
+            DISPLAY_NAME: bidding.bidPicName || '입찰담당자'
+          })
+        }
+      } catch (error) {
+        console.error('Failed to load bidding info:', error)
+      }
+    }
+
+    loadBiddingInfo()
+  }, [biddingId, open])
+
   // 다이얼로그가 열릴 때 폼 초기화
   React.useEffect(() => {
     if (open) {
@@ -177,7 +200,7 @@ export function CreatePreQuoteRfqDialog({
         rfqType: "",
         rfqTitle: "",
         dueDate: undefined,
-        picUserId: undefined,
+        picUserId: selectedBidPic?.USER_ID,
         projectId: undefined,
         remark: "",
         items: initialItems.length > 0 ? initialItems : [
@@ -192,14 +215,13 @@ export function CreatePreQuoteRfqDialog({
           },
         ],
       })
-      setSelectedManager(undefined)
       setPreviewCode("")
     }
-  }, [open, initialItems, form])
+  }, [open, initialItems, form, selectedBidPic])
 
   // 견적담당자 선택 시 RFQ 코드 미리보기 생성
   React.useEffect(() => {
-    if (!selectedManager?.user?.id) {
+    if (!selectedBidPic?.USER_ID) {
       setPreviewCode("")
       return
     }
@@ -208,7 +230,7 @@ export function CreatePreQuoteRfqDialog({
     (async () => {
       setIsLoadingPreview(true)
       try {
-        const code = await previewGeneralRfqCode(selectedManager.user!.id!)
+        const code = await previewGeneralRfqCode(selectedBidPic.USER_ID)
         setPreviewCode(code)
       } catch (error) {
         console.error("코드 미리보기 오류:", error)
@@ -217,7 +239,7 @@ export function CreatePreQuoteRfqDialog({
         setIsLoadingPreview(false)
       }
     })()
-  }, [selectedManager])
+  }, [selectedBidPic])
 
   // 견적 종류 변경
   const handleRfqTypeChange = (value: string) => {
@@ -244,8 +266,8 @@ export function CreatePreQuoteRfqDialog({
         },
       ],
     })
-    setSelectedManager(undefined)
-    setPreviewCode("")
+      setSelectedBidPic(undefined)
+      setPreviewCode("")
     onOpenChange(false)
   }
 
@@ -255,12 +277,12 @@ export function CreatePreQuoteRfqDialog({
       return
     }
 
-    if (!selectedManager?.user?.id) {
-      toast.error("견적담당자를 선택해주세요")
+    if (!selectedBidPic?.USER_ID) {
+      toast.error("입찰담당자를 선택해주세요")
       return
     }
 
-    const picUserId = selectedManager.user.id
+    const picUserId = selectedBidPic.USER_ID
 
     setIsLoading(true)
     
@@ -476,13 +498,13 @@ export function CreatePreQuoteRfqDialog({
                         견적담당자 <span className="text-red-500">*</span>
                       </FormLabel>
                       <FormControl>
-                        <ProcurementManagerSelector
-                          selectedManager={selectedManager}
-                          onManagerSelect={(manager) => {
-                            setSelectedManager(manager)
-                            field.onChange(manager.user?.id)
+                        <PurchaseGroupCodeSelector
+                          selectedCode={selectedBidPic}
+                          onCodeSelect={(code) => {
+                            setSelectedBidPic(code)
+                            field.onChange(code.USER_ID)
                           }}
-                          placeholder="견적담당자를 선택하세요"
+                          placeholder="입찰담당자 선택"
                         />
                       </FormControl>
                       <FormDescription>
-- 
cgit v1.2.3

