From 792fb0c21136eededecf52b5b4aa1a252bdc4bfb Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Tue, 29 Jul 2025 11:47:34 +0000
Subject: (김준회) 파트너 Engineering 메뉴 수정, Knox 결재 로깅 추가
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/knox/approval/ApprovalSubmit.tsx | 39 +++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 7 deletions(-)

(limited to 'components/knox/approval/ApprovalSubmit.tsx')

diff --git a/components/knox/approval/ApprovalSubmit.tsx b/components/knox/approval/ApprovalSubmit.tsx
index f3c1fa3d..8b58aba6 100644
--- a/components/knox/approval/ApprovalSubmit.tsx
+++ b/components/knox/approval/ApprovalSubmit.tsx
@@ -17,6 +17,7 @@ import { Checkbox } from '@/components/ui/checkbox';
 import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
 import { toast } from 'sonner';
 import { Loader2, Trash2, FileText, AlertCircle, GripVertical } from 'lucide-react';
+import { debugLog, debugError } from '@/lib/debug-utils'
 
 // dnd-kit imports for drag and drop
 import {
@@ -760,12 +761,28 @@ export default function ApprovalSubmit({ onSubmitSuccess }: ApprovalSubmitProps)
     setSubmitResult(null);
 
     try {
+      // 세션 정보 확인
+      if (!session?.user) {
+        toast.error('로그인이 필요합니다.');
+        return;
+      }
+
+      const currentEmail = session.user.email ?? '';
+      const currentEpId = (session.user as { epId?: string }).epId;
+      const currentUserId = session.user.id ?? '';
+
+      debugLog('Current User', session.user);
+
+      if (!currentEpId) {
+        toast.error('사용자 정보가 올바르지 않습니다.');
+        return;
+      }
+
       // 결재 경로 생성 (ID 제거하고 API 호출)
       const approvalLines: ApprovalLine[] = await Promise.all(
         data.aplns.map((apln) =>
           createApprovalLine(
-            // userId: apln.userId 는 불필요하므로 제거
-            { epId: apln.epId, emailAddress: apln.emailAddress },
+            { epId: apln.epId },
             apln.role,
             apln.seq,
             { opinion: apln.opinion }
@@ -773,6 +790,8 @@ export default function ApprovalSubmit({ onSubmitSuccess }: ApprovalSubmitProps)
         )
       );
 
+      debugLog('Approval Lines', approvalLines);
+
       // 상신 요청 생성
       const attachmentsArray = data.attachments ? Array.from(data.attachments as FileList) : undefined;
 
@@ -781,7 +800,7 @@ export default function ApprovalSubmit({ onSubmitSuccess }: ApprovalSubmitProps)
         data.subject,
         approvalLines,
         {
-          contentsType: 'HTML',
+          contentsType: data.contentsType,
           docSecuType: data.docSecuType,
           urgYn: data.urgYn ? 'Y' : 'N',
           importantYn: data.importantYn ? 'Y' : 'N',
@@ -796,11 +815,17 @@ export default function ApprovalSubmit({ onSubmitSuccess }: ApprovalSubmitProps)
       // API 호출 (보안 등급에 따라 분기)
       const isSecure = data.docSecuType === 'CONFIDENTIAL' || data.docSecuType === 'CONFIDENTIAL_STRICT';
 
-      console.log(submitRequest);
+      debugLog('Submit Request', submitRequest);
 
       const response = isSecure
         ? await submitSecurityApproval(submitRequest)
-        : await submitApproval(submitRequest);
+        : await submitApproval(submitRequest, {
+            userId: currentUserId,
+            epId: currentEpId,
+            emailAddress: currentEmail
+          });
+
+      debugLog('Submit Response', response);
 
       if (response.result === 'SUCCESS') {
         setSubmitResult({ apInfId: response.data.apInfId });
@@ -808,10 +833,10 @@ export default function ApprovalSubmit({ onSubmitSuccess }: ApprovalSubmitProps)
         onSubmitSuccess?.(response.data.apInfId);
         form.reset();
       } else {
-        toast.error('결재 상신에 실패했습니다.');
+        toast.error(`결재 상신에 실패했습니다: ${response.result}`);
       }
     } catch (error) {
-      console.error('결재 상신 오류:', error);
+      debugError('결재 상신 오류', error);
       toast.error('결재 상신 중 오류가 발생했습니다.');
     } finally {
       setIsSubmitting(false);
-- 
cgit v1.2.3

