From d66d308169e559457878c02e3b0443da22693241 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 1 Jul 2025 02:53:18 +0000 Subject: (최겸) 정보시스템 인포메이션 기능 개발 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/information/information-button.tsx | 259 ++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 components/information/information-button.tsx (limited to 'components/information/information-button.tsx') diff --git a/components/information/information-button.tsx b/components/information/information-button.tsx new file mode 100644 index 00000000..da0de548 --- /dev/null +++ b/components/information/information-button.tsx @@ -0,0 +1,259 @@ +"use client" + +import React, { useState, useEffect } from "react" +import { Info, Download, Edit } from "lucide-react" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { getCachedPageInformation, getCachedEditPermission } from "@/lib/information/service" +import { UpdateInformationDialog } from "@/lib/information/table/update-information-dialog" +import type { PageInformation } from "@/db/schema/information" +import { useSession } from "next-auth/react" + +interface InformationButtonProps { + pageCode: string + className?: string + variant?: "default" | "outline" | "ghost" | "secondary" + size?: "default" | "sm" | "lg" | "icon" +} + +export function InformationButton({ + pageCode, + className, + variant = "ghost", + size = "icon" +}: InformationButtonProps) { + const { data: session } = useSession() + const [information, setInformation] = useState(null) + const [isLoading, setIsLoading] = useState(false) + const [isOpen, setIsOpen] = useState(false) + const [hasEditPermission, setHasEditPermission] = useState(false) + const [isEditDialogOpen, setIsEditDialogOpen] = useState(false) + + useEffect(() => { + if (isOpen && !information) { + loadInformation() + } + }, [isOpen, information]) + + // 편집 권한 확인 + useEffect(() => { + const checkEditPermission = async () => { + if (session?.user?.id) { + try { + const permission = await getCachedEditPermission(pageCode, session.user.id) + setHasEditPermission(permission) + } catch (error) { + console.error("Failed to check edit permission:", error) + setHasEditPermission(false) + } + } + } + + checkEditPermission() + }, [pageCode, session?.user?.id]) + + const loadInformation = async () => { + setIsLoading(true) + try { + const data = await getCachedPageInformation(pageCode) + setInformation(data) + } catch (error) { + console.error("Failed to load information:", error) + } finally { + setIsLoading(false) + } + } + + const handleDownload = () => { + if (information?.attachmentFilePath && information?.attachmentFileName) { + const link = document.createElement('a') + link.href = information.attachmentFilePath + link.download = information.attachmentFileName + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + } + } + + const handleEditClick = () => { + setIsEditDialogOpen(true) + } + + const handleEditClose = () => { + setIsEditDialogOpen(false) + refreshInformation() + } + + const refreshInformation = () => { + // 편집 후 정보 다시 로드 + setInformation(null) + if (isOpen) { + loadInformation() + } + // 캐시 무효화를 위해 다시 확인 + setTimeout(() => { + loadInformation() + }, 500) + } + + // 인포메이션이 없으면 버튼을 숨김 + const [hasInformation, setHasInformation] = useState(null) + + useEffect(() => { + const checkInformation = async () => { + try { + const data = await getCachedPageInformation(pageCode) + setHasInformation(!!data) + } catch { + setHasInformation(false) + } + } + checkInformation() + }, [pageCode]) + + // 인포메이션이 없으면 버튼을 숨김 + if (hasInformation === false) { + return null + } + + return ( + <> + + + + + + +
+
+ {/* */} +
+ {information?.title || "페이지 정보"} + {information?.pageName} +
+
+ {hasEditPermission && ( + + )} +
+
+ +
+ {isLoading ? ( +
+
+
+ ) : information ? ( + <> + {/* 공지사항 */} + {(information.noticeTitle || information.noticeContent) && ( +
+
+

공지사항

+
+
+ {information.noticeTitle && ( +
+ 제목: {information.noticeTitle} +
+ )} + {information.noticeContent && ( +
+
+ {information.noticeContent} +
+
+ )} +
+
+ )} + + {/* 페이지 정보 */} +
+

도움말

+
+
+ {information.description || "페이지 설명이 없습니다."} +
+
+
+ + {/* 첨부파일 */} +
+

첨부파일

+ {information.attachmentFileName ? ( +
+
+
+
+ {information.attachmentFileName} +
+ {information.attachmentFileSize && ( +
+ {information.attachmentFileSize} +
+ )} +
+ +
+
+ ) : ( +
+ +

첨부된 파일이 없습니다.

+
+ )} +
+ + ) : ( +
+ 이 페이지에 대한 정보가 없습니다. +
+ )} +
+
+
+ + {/* 편집 다이얼로그 */} + {information && ( + + )} + + ) +} \ No newline at end of file -- cgit v1.2.3