From a9431a63382576d60329c378a37a6215d1f5b7d5 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 22 Aug 2025 06:21:31 +0000 Subject: (최겸) 인포메이션 수정, 문서관리 인포메이션 버튼 추가 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/information/information-button.tsx | 96 +++++++++++++++++---------- 1 file changed, 61 insertions(+), 35 deletions(-) (limited to 'components/information') diff --git a/components/information/information-button.tsx b/components/information/information-button.tsx index 17f10502..69cbb106 100644 --- a/components/information/information-button.tsx +++ b/components/information/information-button.tsx @@ -50,61 +50,87 @@ export function InformationButton({ const [isNoticeViewDialogOpen, setIsNoticeViewDialogOpen] = useState(false) const [dataLoaded, setDataLoaded] = useState(false) const [isLoading, setIsLoading] = useState(false) + const [retryCount, setRetryCount] = useState(0) - // 데이터 로드 함수 (단순화) + // 데이터 로드 함수 const loadData = React.useCallback(async () => { - if (dataLoaded) return // 이미 로드되었으면 중복 방지 + if (dataLoaded) return setIsLoading(true) try { - // pagePath 정규화 (앞의 / 제거) - const normalizedPath = pagePath.startsWith('/') ? pagePath.slice(1) : pagePath - - console.log('🔍 Information Button - 데이터 로딩:', { - originalPath: pagePath, - normalizedPath: normalizedPath, - sessionUserId: session?.user?.id - }) + // 경로 정규화 - 더 안전한 방식 + let normalizedPath = pagePath + if (normalizedPath.startsWith('/')) { + normalizedPath = normalizedPath.slice(1) + } + // 빈 문자열이면 기본값 설정 + if (!normalizedPath) { + normalizedPath = 'home' + } - // 병렬로 데이터 조회 - const [infoResult, noticesResult] = await Promise.all([ - getPageInformationDirect(normalizedPath), - getPageNotices(normalizedPath) - ]) + // 약간의 지연 추가 (프로덕션에서 DB 연결 안정성) + if (retryCount > 0) { + await new Promise(resolve => setTimeout(resolve, 500 * retryCount)) + } - console.log('📊 조회 결과:', { - infoResult: infoResult ? { - id: infoResult.id, - pagePath: infoResult.pagePath, - pageName: infoResult.pageName, - attachmentsCount: infoResult.attachments?.length || 0 - } : null, - noticesCount: noticesResult.length - }) + // 순차적으로 데이터 조회 (프로덕션 안정성) + const infoResult = await getPageInformationDirect(normalizedPath) + const noticesResult = await getPageNotices(normalizedPath) setInformation(infoResult) setNotices(noticesResult) setDataLoaded(true) + setRetryCount(0) // 성공시 재시도 횟수 리셋 - // 권한 확인 - if (session?.user?.id) { - const hasPermission = await getEditPermissionDirect(normalizedPath, session.user.id) - setHasEditPermission(hasPermission) + // 권한 확인 - 세션이 확실히 있을 때만 + if (session?.user?.id && infoResult) { + try { + const hasPermission = await getEditPermissionDirect(normalizedPath, session.user.id) + setHasEditPermission(hasPermission) + } catch (permError) { + setHasEditPermission(false) + } } } catch (error) { - console.error("데이터 로딩 중 오류:", error) + // 재시도 로직 + if (retryCount < 2) { + setRetryCount(prev => prev + 1) + setIsLoading(false) + return + } + + // 최대 재시도 후 기본값 설정 + setInformation(null) + setNotices([]) + setHasEditPermission(false) + setDataLoaded(true) + setRetryCount(0) } finally { setIsLoading(false) } - }, [pagePath, session?.user?.id, dataLoaded]) + }, [pagePath, session?.user?.id, dataLoaded, retryCount]) + + // 세션이 준비되면 자동으로 데이터 로드 + React.useEffect(() => { + if (isOpen && !dataLoaded && session !== undefined) { + loadData() + } + }, [isOpen, dataLoaded, session]) + + // 재시도 처리 + React.useEffect(() => { + if (retryCount > 0 && retryCount <= 2) { + const timer = setTimeout(() => { + setDataLoaded(false) // 재시도를 위해 리셋 + }, 500 * retryCount) + return () => clearTimeout(timer) + } + }, [retryCount]) // 다이얼로그 열기 const handleDialogOpen = (open: boolean) => { setIsOpen(open) - - if (open && !dataLoaded) { - loadData() - } + // useEffect에서 데이터 로딩 처리하므로 여기서는 제거 } // 편집 관련 핸들러 @@ -116,7 +142,7 @@ export function InformationButton({ setIsEditDialogOpen(false) // 편집 후 데이터 다시 로드 setDataLoaded(false) - loadData() + setRetryCount(0) } // 공지사항 클릭 핸들러 -- cgit v1.2.3