2026-02-05 13:45:23 +09:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import React, { useState, useRef } from "react";
|
|
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import { FileInfo, FileUploadConfig } from "./types";
|
|
|
|
|
import {
|
|
|
|
|
Upload,
|
|
|
|
|
Download,
|
|
|
|
|
Trash2,
|
|
|
|
|
Eye,
|
|
|
|
|
File,
|
|
|
|
|
FileText,
|
|
|
|
|
Image as ImageIcon,
|
|
|
|
|
Video,
|
|
|
|
|
Music,
|
|
|
|
|
Archive,
|
|
|
|
|
Presentation,
|
|
|
|
|
X,
|
2026-02-05 14:07:15 +09:00
|
|
|
Star,
|
|
|
|
|
ZoomIn,
|
|
|
|
|
ZoomOut,
|
|
|
|
|
RotateCcw,
|
2026-02-05 13:45:23 +09:00
|
|
|
} from "lucide-react";
|
|
|
|
|
import { formatFileSize } from "@/lib/utils";
|
|
|
|
|
import { FileViewerModal } from "./FileViewerModal";
|
|
|
|
|
|
|
|
|
|
interface FileManagerModalProps {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
uploadedFiles: FileInfo[];
|
|
|
|
|
onFileUpload: (files: File[]) => Promise<void>;
|
|
|
|
|
onFileDownload: (file: FileInfo) => void;
|
|
|
|
|
onFileDelete: (file: FileInfo) => void;
|
|
|
|
|
onFileView: (file: FileInfo) => void;
|
|
|
|
|
onSetRepresentative?: (file: FileInfo) => void; // 대표 이미지 설정 콜백
|
|
|
|
|
config: FileUploadConfig;
|
|
|
|
|
isDesignMode?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FileManagerModal: React.FC<FileManagerModalProps> = ({
|
|
|
|
|
isOpen,
|
|
|
|
|
onClose,
|
|
|
|
|
uploadedFiles,
|
|
|
|
|
onFileUpload,
|
|
|
|
|
onFileDownload,
|
|
|
|
|
onFileDelete,
|
|
|
|
|
onFileView,
|
|
|
|
|
onSetRepresentative,
|
|
|
|
|
config,
|
|
|
|
|
isDesignMode = false,
|
|
|
|
|
}) => {
|
|
|
|
|
const [dragOver, setDragOver] = useState(false);
|
|
|
|
|
const [uploading, setUploading] = useState(false);
|
|
|
|
|
const [viewerFile, setViewerFile] = useState<FileInfo | null>(null);
|
|
|
|
|
const [isViewerOpen, setIsViewerOpen] = useState(false);
|
|
|
|
|
const [selectedFile, setSelectedFile] = useState<FileInfo | null>(null); // 선택된 파일 (좌측 미리보기용)
|
|
|
|
|
const [previewImageUrl, setPreviewImageUrl] = useState<string | null>(null); // 이미지 미리보기 URL
|
2026-02-05 14:07:15 +09:00
|
|
|
const [zoomLevel, setZoomLevel] = useState(1); // 🔍 확대/축소 레벨
|
|
|
|
|
const [imagePosition, setImagePosition] = useState({ x: 0, y: 0 }); // 🖱️ 이미지 위치
|
|
|
|
|
const [isDragging, setIsDragging] = useState(false); // 🖱️ 드래그 중 여부
|
|
|
|
|
const [dragStart, setDragStart] = useState({ x: 0, y: 0 }); // 🖱️ 드래그 시작 위치
|
2026-02-05 13:45:23 +09:00
|
|
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
2026-02-05 14:07:15 +09:00
|
|
|
const imageContainerRef = useRef<HTMLDivElement>(null);
|
2026-02-05 13:45:23 +09:00
|
|
|
|
|
|
|
|
// 파일 아이콘 가져오기
|
|
|
|
|
const getFileIcon = (fileExt: string) => {
|
|
|
|
|
const ext = fileExt.toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'].includes(ext)) {
|
|
|
|
|
return <ImageIcon className="w-5 h-5 text-blue-500" />;
|
|
|
|
|
} else if (['pdf', 'doc', 'docx', 'txt', 'rtf'].includes(ext)) {
|
|
|
|
|
return <FileText className="w-5 h-5 text-red-500" />;
|
|
|
|
|
} else if (['xls', 'xlsx', 'csv'].includes(ext)) {
|
|
|
|
|
return <FileText className="w-5 h-5 text-green-500" />;
|
|
|
|
|
} else if (['ppt', 'pptx'].includes(ext)) {
|
|
|
|
|
return <Presentation className="w-5 h-5 text-orange-500" />;
|
|
|
|
|
} else if (['mp4', 'avi', 'mov', 'webm'].includes(ext)) {
|
|
|
|
|
return <Video className="w-5 h-5 text-purple-500" />;
|
|
|
|
|
} else if (['mp3', 'wav', 'ogg'].includes(ext)) {
|
|
|
|
|
return <Music className="w-5 h-5 text-pink-500" />;
|
|
|
|
|
} else if (['zip', 'rar', '7z'].includes(ext)) {
|
|
|
|
|
return <Archive className="w-5 h-5 text-yellow-500" />;
|
|
|
|
|
} else {
|
|
|
|
|
return <File className="w-5 h-5 text-gray-500" />;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 파일 업로드 핸들러
|
|
|
|
|
const handleFileUpload = async (files: FileList | File[]) => {
|
|
|
|
|
if (!files || files.length === 0) return;
|
|
|
|
|
|
|
|
|
|
setUploading(true);
|
|
|
|
|
try {
|
|
|
|
|
const fileArray = Array.from(files);
|
|
|
|
|
await onFileUpload(fileArray);
|
|
|
|
|
console.log('✅ FileManagerModal: 파일 업로드 완료');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('❌ FileManagerModal: 파일 업로드 오류:', error);
|
|
|
|
|
} finally {
|
|
|
|
|
setUploading(false);
|
|
|
|
|
console.log('🔄 FileManagerModal: 업로드 상태 초기화');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 드래그 앤 드롭 핸들러
|
|
|
|
|
const handleDragOver = (e: React.DragEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setDragOver(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDragLeave = (e: React.DragEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setDragOver(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDrop = (e: React.DragEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setDragOver(false);
|
|
|
|
|
|
|
|
|
|
if (config.disabled || isDesignMode) return;
|
|
|
|
|
|
|
|
|
|
const files = e.dataTransfer.files;
|
|
|
|
|
handleFileUpload(files);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 파일 선택 핸들러
|
|
|
|
|
const handleFileSelect = () => {
|
|
|
|
|
if (config.disabled || isDesignMode) return;
|
|
|
|
|
fileInputRef.current?.click();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleFileInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const files = e.target.files;
|
|
|
|
|
if (files) {
|
|
|
|
|
handleFileUpload(files);
|
|
|
|
|
}
|
|
|
|
|
// 입력값 초기화
|
|
|
|
|
e.target.value = '';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 파일 뷰어 핸들러
|
|
|
|
|
const handleFileViewInternal = (file: FileInfo) => {
|
|
|
|
|
setViewerFile(file);
|
|
|
|
|
setIsViewerOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleViewerClose = () => {
|
|
|
|
|
setIsViewerOpen(false);
|
|
|
|
|
setViewerFile(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 파일 클릭 시 미리보기 로드
|
|
|
|
|
const handleFileClick = async (file: FileInfo) => {
|
|
|
|
|
setSelectedFile(file);
|
2026-02-05 14:07:15 +09:00
|
|
|
setZoomLevel(1); // 🔍 파일 선택 시 확대/축소 레벨 초기화
|
|
|
|
|
setImagePosition({ x: 0, y: 0 }); // 🖱️ 이미지 위치 초기화
|
2026-02-05 13:45:23 +09:00
|
|
|
|
|
|
|
|
// 이미지 파일인 경우 미리보기 로드
|
|
|
|
|
// 🔑 점(.)을 제거하고 확장자만 비교
|
|
|
|
|
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'];
|
|
|
|
|
const ext = file.fileExt.toLowerCase().replace('.', '');
|
|
|
|
|
if (imageExtensions.includes(ext) || file.isImage) {
|
|
|
|
|
try {
|
|
|
|
|
// 이전 Blob URL 해제
|
|
|
|
|
if (previewImageUrl) {
|
|
|
|
|
URL.revokeObjectURL(previewImageUrl);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-06 16:23:38 +09:00
|
|
|
// 🔑 항상 apiClient를 통해 Blob 다운로드 (Docker 환경에서 상대 경로 문제 방지)
|
2026-02-05 13:45:23 +09:00
|
|
|
const { apiClient } = await import("@/lib/api/client");
|
|
|
|
|
const response = await apiClient.get(`/files/preview/${file.objid}`, {
|
|
|
|
|
responseType: 'blob'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const blob = new Blob([response.data]);
|
|
|
|
|
const blobUrl = URL.createObjectURL(blob);
|
|
|
|
|
setPreviewImageUrl(blobUrl);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("이미지 로드 실패:", error);
|
2026-02-06 16:23:38 +09:00
|
|
|
setPreviewImageUrl(null);
|
2026-02-05 13:45:23 +09:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setPreviewImageUrl(null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 컴포넌트 언마운트 시 Blob URL 해제
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
return () => {
|
|
|
|
|
if (previewImageUrl) {
|
|
|
|
|
URL.revokeObjectURL(previewImageUrl);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}, [previewImageUrl]);
|
|
|
|
|
|
2026-02-05 14:07:15 +09:00
|
|
|
// 🔑 모달이 열릴 때 첫 번째 파일을 자동으로 선택하고 확대/축소 레벨 초기화
|
2026-02-05 13:45:23 +09:00
|
|
|
React.useEffect(() => {
|
2026-02-05 14:07:15 +09:00
|
|
|
if (isOpen) {
|
|
|
|
|
setZoomLevel(1); // 🔍 모달 열릴 때 확대/축소 레벨 초기화
|
|
|
|
|
setImagePosition({ x: 0, y: 0 }); // 🖱️ 이미지 위치 초기화
|
|
|
|
|
if (uploadedFiles.length > 0 && !selectedFile) {
|
|
|
|
|
const firstFile = uploadedFiles[0];
|
|
|
|
|
handleFileClick(firstFile);
|
|
|
|
|
}
|
2026-02-05 13:45:23 +09:00
|
|
|
}
|
|
|
|
|
}, [isOpen, uploadedFiles, selectedFile]);
|
|
|
|
|
|
2026-02-05 14:07:15 +09:00
|
|
|
// 🖱️ 마우스 드래그 핸들러
|
|
|
|
|
const handleMouseDown = (e: React.MouseEvent) => {
|
|
|
|
|
if (zoomLevel > 1) {
|
|
|
|
|
setIsDragging(true);
|
|
|
|
|
setDragStart({ x: e.clientX - imagePosition.x, y: e.clientY - imagePosition.y });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleMouseMove = (e: React.MouseEvent) => {
|
|
|
|
|
if (isDragging && zoomLevel > 1) {
|
|
|
|
|
setImagePosition({
|
|
|
|
|
x: e.clientX - dragStart.x,
|
|
|
|
|
y: e.clientY - dragStart.y,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleMouseUp = () => {
|
|
|
|
|
setIsDragging(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 🔍 확대/축소 레벨이 1로 돌아가면 위치도 초기화
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (zoomLevel <= 1) {
|
|
|
|
|
setImagePosition({ x: 0, y: 0 });
|
|
|
|
|
}
|
|
|
|
|
}, [zoomLevel]);
|
|
|
|
|
|
2026-02-05 13:45:23 +09:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Dialog open={isOpen} onOpenChange={() => {}}>
|
2026-02-05 14:07:15 +09:00
|
|
|
<DialogContent className="max-w-[95vw] w-[1400px] max-h-[90vh] overflow-hidden [&>button]:hidden">
|
2026-02-05 13:45:23 +09:00
|
|
|
<DialogHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
|
|
|
<DialogTitle className="text-lg font-semibold">
|
|
|
|
|
파일 관리 ({uploadedFiles.length}개)
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-8 w-8 p-0 hover:bg-gray-100"
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
title="닫기"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-4 h-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col space-y-3 h-[75vh]">
|
|
|
|
|
{/* 파일 업로드 영역 - 높이 축소 */}
|
|
|
|
|
{!isDesignMode && (
|
|
|
|
|
<div
|
|
|
|
|
className={`
|
|
|
|
|
border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors
|
|
|
|
|
${dragOver ? 'border-blue-400 bg-blue-50' : 'border-gray-300'}
|
|
|
|
|
${config.disabled ? 'opacity-50 cursor-not-allowed' : 'hover:border-gray-400'}
|
|
|
|
|
${uploading ? 'opacity-75' : ''}
|
|
|
|
|
`}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!config.disabled && !isDesignMode) {
|
|
|
|
|
fileInputRef.current?.click();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onDragOver={handleDragOver}
|
|
|
|
|
onDragLeave={handleDragLeave}
|
|
|
|
|
onDrop={handleDrop}
|
|
|
|
|
>
|
|
|
|
|
<input
|
|
|
|
|
ref={fileInputRef}
|
|
|
|
|
type="file"
|
|
|
|
|
multiple={config.multiple}
|
|
|
|
|
accept={config.accept}
|
|
|
|
|
onChange={handleFileInputChange}
|
|
|
|
|
className="hidden"
|
|
|
|
|
disabled={config.disabled}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{uploading ? (
|
|
|
|
|
<div className="flex items-center justify-center gap-2">
|
|
|
|
|
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-blue-600"></div>
|
|
|
|
|
<span className="text-sm text-blue-600 font-medium">업로드 중...</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex items-center justify-center gap-3">
|
|
|
|
|
<Upload className="h-6 w-6 text-gray-400" />
|
|
|
|
|
<p className="text-sm font-medium text-gray-700">
|
|
|
|
|
파일을 드래그하거나 클릭하여 업로드하세요
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-02-05 14:07:15 +09:00
|
|
|
{/* 좌우 분할 레이아웃 - 좌측 넓게, 우측 고정 너비 */}
|
2026-02-05 13:45:23 +09:00
|
|
|
<div className="flex-1 flex gap-4 min-h-0">
|
2026-02-05 14:07:15 +09:00
|
|
|
{/* 좌측: 이미지 미리보기 (확대/축소 가능) */}
|
|
|
|
|
<div className="flex-1 border border-gray-200 rounded-lg bg-gray-900 flex flex-col overflow-hidden relative">
|
|
|
|
|
{/* 확대/축소 컨트롤 */}
|
|
|
|
|
{selectedFile && previewImageUrl && (
|
|
|
|
|
<div className="absolute top-3 left-3 z-10 flex items-center gap-1 bg-black/60 rounded-lg p-1">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-8 w-8 text-white hover:bg-white/20"
|
|
|
|
|
onClick={() => setZoomLevel(prev => Math.max(0.25, prev - 0.25))}
|
|
|
|
|
disabled={zoomLevel <= 0.25}
|
|
|
|
|
>
|
|
|
|
|
<ZoomOut className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<span className="text-white text-xs min-w-[50px] text-center">
|
|
|
|
|
{Math.round(zoomLevel * 100)}%
|
|
|
|
|
</span>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-8 w-8 text-white hover:bg-white/20"
|
|
|
|
|
onClick={() => setZoomLevel(prev => Math.min(4, prev + 0.25))}
|
|
|
|
|
disabled={zoomLevel >= 4}
|
|
|
|
|
>
|
|
|
|
|
<ZoomIn className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-8 w-8 text-white hover:bg-white/20"
|
|
|
|
|
onClick={() => setZoomLevel(1)}
|
|
|
|
|
>
|
|
|
|
|
<RotateCcw className="h-4 w-4" />
|
|
|
|
|
</Button>
|
2026-02-05 13:45:23 +09:00
|
|
|
</div>
|
2026-02-05 14:07:15 +09:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* 이미지 미리보기 영역 - 마우스 휠로 확대/축소, 드래그로 이동 */}
|
|
|
|
|
<div
|
|
|
|
|
ref={imageContainerRef}
|
|
|
|
|
className={`flex-1 flex items-center justify-center overflow-hidden p-4 ${
|
|
|
|
|
zoomLevel > 1 ? (isDragging ? 'cursor-grabbing' : 'cursor-grab') : 'cursor-zoom-in'
|
|
|
|
|
}`}
|
|
|
|
|
onWheel={(e) => {
|
|
|
|
|
if (selectedFile && previewImageUrl) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const delta = e.deltaY > 0 ? -0.1 : 0.1;
|
|
|
|
|
setZoomLevel(prev => Math.min(4, Math.max(0.25, prev + delta)));
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
onMouseDown={handleMouseDown}
|
|
|
|
|
onMouseMove={handleMouseMove}
|
|
|
|
|
onMouseUp={handleMouseUp}
|
|
|
|
|
onMouseLeave={handleMouseUp}
|
|
|
|
|
>
|
|
|
|
|
{selectedFile && previewImageUrl ? (
|
|
|
|
|
<img
|
|
|
|
|
src={previewImageUrl}
|
|
|
|
|
alt={selectedFile.realFileName}
|
|
|
|
|
className="transition-transform duration-100 select-none"
|
|
|
|
|
style={{
|
|
|
|
|
transform: `translate(${imagePosition.x}px, ${imagePosition.y}px) scale(${zoomLevel})`,
|
|
|
|
|
transformOrigin: 'center center',
|
|
|
|
|
}}
|
|
|
|
|
draggable={false}
|
|
|
|
|
/>
|
|
|
|
|
) : selectedFile ? (
|
|
|
|
|
<div className="flex flex-col items-center text-gray-400">
|
|
|
|
|
{getFileIcon(selectedFile.fileExt)}
|
|
|
|
|
<p className="mt-2 text-sm">미리보기 불가능</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-col items-center text-gray-400">
|
|
|
|
|
<ImageIcon className="w-16 h-16 mb-2" />
|
|
|
|
|
<p className="text-sm">파일을 선택하면 미리보기가 표시됩니다</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 파일 정보 바 */}
|
|
|
|
|
{selectedFile && (
|
|
|
|
|
<div className="bg-black/60 text-white text-xs px-3 py-2 text-center truncate">
|
|
|
|
|
{selectedFile.realFileName}
|
2026-02-05 13:45:23 +09:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-05 14:07:15 +09:00
|
|
|
{/* 우측: 파일 목록 (고정 너비) */}
|
|
|
|
|
<div className="w-[400px] shrink-0 border border-gray-200 rounded-lg overflow-hidden flex flex-col">
|
2026-02-05 13:45:23 +09:00
|
|
|
<div className="p-3 border-b border-gray-200 bg-gray-50">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<h3 className="text-sm font-medium text-gray-700">
|
|
|
|
|
업로드된 파일
|
|
|
|
|
</h3>
|
|
|
|
|
{uploadedFiles.length > 0 && (
|
|
|
|
|
<Badge variant="secondary" className="text-xs">
|
|
|
|
|
총 {formatFileSize(uploadedFiles.reduce((sum, file) => sum + file.fileSize, 0))}
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex-1 overflow-y-auto p-3">
|
|
|
|
|
{uploadedFiles.length > 0 ? (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
{uploadedFiles.map((file) => (
|
|
|
|
|
<div
|
|
|
|
|
key={file.objid}
|
|
|
|
|
className={`
|
|
|
|
|
flex items-center space-x-3 p-2 rounded-lg transition-colors cursor-pointer
|
|
|
|
|
${selectedFile?.objid === file.objid ? 'bg-blue-50 border border-blue-200' : 'bg-gray-50 hover:bg-gray-100'}
|
|
|
|
|
`}
|
|
|
|
|
onClick={() => handleFileClick(file)}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex-shrink-0">
|
|
|
|
|
{getFileIcon(file.fileExt)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-sm font-medium text-gray-900 truncate">
|
|
|
|
|
{file.realFileName}
|
|
|
|
|
</span>
|
|
|
|
|
{file.isRepresentative && (
|
|
|
|
|
<Badge variant="default" className="h-5 px-1.5 text-xs">
|
|
|
|
|
대표
|
|
|
|
|
</Badge>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-xs text-gray-500">
|
|
|
|
|
{formatFileSize(file.fileSize)} • {file.fileExt.toUpperCase()}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center space-x-1">
|
|
|
|
|
{onSetRepresentative && (
|
|
|
|
|
<Button
|
|
|
|
|
variant={file.isRepresentative ? "default" : "ghost"}
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-7 w-7 p-0"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onSetRepresentative(file);
|
|
|
|
|
}}
|
|
|
|
|
title={file.isRepresentative ? "현재 대표 파일" : "대표 파일로 설정"}
|
|
|
|
|
>
|
|
|
|
|
<Star className={`w-3 h-3 ${file.isRepresentative ? "fill-white" : ""}`} />
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-7 w-7 p-0"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
handleFileViewInternal(file);
|
|
|
|
|
}}
|
|
|
|
|
title="미리보기"
|
|
|
|
|
>
|
|
|
|
|
<Eye className="w-3 h-3" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-7 w-7 p-0"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onFileDownload(file);
|
|
|
|
|
}}
|
|
|
|
|
title="다운로드"
|
|
|
|
|
>
|
|
|
|
|
<Download className="w-3 h-3" />
|
|
|
|
|
</Button>
|
|
|
|
|
{!isDesignMode && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-7 w-7 p-0 text-red-500 hover:text-red-700"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onFileDelete(file);
|
|
|
|
|
}}
|
|
|
|
|
title="삭제"
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="w-3 h-3" />
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-col items-center justify-center py-8 text-gray-500">
|
|
|
|
|
<File className="w-12 h-12 mb-3 text-gray-300" />
|
|
|
|
|
<p className="text-sm font-medium text-gray-600">업로드된 파일이 없습니다</p>
|
|
|
|
|
<p className="text-xs text-gray-500 mt-1">
|
|
|
|
|
{isDesignMode ? '디자인 모드에서는 파일을 업로드할 수 없습니다' : '위의 영역에 파일을 업로드하세요'}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
|
|
{/* 파일 뷰어 모달 */}
|
|
|
|
|
<FileViewerModal
|
|
|
|
|
file={viewerFile}
|
|
|
|
|
isOpen={isViewerOpen}
|
|
|
|
|
onClose={handleViewerClose}
|
|
|
|
|
onDownload={onFileDownload}
|
|
|
|
|
onDelete={!isDesignMode ? onFileDelete : undefined}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|