diff options
Diffstat (limited to 'components/information')
| -rw-r--r-- | components/information/information-button.tsx | 113 |
1 files changed, 74 insertions, 39 deletions
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<PageInformation | null>(null)
+ const [information, setInformation] = useState<(PageInformation & { attachments: InformationAttachment[] }) | null>(null)
const [notices, setNotices] = useState<NoticeWithAuthor[]>([])
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({ <div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div>
- <DialogTitle>{information?.pageName}</DialogTitle>
+ <DialogTitle></DialogTitle>
</div>
</div>
</div>
@@ -231,29 +254,41 @@ export function InformationButton({ {/* 첨부파일 */}
<div className="space-y-3">
- <h4 className="font-semibold">첨부파일</h4>
+ <div className="flex items-center justify-between">
+ <h4 className="font-semibold">첨부파일</h4>
+ {information?.attachments && information.attachments.length > 0 && (
+ <span className="text-xs text-gray-500">{information.attachments.length}개</span>
+ )}
+ </div>
<div className="bg-gray-50 border rounded-lg p-4">
- {information?.attachmentFileName ? (
- <div className="flex items-center justify-between p-3 bg-white rounded border">
- <div className="flex-1">
- <div className="text-sm font-medium">
- {information.attachmentFileName}
- </div>
- {information.attachmentFileSize && (
- <div className="text-xs text-gray-500 mt-1">
- {information.attachmentFileSize}
+ {information?.attachments && information.attachments.length > 0 ? (
+ <div className="space-y-3">
+ {information.attachments.map((attachment) => (
+ <div
+ key={attachment.id}
+ className="flex items-center justify-between p-3 bg-white rounded border"
+ >
+ <div className="flex-1">
+ <div className="text-sm font-medium">
+ {attachment.fileName}
+ </div>
+ {attachment.fileSize && (
+ <div className="text-xs text-gray-500 mt-1">
+ {attachment.fileSize}
+ </div>
+ )}
</div>
- )}
- </div>
- <Button
- size="sm"
- variant="outline"
- onClick={handleDownload}
- className="flex items-center gap-1"
- >
- <Download className="h-3 w-3" />
- 다운로드
- </Button>
+ <Button
+ size="sm"
+ variant="outline"
+ onClick={() => handleDownload(attachment)}
+ className="flex items-center gap-1"
+ >
+ <Download className="h-3 w-3" />
+ 다운로드
+ </Button>
+ </div>
+ ))}
</div>
) : (
<div className="text-center text-gray-500">
|
