import React, { useState, useEffect } from 'react'; import { api } from '../api'; const ProjectWorkspacePage = ({ project, user, onNavigate, onBackToDashboard }) => { const [projectStats, setProjectStats] = useState(null); const [recentFiles, setRecentFiles] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { if (project) { loadProjectData(); } }, [project]); const loadProjectData = async () => { try { // 실제 파일 데이터만 로드 const filesResponse = await api.get(`/files?job_no=${project.job_no}&limit=5`); if (filesResponse.data && Array.isArray(filesResponse.data)) { setRecentFiles(filesResponse.data); // 파일 데이터를 기반으로 통계 계산 const stats = { totalFiles: filesResponse.data.length, totalMaterials: filesResponse.data.reduce((sum, file) => sum + (file.parsed_count || 0), 0), classifiedMaterials: 0, // API에서 분류 정보를 가져와야 함 pendingVerification: 0, // API에서 검증 정보를 가져와야 함 }; setProjectStats(stats); } else { setRecentFiles([]); setProjectStats({ totalFiles: 0, totalMaterials: 0, classifiedMaterials: 0, pendingVerification: 0 }); } } catch (error) { console.error('프로젝트 데이터 로딩 실패:', error); setRecentFiles([]); setProjectStats({ totalFiles: 0, totalMaterials: 0, classifiedMaterials: 0, pendingVerification: 0 }); } finally { setLoading(false); } }; const getAvailableActions = () => { const userRole = user?.role || 'user'; const allActions = { // BOM 관리 (통합) 'bom-management': { title: 'BOM 관리', description: 'BOM 파일 업로드, 관리 및 리비전 추적을 수행합니다', icon: '📋', color: '#667eea', roles: ['designer', 'manager', 'admin'], path: 'bom-status' }, // 자재 관리 'material-management': { title: '자재 관리', description: '자재 분류, 검증 및 구매 관리를 수행합니다', icon: '🔧', color: '#48bb78', roles: ['designer', 'purchaser', 'manager', 'admin'], path: 'materials' } }; // 사용자 권한에 따라 필터링 return Object.entries(allActions).filter(([key, action]) => action.roles.includes(userRole) ); }; const handleActionClick = (actionPath) => { switch (actionPath) { case 'bom-management': onNavigate('bom-status', { job_no: project.job_no, job_name: project.project_name }); break; case 'material-management': onNavigate('materials', { job_no: project.job_no, job_name: project.project_name }); break; default: alert(`${actionPath} 기능은 곧 구현될 예정입니다.`); } }; if (loading) { return (
{action.description}