From f95fbb0719c5754360472d066b0bbed4bda6a40a Mon Sep 17 00:00:00 2001
From: 0-Zz-ang <s1998319@gmail.com>
Date: Thu, 20 Nov 2025 17:39:10 +0900
Subject: (박서영)준법설문조사 redFlag관련사항수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../status-detail/basic-contracts-detail-table.tsx | 45 +++++++++++++++++++++-
 1 file changed, 43 insertions(+), 2 deletions(-)

(limited to 'lib/basic-contract/status-detail/basic-contracts-detail-table.tsx')

diff --git a/lib/basic-contract/status-detail/basic-contracts-detail-table.tsx b/lib/basic-contract/status-detail/basic-contracts-detail-table.tsx
index 0df46066..93853560 100644
--- a/lib/basic-contract/status-detail/basic-contracts-detail-table.tsx
+++ b/lib/basic-contract/status-detail/basic-contracts-detail-table.tsx
@@ -11,6 +11,7 @@ import type {
 import { getDetailColumns } from "./basic-contracts-detail-columns"
 import { getBasicContractsByTemplateId } from "@/lib/basic-contract/service"
 import { checkGTCCommentsForContracts } from "@/lib/basic-contract/actions/check-gtc-comments"
+import { checkRedFlagsForContracts } from "@/lib/basic-contract/actions/check-red-flags"
 import { BasicContractView } from "@/db/schema"
 import { BasicContractDetailTableToolbarActions } from "./basic-contract-detail-table-toolbar-actions"
 import { toast } from "sonner"
@@ -32,6 +33,10 @@ export function BasicContractsDetailTable({ templateId, promises }: BasicContrac
     // GTC data 상태 관리
     const [gtcData, setGtcData] = React.useState<Record<number, { gtcDocumentId: number | null; hasComments: boolean }>>({})
     const [isLoadingGtcData, setIsLoadingGtcData] = React.useState(false)
+    
+    // Red Flag data 상태 관리
+    const [redFlagData, setRedFlagData] = React.useState<Record<number, boolean>>({})
+    const [isLoadingRedFlagData, setIsLoadingRedFlagData] = React.useState(false)
 
     const [{ data, pageCount }] = React.use(promises)
     const router = useRouter()
@@ -66,14 +71,50 @@ export function BasicContractsDetailTable({ templateId, promises }: BasicContrac
         loadGtcData();
     }, [data]);
 
+    // Red Flag data 로딩
+    React.useEffect(() => {
+        const loadRedFlagData = async () => {
+            if (!data || data.length === 0) return;
+            
+            // 준법서약 템플릿이 있는지 확인
+            const hasComplianceTemplates = data.some(contract => 
+                contract.templateName?.includes('준법')
+            );
+            
+            if (!hasComplianceTemplates) return;
+            
+            setIsLoadingRedFlagData(true);
+            try {
+                const redFlagResults = await checkRedFlagsForContracts(data);
+                setRedFlagData(redFlagResults);
+            } catch (error) {
+                console.error('Error checking Red Flag data:', error);
+                toast.error("Red Flag 데이터를 불러오는데 실패했습니다.");
+            } finally {
+                setIsLoadingRedFlagData(false);
+            }
+        };
+
+        loadRedFlagData();
+    }, [data]);
+
+    // 준법서약 템플릿인지 확인
+    const isComplianceTemplate = React.useMemo(() => {
+        if (!data || data.length === 0) return false;
+        return data.some(contract => contract.templateName?.includes('준법'));
+    }, [data]);
+
     const columns = React.useMemo(
         () => getDetailColumns({ 
             setRowAction, 
             gtcData, 
-            isLoadingGtcData ,
+            isLoadingGtcData,
+            redFlagData,
+            isLoadingRedFlagData,
+            isComplianceTemplate,
             router
         }),
-        [setRowAction, gtcData, isLoadingGtcData, router]
+        [setRowAction, gtcData, isLoadingGtcData, redFlagData, isLoadingRedFlagData, isComplianceTemplate, router]
     )
 
     const advancedFilterFields: DataTableAdvancedFilterField<BasicContractView>[] = [
-- 
cgit v1.2.3

