- 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>
41 lines
1.2 KiB
TypeScript
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}
|
|
/>
|
|
);
|
|
}
|