fix(T3): copy + entry points + recommender alias
Batch of small fixes from the post-audit plan:
F11 — "Mark as won" dialog copy
Was: "This will move the interest to Completed and stamp the outcome."
Completed was retired in the 7-stage refactor; copy now reads
"marks Won; stage stays where it is" with a parallel Lost variant.
F13 — Bulk-add berths wizard had no UI entry point
Page existed at /[portSlug]/admin/berths/bulk-add but nothing linked
to it. Added a "Bulk add" button on the Berths list toolbar, gated
on `berths.import`. Also fixed the API route's permission key
(was `berths.create`, a phantom — switched to `berths.import` to
match seed-permissions).
F14 — Audit Log nav entry
Sidebar Admin section now lists "Audit Log" → /admin/audit, gated
by the adminRequired group rule.
F18 — Recommender `limit` param ignored
POST /interests/[id]/recommend-berths now accepts `limit` as an
alias for `topN`. Audit sent `{limit:3}` and silently got 8 rows
back; both names now resolve.
Tests still green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,10 @@ import { bulkAddBerthsSchema } from '@/lib/validators/berths';
|
|||||||
* /[portSlug]/admin/berths/bulk-add.
|
* /[portSlug]/admin/berths/bulk-add.
|
||||||
*/
|
*/
|
||||||
export const POST = withAuth(
|
export const POST = withAuth(
|
||||||
withPermission('berths', 'create', async (req, ctx) => {
|
// F13: aligned with the seed-permissions scope (`berths.import`).
|
||||||
|
// The previous `berths.create` was a phantom key — not in the role
|
||||||
|
// matrix, so non-super-admins silently failed permission resolution.
|
||||||
|
withPermission('berths', 'import', async (req, ctx) => {
|
||||||
try {
|
try {
|
||||||
const input = await parseBody(req, bulkAddBerthsSchema);
|
const input = await parseBody(req, bulkAddBerthsSchema);
|
||||||
const result = await bulkAddBerths(ctx.portId, input.berths, {
|
const result = await bulkAddBerths(ctx.portId, input.berths, {
|
||||||
|
|||||||
@@ -11,20 +11,29 @@ import { recommendBerths } from '@/lib/services/berth-recommender.service';
|
|||||||
* param) and `portId` (resolved from the auth context — never trust a
|
* param) and `portId` (resolved from the auth context — never trust a
|
||||||
* client-supplied port, plan §14.10).
|
* client-supplied port, plan §14.10).
|
||||||
*/
|
*/
|
||||||
const recommendBerthsSchema = z.object({
|
const recommendBerthsSchema = z
|
||||||
topN: z.number().int().min(1).max(999).optional(),
|
.object({
|
||||||
maxOversizePct: z.number().min(0).max(1000).optional(),
|
topN: z.number().int().min(1).max(999).optional(),
|
||||||
showLateStage: z.boolean().optional(),
|
// F18: accept `limit` as a friendlier alias for `topN`. The audit
|
||||||
amenityFilters: z
|
// sent `{limit: 3}` and was silently ignored; conventional API users
|
||||||
.object({
|
// expect the limit name. Both resolve to the same internal value.
|
||||||
minPowerCapacityKw: z.number().min(0).optional(),
|
limit: z.number().int().min(1).max(999).optional(),
|
||||||
requiredVoltage: z.number().int().min(0).optional(),
|
maxOversizePct: z.number().min(0).max(1000).optional(),
|
||||||
requiredAccess: z.string().min(1).optional(),
|
showLateStage: z.boolean().optional(),
|
||||||
requiredMooringType: z.string().min(1).optional(),
|
amenityFilters: z
|
||||||
requiredCleatCapacity: z.string().min(1).optional(),
|
.object({
|
||||||
})
|
minPowerCapacityKw: z.number().min(0).optional(),
|
||||||
.optional(),
|
requiredVoltage: z.number().int().min(0).optional(),
|
||||||
});
|
requiredAccess: z.string().min(1).optional(),
|
||||||
|
requiredMooringType: z.string().min(1).optional(),
|
||||||
|
requiredCleatCapacity: z.string().min(1).optional(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.transform(({ limit, topN, ...rest }) => ({
|
||||||
|
...rest,
|
||||||
|
topN: topN ?? limit,
|
||||||
|
}));
|
||||||
|
|
||||||
// POST /api/v1/interests/[id]/recommend-berths
|
// POST /api/v1/interests/[id]/recommend-berths
|
||||||
export const POST = withAuth(
|
export const POST = withAuth(
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
import { useRouter, useParams } from 'next/navigation';
|
import { useRouter, useParams } from 'next/navigation';
|
||||||
import { Anchor } from 'lucide-react';
|
import { Anchor, Plus } from 'lucide-react';
|
||||||
|
|
||||||
import { DataTable } from '@/components/shared/data-table';
|
import { DataTable } from '@/components/shared/data-table';
|
||||||
import { FilterBar } from '@/components/shared/filter-bar';
|
import { FilterBar } from '@/components/shared/filter-bar';
|
||||||
import { PageHeader } from '@/components/shared/page-header';
|
import { PageHeader } from '@/components/shared/page-header';
|
||||||
import { SavedViewsDropdown } from '@/components/shared/saved-views-dropdown';
|
import { SavedViewsDropdown } from '@/components/shared/saved-views-dropdown';
|
||||||
import { ColumnPicker } from '@/components/shared/column-picker';
|
import { ColumnPicker } from '@/components/shared/column-picker';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { EmptyState } from '@/components/shared/empty-state';
|
import { EmptyState } from '@/components/shared/empty-state';
|
||||||
import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
import { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
||||||
|
import { usePermissions } from '@/hooks/use-permissions';
|
||||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||||
import { useTablePreferences } from '@/hooks/use-table-preferences';
|
import { useTablePreferences } from '@/hooks/use-table-preferences';
|
||||||
import { BerthCard } from './berth-card';
|
import { BerthCard } from './berth-card';
|
||||||
@@ -26,6 +29,11 @@ import { mooringLetterTone } from './mooring-letter-tone';
|
|||||||
export function BerthList() {
|
export function BerthList() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const params = useParams<{ portSlug: string }>();
|
const params = useParams<{ portSlug: string }>();
|
||||||
|
// F13: bulk-add wizard had no UI entry point. Gate the CTA on
|
||||||
|
// `berths.import` (the existing permission used for adding berths)
|
||||||
|
// so non-admins don't see a button that 403s on click.
|
||||||
|
const { can } = usePermissions();
|
||||||
|
const canBulkAdd = can('berths', 'import');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
@@ -97,6 +105,14 @@ export function BerthList() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ColumnPicker columns={BERTH_COLUMN_OPTIONS} hidden={hidden} onChange={setHidden} />
|
<ColumnPicker columns={BERTH_COLUMN_OPTIONS} hidden={hidden} onChange={setHidden} />
|
||||||
|
{canBulkAdd && (
|
||||||
|
<Button asChild size="sm" variant="default">
|
||||||
|
<Link href={`/${params.portSlug}/admin/berths/bulk-add`}>
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
<span className="hidden sm:inline">Bulk add</span>
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -126,8 +126,17 @@ export function InterestOutcomeDialog({ interestId, open, onOpenChange, mode }:
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
This will move the interest to <strong>Completed</strong> and stamp the outcome. You can
|
{mode === 'won' ? (
|
||||||
reopen it later.
|
<>
|
||||||
|
This will mark the interest as <strong>Won</strong>. The pipeline stage stays where
|
||||||
|
it is; the outcome flag is set. You can clear the outcome later to reopen.
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
This will close the interest with a <strong>Lost</strong> outcome. The pipeline
|
||||||
|
stage stays where it is. You can clear the outcome later to reopen.
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
Globe,
|
Globe,
|
||||||
Settings,
|
Settings,
|
||||||
Shield,
|
Shield,
|
||||||
|
ScrollText,
|
||||||
Home,
|
Home,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
@@ -159,6 +160,8 @@ function buildNavSections(portSlug: string | undefined): NavSection[] {
|
|||||||
items: [
|
items: [
|
||||||
{ href: `${base}/settings`, label: 'Settings', icon: Settings },
|
{ href: `${base}/settings`, label: 'Settings', icon: Settings },
|
||||||
{ href: `${base}/admin`, label: 'Administration', icon: Shield },
|
{ href: `${base}/admin`, label: 'Administration', icon: Shield },
|
||||||
|
// F14: audit log page existed but had no nav link.
|
||||||
|
{ href: `${base}/admin/audit`, label: 'Audit Log', icon: ScrollText },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user