trello_fake/components/dashboard/project-card.tsx

165 lines
6.5 KiB
TypeScript
Raw Normal View History

"use client";
2026-01-28 10:44:49 +00:00
import Link from 'next/link';
import { Calendar, DollarSign, TrendingUp, FileText, MoreHorizontal, Pencil, Trash2, Eye } from 'lucide-react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Avatar, AvatarFallback } from '@/components/ui/avatar';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { ProjectStatusBadge } from '@/components/ui/project-status-badge';
import { Project } from '@/types/project';
interface ProjectCardProps {
project: Project;
onEdit?: (project: Project) => void;
onDelete?: (project: Project) => void;
}
2026-01-09 17:39:19 +00:00
// Función para generar iniciales
function getInitials(name: string): string {
return name
.split(' ')
.map(word => word[0])
.join('')
.toUpperCase()
.slice(0, 2);
}
export default function ProjectCard({ project, onEdit, onDelete }: ProjectCardProps) {
2026-01-09 17:39:19 +00:00
const initials = getInitials(project.name);
return (
<Card className="hover:shadow-lg transition-all duration-300 hover:-translate-y-1 h-full group">
<CardHeader>
<div className="flex items-start justify-between">
<Link href={`/proyectos/${project.id}`} className="flex items-center gap-3 flex-1 cursor-pointer">
<Avatar className="w-12 h-12">
<AvatarFallback className="bg-gradient-to-br from-blue-500 to-purple-600 text-white font-semibold">
{initials}
</AvatarFallback>
</Avatar>
<div>
<CardTitle className="text-lg hover:text-primary transition-colors">{project.name}</CardTitle>
<CardDescription className="text-sm">{project.ref}</CardDescription>
</div>
</Link>
{/* Menú de acciones */}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 opacity-0 group-hover:opacity-100 transition-opacity"
onClick={(e) => e.stopPropagation()}
>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem asChild>
<Link href={`/proyectos/${project.id}`}>
<Eye className="mr-2 h-4 w-4" />
Ver detalles
</Link>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onEdit?.(project)}>
<Pencil className="mr-2 h-4 w-4" />
Editar
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
className="text-destructive focus:text-destructive"
onClick={() => onDelete?.(project)}
>
<Trash2 className="mr-2 h-4 w-4" />
Eliminar
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
<ProjectStatusBadge status={project.status} className="mt-3 w-fit" />
</CardHeader>
<Link href={`/proyectos/${project.id}`} className="cursor-pointer">
2026-01-28 10:44:49 +00:00
<CardContent>
{/* Description */}
{project.description && (
<div className="mb-4">
<div className="flex items-center gap-1 text-muted-foreground mb-1">
2026-01-28 10:44:49 +00:00
<FileText className="w-3 h-3" />
<span className="text-xs">Descripción</span>
</div>
<p className="text-sm text-muted-foreground line-clamp-2">{project.description}</p>
2026-01-09 17:39:19 +00:00
</div>
2026-01-28 10:44:49 +00:00
)}
2026-01-09 17:39:19 +00:00
2026-01-28 10:44:49 +00:00
{/* Progress Bar */}
<div className="mb-4">
<div className="flex items-center justify-between mb-2">
<span className="text-xs font-medium text-muted-foreground">Progreso</span>
<span className="text-xs font-semibold">{project.progress}%</span>
2026-01-28 10:44:49 +00:00
</div>
<div className="w-full bg-muted rounded-full h-2">
2026-01-28 10:44:49 +00:00
<div
className="bg-gradient-to-r from-blue-500 to-purple-600 h-2 rounded-full transition-all duration-500"
style={{ width: `${project.progress}%` }}
/>
</div>
</div>
2026-01-28 10:44:49 +00:00
{/* Budget Info */}
<div className="grid grid-cols-2 gap-4 mb-4">
<div>
<div className="flex items-center gap-1 text-muted-foreground mb-1">
2026-01-28 10:44:49 +00:00
<DollarSign className="w-3 h-3" />
<span className="text-xs">Presupuesto</span>
</div>
<p className="text-sm font-semibold">
2026-01-28 10:44:49 +00:00
€{project.budget.toLocaleString('es-ES', { minimumFractionDigits: 0, maximumFractionDigits: 0 })}
</p>
</div>
2026-01-28 10:44:49 +00:00
<div>
<div className="flex items-center gap-1 text-muted-foreground mb-1">
2026-01-28 10:44:49 +00:00
<TrendingUp className="w-3 h-3" />
<span className="text-xs">Estimado</span>
</div>
<p className="text-sm font-semibold">
2026-01-28 10:44:49 +00:00
€{project.spent.toLocaleString('es-ES', { minimumFractionDigits: 0, maximumFractionDigits: 0 })}
</p>
</div>
</div>
2026-01-28 10:44:49 +00:00
{/* Footer Info */}
<div className="pt-4 border-t flex items-center justify-between">
<div className="flex items-center gap-1 text-muted-foreground">
2026-01-28 10:44:49 +00:00
<Calendar className="w-4 h-4" />
<span className="text-xs">
{new Date(project.startDate).toLocaleDateString('es-ES', { day: '2-digit', month: 'short', year: 'numeric' })}
</span>
</div>
<div className="flex items-center gap-1 text-muted-foreground">
2026-01-28 10:44:49 +00:00
<Calendar className="w-4 h-4" />
<span className="text-xs">
{new Date(project.endDate).toLocaleDateString('es-ES', { day: '2-digit', month: 'short', year: 'numeric' })}
</span>
</div>
</div>
2026-01-09 17:39:19 +00:00
2026-01-28 10:44:49 +00:00
{/* Cliente */}
{project.client !== 'Sin cliente' && (
<div className="mt-3 pt-3 border-t">
<span className="text-xs text-muted-foreground">Cliente: </span>
<span className="text-xs font-medium">{project.client}</span>
2026-01-28 10:44:49 +00:00
</div>
)}
</CardContent>
</Link>
</Card>
);
}