77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import { notFound } from "next/navigation";
|
|
import { getTaskById } from "@/lib/tasksService";
|
|
import { getProjectById } from "@/lib/projectsService";
|
|
import { TaskDetailView } from "@/components/task-detail";
|
|
|
|
interface PageProps {
|
|
params: Promise<{
|
|
id: string;
|
|
}>;
|
|
}
|
|
|
|
/**
|
|
* Página de detalle de tarea
|
|
* Ruta dinámica: /tareas/[id]
|
|
*
|
|
* Muestra información completa de la tarea incluyendo:
|
|
* - Header con breadcrumb, título, estado y prioridad
|
|
* - Estadísticas (progreso, tiempo, fecha límite, rendimiento)
|
|
* - Información detallada (descripción, fechas, metadatos)
|
|
* - Navegación al proyecto padre
|
|
*/
|
|
export default async function TaskDetailPage({ params }: PageProps) {
|
|
// Await params en Next.js 16
|
|
const resolvedParams = await params;
|
|
const taskId = parseInt(resolvedParams.id);
|
|
|
|
if (isNaN(taskId)) {
|
|
notFound();
|
|
}
|
|
|
|
// Obtener la tarea
|
|
const task = await getTaskById(taskId);
|
|
|
|
if (!task) {
|
|
notFound();
|
|
}
|
|
|
|
// Obtener el proyecto asociado (puede ser null)
|
|
let project = null;
|
|
if (task.projectId) {
|
|
try {
|
|
const fetchedProject = await getProjectById(task.projectId);
|
|
project = fetchedProject ?? null;
|
|
} catch (error) {
|
|
console.error('Error fetching project for task:', error);
|
|
// Continuar sin proyecto
|
|
}
|
|
}
|
|
|
|
return <TaskDetailView initialTask={task} project={project} />;
|
|
}
|
|
|
|
// Metadata dinámica para SEO
|
|
export async function generateMetadata({ params }: PageProps) {
|
|
const resolvedParams = await params;
|
|
const taskId = parseInt(resolvedParams.id);
|
|
|
|
if (isNaN(taskId)) {
|
|
return { title: "Tarea no encontrada" };
|
|
}
|
|
|
|
try {
|
|
const task = await getTaskById(taskId);
|
|
|
|
if (!task) {
|
|
return { title: "Tarea no encontrada" };
|
|
}
|
|
|
|
return {
|
|
title: `${task.title} - Tarea`,
|
|
description: task.description || `Detalles de la tarea ${task.ref}`,
|
|
};
|
|
} catch {
|
|
return { title: "Tarea" };
|
|
}
|
|
}
|