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

---
 .../table/enhanced-documents-table.tsx             | 112 +++++++--------------
 1 file changed, 39 insertions(+), 73 deletions(-)

(limited to 'lib/vendor-document-list/table/enhanced-documents-table.tsx')

diff --git a/lib/vendor-document-list/table/enhanced-documents-table.tsx b/lib/vendor-document-list/table/enhanced-documents-table.tsx
index d0f2991a..14c52455 100644
--- a/lib/vendor-document-list/table/enhanced-documents-table.tsx
+++ b/lib/vendor-document-list/table/enhanced-documents-table.tsx
@@ -10,7 +10,7 @@ import type {
 import { useDataTable } from "@/hooks/use-data-table"
 import { StageRevisionExpandedContent } from "./stage-revision-expanded-content"
 import { RevisionUploadDialog } from "./revision-upload-dialog"
-import { SimplifiedDocumentEditDialog } from "./simplified-document-edit-dialog"
+// ✅ UpdateDocumentSheet import 추가
 import { EnhancedDocTableToolbarActions } from "./enhanced-doc-table-toolbar-actions"
 import { getEnhancedDocuments } from "../enhanced-document-service"
 import type { EnhancedDocument } from "@/types/enhanced-documents"
@@ -27,22 +27,28 @@ import {
 import { getUpdatedEnhancedColumns } from "./enhanced-doc-table-columns"
 import { ExpandableDataTable } from "@/components/data-table/expandable-data-table"
 import { toast } from "sonner"
-// import { ViewDocumentDialog } from "@/components/documents/view-document-dialog"
+import { UpdateDocumentSheet } from "./update-doc-sheet"
 
 interface FinalIntegratedDocumentsTableProps {
   promises: Promise<[Awaited<ReturnType<typeof getEnhancedDocuments>>]>
   selectedPackageId: number
   projectType: "ship" | "plant"
+  // ✅ contractId 추가 (AddDocumentListDialog에서 필요)
+  contractId: number
 }
 
 export function EnhancedDocumentsTable({
   promises,
   selectedPackageId,
   projectType,
+  contractId, // ✅ contractId 추가
 }: FinalIntegratedDocumentsTableProps) {
   // 데이터 로딩
   const [{ data, pageCount, total }] = React.use(promises)
 
+  console.log(data)
+
+
   // 상태 관리
   const [rowAction, setRowAction] = React.useState<DataTableRowAction<EnhancedDocument> | null>(null)
   const [expandedRows, setExpandedRows] = React.useState<Set<string>>(new Set())
@@ -51,14 +57,12 @@ export function EnhancedDocumentsTable({
   // ✅ 스테이지 확장 상태 관리 (문서별로 관리)
   const [expandedStages, setExpandedStages] = React.useState<Record<string, Record<number, boolean>>>({})
   
-  // 다이얼로그 상태들
+  // ✅ 다이얼로그 상태들 - editDialogOpen -> editSheetOpen으로 변경
   const [uploadDialogOpen, setUploadDialogOpen] = React.useState(false)
-  const [editDialogOpen, setEditDialogOpen] = React.useState(false)
-  // const [viewDialogOpen, setViewDialogOpen] = React.useState(false)
+  const [editSheetOpen, setEditSheetOpen] = React.useState(false) // Sheet로 변경
   const [selectedDocument, setSelectedDocument] = React.useState<EnhancedDocument | null>(null)
   const [selectedStage, setSelectedStage] = React.useState<string>("")
   const [selectedRevision, setSelectedRevision] = React.useState<string>("")
-  // const [selectedRevisions, setSelectedRevisions] = React.useState<any[]>([])
   const [uploadMode, setUploadMode] = React.useState<'new' | 'append'>('new')
 
   // 다음 리비전 계산 함수
@@ -94,7 +98,7 @@ export function EnhancedDocumentsTable({
           // 액션 타입에 따른 다이얼로그 열기
           switch (action.type) {
             case "update":
-              setEditDialogOpen(true)
+              setEditSheetOpen(true) // ✅ Sheet 열기로 변경
               break
             case "upload":
               setSelectedStage(action.row.original.currentStageName || "")
@@ -114,9 +118,7 @@ export function EnhancedDocumentsTable({
           }
         }
       },
-
       projectType
-      
     }),
     [expandedRows, projectType]
   )
@@ -219,19 +221,10 @@ export function EnhancedDocumentsTable({
     return sortedRevisions[sortedRevisions.length - 1]?.revision || null
   }, [])
 
-  // const handleEditDocument = (document: EnhancedDocument) => {
-  //   setSelectedDocument(document)
-  //   setEditDialogOpen(true)
-  // }
-
-  // const handleViewRevisions = (revisions: any[]) => {
-  //   setSelectedRevisions(revisions)
-  //   setViewDialogOpen(true)
-  // }
-
+  // ✅ 새 문서 추가 핸들러 - EnhancedDocTableToolbarActions에서 AddDocumentListDialog를 직접 렌더링하므로 별도 상태 관리 불필요
   const handleNewDocument = () => {
-    setSelectedDocument(null)
-    setEditDialogOpen(true)
+    // AddDocumentListDialog는 자체적으로 Dialog trigger를 가지므로 별도 처리 불필요
+    // EnhancedDocTableToolbarActions에서 처리됨
   }
 
   // ✅ 스테이지 토글 핸들러 추가
@@ -266,19 +259,32 @@ export function EnhancedDocumentsTable({
     }
   }
 
-  // 다이얼로그 닫기
+  // ✅ 다이얼로그 닫기 함수 수정
   const closeAllDialogs = () => {
     setUploadDialogOpen(false)
-    setEditDialogOpen(false)
-    // setViewDialogOpen(false)
+    setEditSheetOpen(false) // editDialogOpen -> editSheetOpen
     setSelectedDocument(null)
     setSelectedStage("")
     setSelectedRevision("")
-    // setSelectedRevisions([])
     setUploadMode('new') // ✅ 모드 초기화
     setRowAction(null)
   }
 
+  // ✅ EnhancedDocument를 UpdateDocumentSheet의 document 형식으로 변환하는 함수
+  const convertToUpdateFormat = React.useCallback((doc: EnhancedDocument | null) => {
+    if (!doc) return null
+    
+    return {
+      id: doc.documentId,
+      contractId: contractId, // contractId 사용
+      docNumber: doc.docNumber,
+      title: doc.title,
+      status: doc.status || "pending", // 기본값 설정
+      description: doc.description || null,
+      remarks: doc.remarks || null,
+    }
+  }, [contractId])
+
   // 필터 필드 정의
   const filterFields: DataTableFilterField<EnhancedDocument>[] = [
     {
@@ -473,7 +479,6 @@ export function EnhancedDocumentsTable({
                 <StageRevisionExpandedContent 
                   document={document}
                   onUploadRevision={handleUploadRevision}
-                  // onViewRevision={handleViewRevisions}
                   projectType={projectType}
                   expandedStages={expandedStages[String(document.documentId)] || {}}
                   onStageToggle={(stageId) => handleStageToggle(String(document.documentId), stageId)}
@@ -492,44 +497,18 @@ export function EnhancedDocumentsTable({
                 table={table}
                 projectType={projectType}
                 selectedPackageId={selectedPackageId}
+                contractId={contractId} // ✅ contractId 추가
                 onNewDocument={handleNewDocument}
                 onBulkAction={handleBulkAction}
               />
             </DataTableAdvancedToolbar>
           </ExpandableDataTable>
         </div>
-        
-        {/* 선택된 항목 정보 */}
-        {/* {table.getFilteredSelectedRowModel().rows.length > 0 && (
-          <div className="flex items-center justify-between p-4 bg-blue-50 border border-blue-200 rounded-lg">
-            <span className="text-sm text-blue-700">
-              {table.getFilteredSelectedRowModel().rows.length}개 항목이 선택되었습니다
-            </span>
-            <div className="flex gap-2">
-              <Button
-                size="sm"
-                variant="outline"
-                onClick={() => table.toggleAllRowsSelected(false)}
-              >
-                선택 해제
-              </Button>
-              <Button
-                size="sm"
-                onClick={() => {
-                  const selectedRows = table.getFilteredSelectedRowModel().rows
-                  handleBulkAction('bulk_approve', selectedRows)
-                }}
-              >
-                선택 항목 승인
-              </Button>
-            </div>
-          </div>
-        )} */}
       </div>
 
-      {/* 분리된 다이얼로그들 */}
+      {/* ✅ 분리된 다이얼로그들 - UpdateDocumentSheet와 AddDocumentListDialog로 교체 */}
       
-      {/* ✅ 리비전 업로드 다이얼로그 - mode props 추가 */}
+      {/* 리비전 업로드 다이얼로그 - mode props 추가 */}
       <RevisionUploadDialog
         open={uploadDialogOpen}
         onOpenChange={(open) => {
@@ -543,28 +522,15 @@ export function EnhancedDocumentsTable({
         mode={uploadMode}
       />
 
-      {/* 문서 편집 다이얼로그 */}
-      <SimplifiedDocumentEditDialog
-        open={editDialogOpen}
-        onOpenChange={(open) => {
-          if (!open) closeAllDialogs()
-          else setEditDialogOpen(open)
-        }}
-        document={selectedDocument}
-        projectType={projectType}
-      />
-
-      {/* PDF 뷰어 다이얼로그 (기존 ViewDocumentDialog 재사용) */}
-      
-      {/* <ViewDocumentDialog
-        open={viewDialogOpen}
+      {/* ✅ 문서 편집 Sheet로 교체 */}
+      <UpdateDocumentSheet
+        open={editSheetOpen}
         onOpenChange={(open) => {
           if (!open) closeAllDialogs()
-          else setViewDialogOpen(open)
+          else setEditSheetOpen(open)
         }}
-        revisions={selectedRevisions}
+        document={convertToUpdateFormat(selectedDocument)}
       />
-      */}
     </div>
   )
 }
\ No newline at end of file
-- 
cgit v1.2.3

