import React, { useState, useEffect } from 'react'; import { Card, Button, Progress, Tag, List, Spin, message, Empty, Space, Typography } from 'antd'; import { ArrowLeftOutlined, RightOutlined } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; import apiClient from '../../utils/request'; import { useLanguageStore } from '../../store/languageStore'; const { Title, Text } = Typography; interface ProjectPhase { id: number; phase_name: string; phase_order: number; phase_type: string; status: string; } interface Project { id: number; name: string; status: string; current_phase: string; phase_progress: number; contract_amount: number; phases: ProjectPhase[]; } const ConstructionOverview: React.FC = () => { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(false); const navigate = useNavigate(); const { t, currentLanguage } = useLanguageStore(); useEffect(() => { fetchProjects(); }, []); const fetchProjects = async () => { setLoading(true); try { const res = await apiClient.get('/construction/my-projects'); if (res.data.success) { const projectsData = res.data.data || []; const enriched = await Promise.all(projectsData.map(async (p: Project) => { try { const phaseRes = await apiClient.get(`/projects/${p.id}/phases`); return { ...p, phases: phaseRes.data.data || [] }; } catch { return { ...p, phases: [] }; } })); setProjects(enriched); } } catch (e) { message.error(t('construction.getListFailed')); } finally { setLoading(false); } }; const getStatusColor = (status: string) => { const map: Record = { active: 'green', in_progress: 'processing', planning: 'blue', completed: 'default', suspended: 'orange' }; return map[status] || 'default'; }; const getStatusText = (status: string) => { const map: Record = { active: t('construction.underConstruction'), in_progress: t('construction.underConstruction'), planning: t('construction.pendingStart'), completed: t('construction.completed'), suspended: t('construction.paused') }; return map[status] || status; }; const activeProjects = projects.filter(p => p.status !== 'completed'); const completedProjects = projects.filter(p => p.status === 'completed'); return (
{t('construction.overview')}}> {activeProjects.length === 0 && completedProjects.length === 0 ? ( ) : ( <> {activeProjects.length > 0 && ( <> {t('construction.underConstruction')}{activeProjects.length}{t('common.unit')} ( } onClick={() => navigate(`/construction/progress/${project.id}`)}>{t('construction.enter')}]} > {project.name}{getStatusText(project.status)}} description={
{t('construction.currentPhase')}{project.current_phase || t('common.notSet')} {project.phases.length > 0 && ({project.phases.filter(p => p.status === 'completed').length}/{project.phases.length})}
} />
)} /> )} {completedProjects.length > 0 && ( <> {t('construction.completedProjects')}{completedProjects.length}{t('common.unit')} ( } onClick={() => navigate(`/construction/progress/${project.id}`)}>{t('common.view')}]} > {project.name}{t('construction.completed')}} description={} /> )} /> )} )}
); }; export default ConstructionOverview;