From 7dd2b9fc1856306652f311d19697d9880955bfab Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 22 Aug 2025 02:12:15 +0000 Subject: (최겸) 공지사항, 인포메이션 기능 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/information/information-button.tsx | 113 +++++++++++++++++--------- 1 file changed, 74 insertions(+), 39 deletions(-) (limited to 'components/information/information-button.tsx') diff --git a/components/information/information-button.tsx b/components/information/information-button.tsx index 52079767..17f10502 100644 --- a/components/information/information-button.tsx +++ b/components/information/information-button.tsx @@ -12,14 +12,15 @@ import { DialogTrigger, } from "@/components/ui/dialog" import { Info, Download, Edit, Loader2 } from "lucide-react" -import { getCachedPageInformation, getCachedEditPermission } from "@/lib/information/service" -import { getCachedPageNotices } from "@/lib/notice/service" +import { getPageInformationDirect, getEditPermissionDirect } from "@/lib/information/service" +import { getPageNotices } from "@/lib/notice/service" import { UpdateInformationDialog } from "@/lib/information/table/update-information-dialog" import { NoticeViewDialog } from "@/components/notice/notice-view-dialog" -import type { PageInformation } from "@/db/schema/information" +import type { PageInformation, InformationAttachment } from "@/db/schema/information" import type { Notice } from "@/db/schema/notice" import { useSession } from "next-auth/react" import { formatDate } from "@/lib/utils" +// downloadFile은 동적으로 import interface InformationButtonProps { pagePath: string @@ -41,7 +42,7 @@ export function InformationButton({ }: InformationButtonProps) { const { data: session } = useSession() const [isOpen, setIsOpen] = useState(false) - const [information, setInformation] = useState(null) + const [information, setInformation] = useState<(PageInformation & { attachments: InformationAttachment[] }) | null>(null) const [notices, setNotices] = useState([]) const [hasEditPermission, setHasEditPermission] = useState(false) const [isEditDialogOpen, setIsEditDialogOpen] = useState(false) @@ -59,19 +60,35 @@ export function InformationButton({ // pagePath 정규화 (앞의 / 제거) const normalizedPath = pagePath.startsWith('/') ? pagePath.slice(1) : pagePath + console.log('🔍 Information Button - 데이터 로딩:', { + originalPath: pagePath, + normalizedPath: normalizedPath, + sessionUserId: session?.user?.id + }) + // 병렬로 데이터 조회 const [infoResult, noticesResult] = await Promise.all([ - getCachedPageInformation(normalizedPath), - getCachedPageNotices(normalizedPath) + getPageInformationDirect(normalizedPath), + getPageNotices(normalizedPath) ]) + console.log('📊 조회 결과:', { + infoResult: infoResult ? { + id: infoResult.id, + pagePath: infoResult.pagePath, + pageName: infoResult.pageName, + attachmentsCount: infoResult.attachments?.length || 0 + } : null, + noticesCount: noticesResult.length + }) + setInformation(infoResult) setNotices(noticesResult) setDataLoaded(true) // 권한 확인 if (session?.user?.id) { - const hasPermission = await getCachedEditPermission(normalizedPath, session.user.id) + const hasPermission = await getEditPermissionDirect(normalizedPath, session.user.id) setHasEditPermission(hasPermission) } } catch (error) { @@ -109,16 +126,22 @@ export function InformationButton({ } // 파일 다운로드 핸들러 - const handleDownload = () => { - if (information?.attachmentFilePath) { - // window.open 대신 link 요소 사용 - const link = document.createElement('a') - link.href = information.attachmentFilePath - link.target = '_blank' - link.rel = 'noopener noreferrer' - document.body.appendChild(link) - link.click() - document.body.removeChild(link) + const handleDownload = async (attachment: InformationAttachment) => { + try { + // 동적으로 downloadFile 함수 import + const { downloadFile } = await import('@/lib/file-download') + + await downloadFile( + attachment.filePath, + attachment.fileName, + { + action: 'download', + showToast: true, + showSuccessToast: true + } + ) + } catch (error) { + console.error('파일 다운로드 실패:', error) } } @@ -145,7 +168,7 @@ export function InformationButton({
- {information?.pageName} +
@@ -231,29 +254,41 @@ export function InformationButton({ {/* 첨부파일 */}
-

첨부파일

+
+

첨부파일

+ {information?.attachments && information.attachments.length > 0 && ( + {information.attachments.length}개 + )} +
- {information?.attachmentFileName ? ( -
-
-
- {information.attachmentFileName} -
- {information.attachmentFileSize && ( -
- {information.attachmentFileSize} + {information?.attachments && information.attachments.length > 0 ? ( +
+ {information.attachments.map((attachment) => ( +
+
+
+ {attachment.fileName} +
+ {attachment.fileSize && ( +
+ {attachment.fileSize} +
+ )}
- )} -
- + +
+ ))}
) : (
-- cgit v1.2.3