From 33e8452331c301430191b3506825ebaf3edac93a Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Wed, 1 Oct 2025 09:48:03 +0000
Subject: (최겸) 구매 PQ 리스트 기능 수정, 견적 첨부파일 리비전 액션 추가, 기타
 등
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/pq/table/pq-lists-table.tsx | 45 +++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)

(limited to 'lib/pq/table/pq-lists-table.tsx')

diff --git a/lib/pq/table/pq-lists-table.tsx b/lib/pq/table/pq-lists-table.tsx
index c5fd82a5..1be0a1c7 100644
--- a/lib/pq/table/pq-lists-table.tsx
+++ b/lib/pq/table/pq-lists-table.tsx
@@ -13,10 +13,12 @@ import {
   deletePQListsAction,
   copyPQListAction,
   togglePQListsAction,
+  updatePqValidToAction,
 } from "@/lib/pq/service"
 import { CopyPqDialog } from "./copy-pq-list-dialog"
 import { AddPqDialog } from "./add-pq-list-dialog"
 import { PQListsToolbarActions } from "./pq-lists-toolbar"
+import { EditValidToSheet } from "./pq-lists-columns"
 import type { DataTableRowAction } from "@/types/table"
 
 interface Project {
@@ -34,10 +36,12 @@ export function PqListsTable({ promises }: PqListsTableProps) {
   const [rowAction, setRowAction] = React.useState<DataTableRowAction<PQList> | null>(null)
   const [createDialogOpen, setCreateDialogOpen] = React.useState(false)
   const [copyDialogOpen, setCopyDialogOpen] = React.useState(false)
+  const [editValidToSheetOpen, setEditValidToSheetOpen] = React.useState(false)
+  const [selectedPqList, setSelectedPqList] = React.useState<PQList | null>(null)
   const [isPending, startTransition] = React.useTransition()
 
   const [{ data, pageCount }, projects] = React.use(promises)
-  const activePqLists = data.filter((item) => !item.isDeleted)
+  // const activePqLists = data.filter((item) => !item.isDeleted)
 
   const columns = React.useMemo(() => createPQListsColumns({ setRowAction }), [setRowAction])
 
@@ -116,15 +120,38 @@ export function PqListsTable({ promises }: PqListsTableProps) {
     })
   }
 
+  const handleUpdateValidTo = React.useCallback(async (pqListId: number, newValidTo: Date | null) => {
+    startTransition(async () => {
+      try {
+        const result = await updatePqValidToAction({ pqListId, validTo: newValidTo })
+        if (result.success) {
+          toast.success(result.message || "유효일이 성공적으로 수정되었습니다")
+          setEditValidToSheetOpen(false)
+          setSelectedPqList(null)
+          router.refresh()
+        } else {
+          toast.error(`유효일 수정 실패: ${result.error}`)
+        }
+      } catch (error) {
+        console.error("유효일 수정 실패:", error)
+        toast.error("유효일 수정 실패")
+      }
+    })
+  }, [])
+
   React.useEffect(() => {
     if (!rowAction) return
-    const id = rowAction.row.original.id
+    const pqList = rowAction.row.original
     switch (rowAction.type) {
       case "view":
-        router.push(`/evcp/pq-criteria/${id}`)
+        router.push(`/evcp/pq-criteria/${pqList.id}`)
         break
       case "delete":
-        handleDelete([id])
+        handleDelete([pqList.id])
+        break
+      case "editValidTo":
+        setSelectedPqList(pqList)
+        setEditValidToSheetOpen(true)
         break
     }
     setRowAction(null)
@@ -153,18 +180,24 @@ export function PqListsTable({ promises }: PqListsTableProps) {
         open={createDialogOpen}
         onOpenChange={setCreateDialogOpen}
         onSubmit={handleCreate}
-        projects={projects}
         isLoading={isPending}
       />
 
       <CopyPqDialog
         open={copyDialogOpen}
         onOpenChange={setCopyDialogOpen}
-        pqLists={activePqLists}
+        pqLists={data}
         projects={projects}
         onCopy={handleCopy}
         isLoading={isPending}
       />
+
+      <EditValidToSheet
+        pqList={selectedPqList}
+        open={editValidToSheetOpen}
+        onOpenChange={setEditValidToSheetOpen}
+        onUpdate={handleUpdateValidTo}
+      />
     </>
   )
 }
-- 
cgit v1.2.3

