import { useState, useEffect, useRef } from 'react'; import { fetchUploadLogs } from '@tabs/assets/services/assetsApi'; import type { UploadLogItem } from '@tabs/assets/services/assetsApi'; const ASSET_CATEGORIES = ['전체', '방제선', '유회수기', '이송펌프', '방제차량', '살포장치', '오일붐', '흡착재', '기타']; const JURISDICTIONS = ['전체', '남해청', '서해청', '중부청', '동해청', '제주청']; const PERM_ITEMS = [ { icon: '👑', role: '시스템관리자', desc: '전체 자산 업로드/삭제 가능', bg: 'rgba(245,158,11,0.15)', color: 'text-yellow-400' }, { icon: '🔧', role: '운영관리자', desc: '관할청 내 자산 업로드 가능', bg: 'rgba(6,182,212,0.15)', color: 'text-primary-cyan' }, { icon: '👁', role: '조회자', desc: '현황 조회만 가능', bg: 'rgba(148,163,184,0.15)', color: 'text-text-2' }, { icon: '🚫', role: '게스트', desc: '접근 불가', bg: 'rgba(239,68,68,0.1)', color: 'text-red-400' }, ]; function formatDate(dtm: string) { const d = new Date(dtm); if (isNaN(d.getTime())) return dtm; return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; } function AssetUploadPanel() { const [assetCategory, setAssetCategory] = useState('전체'); const [jurisdiction, setJurisdiction] = useState('전체'); const [uploadMode, setUploadMode] = useState<'add' | 'replace'>('add'); const [uploaded, setUploaded] = useState(false); const [uploadHistory, setUploadHistory] = useState([]); const [dragging, setDragging] = useState(false); const [selectedFile, setSelectedFile] = useState(null); const fileInputRef = useRef(null); const resetTimerRef = useRef | null>(null); useEffect(() => { fetchUploadLogs(10) .then(setUploadHistory) .catch(err => console.error('[AssetUploadPanel] 이력 로드 실패:', err)); }, []); useEffect(() => { return () => { if (resetTimerRef.current) clearTimeout(resetTimerRef.current); }; }, []); const handleFileSelect = (file: File | null) => { if (!file) return; const ext = file.name.split('.').pop()?.toLowerCase(); if (ext !== 'xlsx' && ext !== 'csv') return; setSelectedFile(file); }; const handleDrop = (e: React.DragEvent) => { e.preventDefault(); setDragging(false); const file = e.dataTransfer.files[0] ?? null; handleFileSelect(file); }; const handleUpload = () => { if (!selectedFile) return; setUploaded(true); resetTimerRef.current = setTimeout(() => { setUploaded(false); setSelectedFile(null); }, 3000); }; return (
{/* 헤더 */}

자산 현행화

자산 데이터를 업로드하여 현행화합니다

{/* 본문 */}
{/* 좌측: 파일 업로드 */}

파일 업로드

{/* 드롭존 */}
{ e.preventDefault(); setDragging(true); }} onDragLeave={() => setDragging(false)} onDrop={handleDrop} onClick={() => fileInputRef.current?.click()} className={`rounded-lg border-2 border-dashed py-8 text-center cursor-pointer transition-colors ${ dragging ? 'border-primary-cyan bg-[rgba(6,182,212,0.05)]' : 'border-border hover:border-primary-cyan/50 bg-bg-2' }`} >
📁
{selectedFile ? (
{selectedFile.name}
) : ( <>
파일을 드래그하거나 클릭하여 업로드
엑셀(.xlsx), CSV 파일 지원 · 최대 10MB
)} handleFileSelect(e.target.files?.[0] ?? null)} />
{/* 자산 분류 */}
{/* 대상 관할 */}
{/* 업로드 방식 */}
{/* 업로드 버튼 */}
{/* 우측 */}
{/* 수정 권한 체계 */}

수정 권한 체계

{PERM_ITEMS.map(p => (
{p.icon}
{p.role}
{p.desc}
))}
{/* 최근 업로드 이력 */}

최근 업로드 이력

{uploadHistory.length === 0 ? (
이력이 없습니다.
) : uploadHistory.map(h => (
{h.fileNm}
{formatDate(h.regDtm)} · {h.uploaderNm} · {h.uploadCnt.toLocaleString()}건
완료
))}
); } export default AssetUploadPanel;