import Link from "next/link"; import { ProjectType } from "@prisma/client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import AdminPageHeader from "@/components/admin/admin-page-header"; import { deleteProject } from "@/app/admin/(protected)/projects/actions"; import { prisma } from "@/lib/db"; import { projectTypeFilterSchema } from "@/lib/validations/project"; const typeLabels: Record = { PORTFOLIO: "Portfolio", APP: "App", WEBSITE: "Website", DESIGN: "Design", }; type ProjectsPageProps = { searchParams: { type?: string; error?: string }; }; function getErrorMessage(error?: string) { if (error === "invalid-id") return "The selected project id is invalid."; if (error === "not-found") return "The selected project no longer exists."; if (error === "delete-failed") return "The project could not be deleted."; return null; } export default async function ProjectsPage({ searchParams }: ProjectsPageProps) { const type = projectTypeFilterSchema.safeParse(searchParams.type); const selectedType = type.success ? type.data : undefined; const projects = await prisma.project.findMany({ where: selectedType ? { type: selectedType } : undefined, orderBy: [{ sortOrder: "asc" }, { updatedAt: "desc" }], include: { category: { select: { nameEn: true, nameAr: true } } }, }); const errorMessage = getErrorMessage(searchParams.error); return (
New project } /> {errorMessage ? (

{errorMessage}

) : null}
{Object.entries(typeLabels).map(([value, label]) => ( ))}
{projects.length === 0 ? (

No projects match this filter yet.

) : (
{projects.map((project) => (

{typeLabels[project.type]}

{project.titleEn}

{project.titleAr}

{project.status}

/{project.slug}

{project.category ? `${project.category.nameEn} · ${project.category.nameAr}` : "No category"}

{project.images.length} images · {project.technologies.length} technologies

))}
)}
); }