pelagia-portal/App/app/(portal)/admin/vessels/page.tsx
Hardik a1b77d8b00 feat(vessels): editable custom code when creating a vessel
- Add Vessel dialog now shows an editable Code field pre-filled with the
  next auto-generated code (e.g. SITE-004) — user can change it freely
- Edit Vessel dialog keeps the code read-only (changing codes on existing
  data would break PO references)
- createVessel action: uses submitted code if provided, auto-generates if
  left blank, and validates uniqueness before saving

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 04:14:03 +05:30

41 lines
1.2 KiB
TypeScript

import { auth } from "@/auth";
import { db } from "@/lib/db";
import { hasPermission } from "@/lib/permissions";
import { redirect } from "next/navigation";
import { VesselsTable } from "./vessels-table";
import { nextId } from "@/lib/id-generators";
import type { Metadata } from "next";
export const metadata: Metadata = { title: "Vessel Management" };
export default async function AdminVesselsPage() {
const session = await auth();
if (!session?.user) redirect("/login");
if (!hasPermission(session.user.role, "manage_vessels_accounts")) redirect("/dashboard");
const [vessels, sites] = await Promise.all([
db.vessel.findMany({
orderBy: { name: "asc" },
include: { site: { select: { name: true } } },
}),
db.site.findMany({ where: { isActive: true }, orderBy: { name: "asc" }, select: { id: true, name: true } }),
]);
const suggestedCode = nextId("SITE", vessels.map((v) => v.code));
return (
<VesselsTable
suggestedCode={suggestedCode}
vessels={vessels.map((v) => ({
id: v.id,
code: v.code,
name: v.name,
siteId: v.siteId ?? null,
siteName: v.site?.name ?? null,
isActive: v.isActive,
}))}
sites={sites}
/>
);
}