From 8440ac29c7dcbef992039678ecc0fabff2fd04ec Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 1 Dec 2025 00:58:23 +0000
Subject: (대표님) S-EDP 관련 대표님 작업사항
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/form-data-plant/form-data-table.tsx | 91 +++++++++-----------------
 1 file changed, 30 insertions(+), 61 deletions(-)

(limited to 'components/form-data-plant/form-data-table.tsx')

diff --git a/components/form-data-plant/form-data-table.tsx b/components/form-data-plant/form-data-table.tsx
index 30c176bd..c6c79a69 100644
--- a/components/form-data-plant/form-data-table.tsx
+++ b/components/form-data-plant/form-data-table.tsx
@@ -76,7 +76,8 @@ interface GenericData {
 export interface DynamicTableProps {
   dataJSON: GenericData[];
   columnsJSON: DataTableColumnJSON[];
-  contractItemId: number;
+  projectCode: string;
+  packageCode: string;
   formCode: string;
   formId: number;
   projectId: number;
@@ -89,7 +90,8 @@ export interface DynamicTableProps {
 export default function DynamicTable({
   dataJSON,
   columnsJSON,
-  contractItemId,
+  projectCode,
+  packageCode,
   formCode,
   formId,
   projectId,
@@ -156,7 +158,8 @@ export default function DynamicTable({
       // 서버 액션 호출
       const result = await excludeFormDataByTags({
         formCode,
-        contractItemId,
+        projectCode,
+        packageCode,
         tagNumbers,
       });
 
@@ -288,7 +291,7 @@ export default function DynamicTable({
       try {
         setIsLoadingStats(true);
         // getFormStatusByVendor 서버 액션 직접 호출
-        const data = await getFormStatusByVendor(projectId, contractItemId, formCode);
+        const data = await getFormStatusByVendor(projectId, projectCode, packageCode,formCode);
 
         if (data && data.length > 0) {
           setFormStats(data[0]);
@@ -339,9 +342,7 @@ export default function DynamicTable({
 
   // SEDP compare dialog state 
   const [sedpCompareOpen, setSedpCompareOpen] = React.useState(false);
-  const [projectCode, setProjectCode] = React.useState<string>('');
-  const [projectType, setProjectType] = React.useState<string>('plant');
-  const [packageCode, setPackageCode] = React.useState<string>('');
+  const projectType = "plant";
 
   // 새로 추가된 Template 다이얼로그 상태
   const [templateDialogOpen, setTemplateDialogOpen] = React.useState(false);
@@ -374,43 +375,13 @@ const [isLoadingRegisters, setIsLoadingRegisters] = React.useState(false);
 
   React.useEffect(() => {
     const getTempCount = async () => {
-      const tempList = await getReportTempList(contractItemId, formId);
+      const tempList = await getReportTempList(projectCode, packageCode, formId);
       setTempCount(tempList.length);
     };
 
     getTempCount();
-  }, [contractItemId, formId, tempUpDialog]);
+  }, [projectCode,packageCode, formId, tempUpDialog]);
 
-  React.useEffect(() => {
-    const getPackageCode = async () => {
-      try {
-        const packageCode = await getPackageCodeById(contractItemId);
-        setPackageCode(packageCode || ''); // 빈 문자열이나 다른 기본값
-      } catch (error) {
-        console.error('패키지 조회 실패:', error);
-        setPackageCode('');
-      }
-    };
-
-    getPackageCode();
-  }, [contractItemId])
-  // Get project code when component mounts
-  React.useEffect(() => {
-    const getProjectCode = async () => {
-      try {
-        const project = await getProjectById(projectId);
-        setProjectCode(project.code);
-        setProjectType(project.type);
-      } catch (error) {
-        console.error("Error fetching project code:", error);
-        toast.error("Failed to fetch project code");
-      }
-    };
-
-    if (projectId) {
-      getProjectCode();
-    }
-  }, [projectId]);
 
   // 선택된 행들의 실제 데이터 가져오기
   const getSelectedRowsData = React.useCallback(() => {
@@ -529,7 +500,7 @@ React.useEffect(() => {
   async function handleSyncTags() {
     try {
       setIsSyncingTags(true);
-      const result = await syncMissingTags(contractItemId, formCode);
+      const result = await syncMissingTags(projectCode,packageCode, formCode);
 
       // Prepare the toast messages based on what changed
       const changes = [];
@@ -562,9 +533,9 @@ React.useEffect(() => {
       setIsLoadingTags(true);
 
       // API 엔드포인트 호출 - 작업 시작만 요청
-      const response = await fetch('/api/cron/form-tags/start', {
+      const response = await fetch('/api/cron/form-tags-plant/start', {
         method: 'POST',
-        body: JSON.stringify({ projectCode, formCode, contractItemId })
+        body: JSON.stringify({ projectCode, formCode, packageCode })
       });
 
       if (!response.ok) {
@@ -603,7 +574,7 @@ React.useEffect(() => {
     // 5초마다 상태 확인
     pollingRef.current = setInterval(async () => {
       try {
-        const response = await fetch(`/api/cron/form-tags/status?id=${id}`);
+        const response = await fetch(`/api/cron/form-tags-plant/status?id=${id}`);
 
         if (!response.ok) {
           throw new Error('Failed to get tag import status');
@@ -666,7 +637,8 @@ React.useEffect(() => {
         tableData,
         columnsJSON,
         formCode,
-        contractItemId,
+        projectCode,
+        packageCode,
         editableFieldsMap, // 추가: 편집 가능 필드 정보 전달
         onPendingChange: setIsImporting, // Let importExcelData handle loading state
         onDataUpdate: (newData) => {
@@ -747,7 +719,8 @@ React.useEffect(() => {
       const sedpResult = await sendFormDataToSEDP(
         formCode,        // Send formCode instead of formName
         projectId,       // Project ID
-        contractItemId,
+        projectCode,
+        packageCode,
         tableData.filter(v=>v.status !== 'excluded'),       // Table data
         columnsJSON      // Column definitions
       );
@@ -1226,7 +1199,8 @@ React.useEffect(() => {
         columns={columnsJSON}
         rowData={rowAction?.row.original ?? null}
         formCode={formCode}
-        contractItemId={contractItemId}
+        projectCode={projectCode}
+        packageCode={packageCode}
         editableFieldsMap={editableFieldsMap}
         onUpdateSuccess={(updatedValues) => {
           // Update the specific row in tableData when a single row is updated
@@ -1244,7 +1218,8 @@ React.useEffect(() => {
       <DeleteFormDataDialog
         formData={deleteTarget}
         formCode={formCode}
-        contractItemId={contractItemId}
+        projectCode={projectCode}
+        packageCode={packageCode}
         projectId={projectId}
         open={deleteDialogOpen}
         onOpenChange={(open) => {
@@ -1257,16 +1232,6 @@ React.useEffect(() => {
         showTrigger={false}
       />
 
-      {/* Dialog for adding tags */}
-      {/* <AddFormTagDialog
-        projectId={projectId}
-        formCode={formCode}
-        formName={`Form ${formCode}`}
-        contractItemId={contractItemId}
-        packageCode={packageCode}
-        open={addTagDialogOpen}
-        onOpenChange={setAddTagDialogOpen}
-      /> */}
 
       {/* 새로 추가된 Template 다이얼로그 */}
       <TemplateViewDialog
@@ -1276,7 +1241,8 @@ React.useEffect(() => {
         selectedRow={selectedRowsData[0]} // SPR_ITM_LST_SETUP용
         tableData={tableData} // SPR_LST_SETUP용 - 새로 추가
         formCode={formCode}
-        contractItemId={contractItemId}
+        projectCode={projectCode}
+        packageCode={packageCode}
         editableFieldsMap={editableFieldsMap}
         columnsJSON={columnsJSON}
         onUpdateSuccess={(updatedValues) => {
@@ -1344,7 +1310,8 @@ React.useEffect(() => {
           columnsJSON={columnsJSON}
           open={tempUpDialog}
           setOpen={setTempUpDialog}
-          packageId={contractItemId}
+          projectCode={projectCode}
+          packageCode={packageCode}
           formCode={formCode}
           formId={formId}
           uploaderType="vendor"
@@ -1356,7 +1323,8 @@ React.useEffect(() => {
           columnsJSON={columnsJSON}
           reportData={reportData}
           setReportData={setReportData}
-          packageId={contractItemId}
+          projectCode={projectCode}
+          packageCode={packageCode}
           formCode={formCode}
           formId={formId}
         />
@@ -1368,7 +1336,8 @@ React.useEffect(() => {
           setOpen={setBatchDownDialog}
           columnsJSON={columnsJSON}
           reportData={selectedRowCount > 0 ? getSelectedRowsData() : tableData}
-          packageId={contractItemId}
+          projectCode={projectCode}
+          packageCode={packageCode}
           formCode={formCode}
           formId={formId}
         />
-- 
cgit v1.2.3

