From bde9151154dc9731046ac3facdc4869b7612a7af Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Fri, 22 Aug 2025 02:18:10 +0000
Subject: (김준회) 설계 데이터 입력 - EDP 에 클라이언트가 직접 요청 보내던 문제
 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/form-data/form-data-table.tsx | 112 +++----------------------------
 1 file changed, 11 insertions(+), 101 deletions(-)

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

diff --git a/components/form-data/form-data-table.tsx b/components/form-data/form-data-table.tsx
index c9632c8c..a2645679 100644
--- a/components/form-data/form-data-table.tsx
+++ b/components/form-data/form-data-table.tsx
@@ -16,30 +16,25 @@ import { Button } from "../ui/button";
 import {
   Download,
   Loader,
-  Save,
   Upload,
   Plus,
   Tag,
   TagsIcon,
-  FileText,
-  FileSpreadsheet,
   FileOutput,
   Clipboard,
   Send,
   GitCompareIcon,
   RefreshCcw,
   Trash2,
-  Eye // 새로 추가된 아이콘
+  Eye
 } from "lucide-react";
 import { toast } from "sonner";
 import {
   getPackageCodeById,
   getProjectById,
-  getProjectCodeById,
   getReportTempList,
   sendFormDataToSEDP,
   syncMissingTags,
-  updateFormDataInDB,
 } from "@/lib/forms/services";
 import { UpdateTagSheet } from "./update-form-sheet";
 import { FormDataReportTempUploadDialog } from "./form-data-report-temp-upload-dialog";
@@ -50,101 +45,18 @@ import {
   DropdownMenuContent,
   DropdownMenuItem,
   DropdownMenuTrigger,
-  DropdownMenuSeparator,
 } from "@/components/ui/dropdown-menu";
 import { AddFormTagDialog } from "./add-formTag-dialog";
 import { importExcelData } from "./import-excel-form";
 import { exportExcelData } from "./export-excel-form";
 import { SEDPConfirmationDialog, SEDPStatusDialog } from "./sedp-components";
 import { SEDPCompareDialog } from "./sedp-compare-dialog";
-import { getSEDPToken } from "@/lib/sedp/sedp-token";
 import { DeleteFormDataDialog } from "./delete-form-data-dialog";
 import { TemplateViewDialog } from "./spreadJS-dialog";
-
-// 기존 fetchTagDataFromSEDP 함수
-async function fetchTagDataFromSEDP(projectCode: string, formCode: string): Promise<any> {
-  try {
-    // Get the token
-    const apiKey = await getSEDPToken();
-
-    // Define the API base URL
-    const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api';
-
-    // Make the API call
-    const response = await fetch(
-      `${SEDP_API_BASE_URL}/Data/GetPubData`,
-      {
-        method: 'POST',
-        headers: {
-          'Content-Type': 'application/json',
-          'accept': '*/*',
-          'ApiKey': apiKey,
-          'ProjectNo': projectCode
-        },
-        body: JSON.stringify({
-          ProjectNo: projectCode,
-          REG_TYPE_ID: formCode,
-          ContainDeleted: false
-        })
-      }
-    );
-
-    if (!response.ok) {
-      const errorText = await response.text();
-      throw new Error(`SEDP API request failed: ${response.status} ${response.statusText} - ${errorText}`);
-    }
-
-    const data = await response.json();
-    return data;
-  } catch (error: any) {
-    console.error('Error calling SEDP API:', error);
-    throw new Error(`Failed to fetch data from SEDP API: ${error.message || 'Unknown error'}`);
-  }
-}
-
-// 새로 추가된 fetchTemplateFromSEDP 함수
-async function fetchTemplateFromSEDP(projectCode: string, formCode: string): Promise<any> {
-  try {
-    // Get the token
-    const apiKey = await getSEDPToken();
-
-    // Define the API base URL
-    const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api';
-
-    // Make the API call
-    const response = await fetch(
-      `${SEDP_API_BASE_URL}/Template/GetByRegisterID`,
-      {
-        method: 'POST',
-        headers: {
-          'Content-Type': 'application/json',
-          'accept': '*/*',
-          'ApiKey': apiKey,
-          'ProjectNo': projectCode
-        },
-        body: JSON.stringify({
-          WithContent: true,
-          ProjectNo: projectCode,
-          REG_TYPE_ID: formCode
-        })
-      }
-    );
-
-    if (!response.ok) {
-      const errorText = await response.text();
-      throw new Error(`SEDP Template API request failed: ${response.status} ${response.statusText} - ${errorText}`);
-    }
-
-    const data = await response.json();
-    return data;
-  } catch (error: any) {
-    console.error('Error calling SEDP Template API:', error);
-    throw new Error(`Failed to fetch template from SEDP API: ${error.message || 'Unknown error'}`);
-  }
-}
+import { fetchTemplateFromSEDP } from "@/lib/forms/sedp-actions";
 
 interface GenericData {
-  [key: string]: any;
+  [key: string]: unknown;
 }
 
 export interface DynamicTableProps {
@@ -194,13 +106,12 @@ export default function DynamicTable({
 
   // 폴링 상태 관리를 위한 ref
   const pollingRef = React.useRef<NodeJS.Timeout | null>(null);
-  const [syncId, setSyncId] = React.useState<string | null>(null);
 
   // Separate loading states for different operations
   const [isSyncingTags, setIsSyncingTags] = React.useState(false);
   const [isImporting, setIsImporting] = React.useState(false);
   const [isExporting, setIsExporting] = React.useState(false);
-  const [isSaving, setIsSaving] = React.useState(false);
+  const [isSaving] = React.useState(false);
   const [isSendingSEDP, setIsSendingSEDP] = React.useState(false);
   const [isLoadingTags, setIsLoadingTags] = React.useState(false);
   const [isLoadingTemplate, setIsLoadingTemplate] = React.useState(false); // 새로 추가
@@ -227,7 +138,7 @@ export default function DynamicTable({
 
   // 새로 추가된 Template 다이얼로그 상태
   const [templateDialogOpen, setTemplateDialogOpen] = React.useState(false);
-  const [templateData, setTemplateData] = React.useState<any>(null);
+  const [templateData, setTemplateData] = React.useState<unknown>(null);
 
   const [tempUpDialog, setTempUpDialog] = React.useState(false);
   const [reportData, setReportData] = React.useState<GenericData[]>([]);
@@ -415,7 +326,6 @@ export default function DynamicTable({
 
       // 작업 ID 저장
       if (data.syncId) {
-        setSyncId(data.syncId);
         toast.info('Tag import started. This may take a while...');
 
         // 상태 확인을 위한 폴링 시작
@@ -462,7 +372,6 @@ export default function DynamicTable({
 
           // 상태 초기화
           setIsLoadingTags(false);
-          setSyncId(null);
 
           // 성공 메시지 표시
           toast.success(
@@ -477,7 +386,6 @@ export default function DynamicTable({
           }
 
           setIsLoadingTags(false);
-          setSyncId(null);
           toast.error(data.error || 'Import failed');
         } else if (data.status === 'processing') {
           // 진행 상태 업데이트 (선택적)
@@ -575,7 +483,10 @@ export default function DynamicTable({
       setIsSendingSEDP(true);
 
       // Validate data
-      const invalidData = tableData.filter((item) => !item.TAG_NO?.trim());
+      const invalidData = tableData.filter((item) => {
+        const tagNo = item.TAG_NO;
+        return !tagNo || (typeof tagNo === 'string' && !tagNo.trim());
+      });
       if (invalidData.length > 0) {
         toast.error(`태그 번호가 없는 항목이 ${invalidData.length}개 있습니다.`);
         setSedpConfirmOpen(false);
@@ -619,13 +530,13 @@ export default function DynamicTable({
       // Refresh the route to get fresh data
       router.refresh();
 
-    } catch (err: any) {
+    } catch (err: unknown) {
       console.error("SEDP error:", err);
 
       // Set error status
       setSedpStatusData({
         status: 'error',
-        message: err.message || "An unexpected error occurred",
+        message: err instanceof Error ? err.message : "An unexpected error occurred",
         successCount: 0,
         errorCount: tableData.length,
         totalCount: tableData.length
@@ -1001,7 +912,6 @@ export default function DynamicTable({
         columnsJSON={columnsJSON}
         projectCode={projectCode}
         formCode={formCode}
-        fetchTagDataFromSEDP={fetchTagDataFromSEDP}
         projectType={projectType}
         packageCode={packageCode}
       />
-- 
cgit v1.2.3

