import { auth } from "@/auth"; import { db } from "@/lib/db"; import { hasPermission } from "@/lib/permissions"; import { CREWING_ENABLED } from "@/lib/feature-flags"; import { redirect, notFound } from "next/navigation"; import Link from "next/link"; import { ArrowLeft, Check } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { ApplicationActionCard } from "../application-action-card"; import { STAGE_ORDER, STAGE_LABEL, STAGE_VARIANT, stageIndex } from "../application-ui"; import { experienceLabel } from "../../candidates/candidate-ui"; import { cn } from "@/lib/utils"; import type { Metadata } from "next"; export const metadata: Metadata = { title: "Application" }; export default async function ApplicationDetailPage({ params }: { params: Promise<{ id: string }> }) { if (!CREWING_ENABLED) notFound(); const session = await auth(); if (!session?.user) redirect("/login"); const role = session.user.role; if (!hasPermission(role, "view_requisitions") && !hasPermission(role, "manage_candidates")) redirect("/dashboard"); const { id } = await params; const app = await db.application.findUnique({ where: { id }, include: { requisition: { include: { rank: { select: { name: true } }, vessel: { select: { name: true } }, site: { select: { name: true } } } }, crewMember: { include: { appliedRank: { select: { name: true } }, currentRank: { select: { name: true } } } }, gates: true, salaryStructures: { orderBy: { createdAt: "desc" } }, }, }); if (!app) notFound(); const gate = (t: string) => app.gates.find((g) => g.gate === t); const salaryPending = gate("SALARY")?.result === "PENDING"; const waiverPending = gate("WAIVER")?.result === "PENDING"; const selectionPending = gate("SELECTION")?.result === "PENDING"; const proposed = app.salaryStructures.find((s) => !s.approvedById) ?? app.salaryStructures[0] ?? null; const loc = app.requisition.vessel?.name ?? app.requisition.site?.name ?? "—"; const curIdx = stageIndex(app.stage); return (
{app.requisition.rank.name} · {loc} · {app.requisition.code}
{/* 7-step stepper */}