'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { StatusBadge, StatusDot } from '@/components/status-badge'; import { useUser } from '@/components/user-context'; import type { Project, User } from '@/types/database'; import { Plus, Users, Target, ArrowRight } from 'lucide-react'; interface ProjectWithRelations extends Project { owner: User | null; pm: User | null; } export default function ProjectsPage() { const { currentUser } = useUser(); const [projects, setProjects] = useState([]); const [isLoading, setIsLoading] = useState(true); useEffect(() => { async function fetchProjects() { try { const res = await fetch('/api/projects'); if (res.ok) { const data = await res.json(); setProjects(data); } } catch (error) { console.error('Failed to fetch projects:', error); } finally { setIsLoading(false); } } fetchProjects(); }, []); const canCreate = currentUser?.role === 'owner' || currentUser?.role === 'pm'; if (isLoading) { return (
{[1, 2, 3].map(i => (
))}
); } return (

项目列表

共 {projects.length} 个项目

{canCreate && ( )}
{projects.map(project => (
{project.name}
{project.project_type && ( {project.project_type} )}
{project.description && (

{project.description}

)}
{project.pm?.name || '未指定PM'}
负责人: {project.owner?.name || '未指定'}
))} {projects.length === 0 && (

暂无项目

{canCreate && ( )}
)}
); }