feat(tenancies-p2): rename berth_reservations → berth_tenancies (schema + perms + UI)
73-file atomic rename per docs/tenancies-design.md:
- Migration 0085: rename table + indexes + FK constraints; rename
documents.reservation_id → tenancy_id; migrate jsonb permission maps
(reservations resource → tenancies; collapse create+activate → manage);
rewrite historical audit_logs.entity_type='berth_reservation' →
'berth_tenancy'. FK renames wrapped in DO blocks so dev DBs that pre-date
the FK additions don't abort.
- Schema: berthReservations → berthTenancies; BerthReservation type →
BerthTenancy; indexes idx_br_* / idx_brr_* → idx_bt_*.
- RolePermissions: resource { view, create, activate, cancel } collapses to
{ view, manage, cancel }; all 8 default seed bundles + role-form + matrix
updated.
- Service: berth-reservations.service.ts → berth-tenancies.service.ts;
endReservation → endTenancy; listReservations → listTenancies.
- API: /api/v1/berth-reservations → /api/v1/tenancies (+ nested [id]);
/api/v1/berths/[id]/reservations → /api/v1/berths/[id]/tenancies.
- Validators: reservations.ts → tenancies.ts; RESERVATION_STATUSES →
TENANCY_STATUSES; endReservationSchema → endTenancySchema.
- Routes: /{portSlug}/berth-reservations → /{portSlug}/tenancies;
/portal/my-reservations → /portal/my-tenancies.
- Components: src/components/reservations/* → src/components/tenancies/*;
BerthReservationsTab → BerthTenanciesTab; ClientReservationsTab →
ClientTenanciesTab; ReservationList → TenancyList.
- Socket events: berth_reservation:* → berth_tenancy:*; payload
reservationId → tenancyId.
- Webhook events: berth_reservation.* → berth_tenancy.*.
- Portal: getPortalUserReservations → getPortalUserTenancies;
PortalReservation → PortalTenancy; PortalDashboard.counts.activeReservations
→ activeTenancies; PortalNav label "Reservations" → "Tenancies".
- Dossier: DossierReservation → DossierTenancy; reservationDecisions →
tenancyDecisions across smart-archive-dialog + bulk-archive routes.
- Documents schema: documents.reservationId → documents.tenancyId
(TS + DB column + index + FK constraint).
- Activity feed label berth_reservation → berth_tenancy (matched against
migrated historical audit rows).
KEPT (separate concepts):
- Reservation Agreement document type (the contract sent to clients).
- "Reservation" pipeline stage name.
- {{reservation.*}} merge tokens in template authoring.
- interest.reservationStatus / reservationDocStatus / dateReservationSent
fields (track agreement signing on the deal).
- reservation-agreement-context.ts service (builds merge context for the
Reservation Agreement doc; only its DB imports were renamed).
Verified: tsc clean, 1480/1480 vitest passing, migration applied.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
||||
BERTH_SIDE_PONTOON_OPTIONS,
|
||||
toSelectOptions,
|
||||
} from '@/lib/constants';
|
||||
import { BerthReservationsTab } from './berth-reservations-tab';
|
||||
import { BerthTenanciesTab } from './berth-tenancies-tab';
|
||||
import { BerthInterestsTab } from './berth-interests-tab';
|
||||
import { BerthInterestPulse } from './berth-interest-pulse';
|
||||
import { BerthDocumentsTab } from './berth-documents-tab';
|
||||
@@ -432,9 +432,9 @@ export function buildBerthTabs(berth: BerthData): DetailTab[] {
|
||||
content: <BerthInterestsTab berthId={berth.id} />,
|
||||
},
|
||||
{
|
||||
id: 'reservations',
|
||||
label: 'Reservations',
|
||||
content: <BerthReservationsTab berthId={berth.id} />,
|
||||
id: 'tenancies',
|
||||
label: 'Tenancies',
|
||||
content: <BerthTenanciesTab berthId={berth.id} />,
|
||||
},
|
||||
{
|
||||
id: 'spec',
|
||||
|
||||
@@ -9,61 +9,61 @@ import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { PermissionGate } from '@/components/shared/permission-gate';
|
||||
import { EmptyState } from '@/components/shared/empty-state';
|
||||
import { ReservationList, type ReservationRow } from '@/components/reservations/reservation-list';
|
||||
import { BerthReserveDialog } from '@/components/reservations/berth-reserve-dialog';
|
||||
import { TenancyList, type TenancyRow } from '@/components/tenancies/tenancy-list';
|
||||
import { BerthReserveDialog } from '@/components/tenancies/berth-reserve-dialog';
|
||||
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
|
||||
interface BerthReservationsTabProps {
|
||||
interface BerthTenanciesTabProps {
|
||||
berthId: string;
|
||||
}
|
||||
|
||||
export function BerthReservationsTab({ berthId }: BerthReservationsTabProps) {
|
||||
export function BerthTenanciesTab({ berthId }: BerthTenanciesTabProps) {
|
||||
const routeParams = useParams<{ portSlug: string }>();
|
||||
const portSlug = routeParams?.portSlug ?? '';
|
||||
const [reserveOpen, setReserveOpen] = useState(false);
|
||||
|
||||
const { data, isLoading } = useQuery<{ data: ReservationRow[]; pagination?: unknown }>({
|
||||
queryKey: ['berths', berthId, 'reservations'],
|
||||
const { data, isLoading } = useQuery<{ data: TenancyRow[]; pagination?: unknown }>({
|
||||
queryKey: ['berths', berthId, 'tenancies'],
|
||||
queryFn: () =>
|
||||
apiFetch(
|
||||
`/api/v1/berths/${berthId}/reservations?page=1&limit=50&order=desc&includeArchived=false`,
|
||||
`/api/v1/berths/${berthId}/tenancies?page=1&limit=50&order=desc&includeArchived=false`,
|
||||
),
|
||||
});
|
||||
|
||||
useRealtimeInvalidation({
|
||||
'berth_reservation:created': [['berths', berthId, 'reservations']],
|
||||
'berth_reservation:activated': [['berths', berthId, 'reservations']],
|
||||
'berth_reservation:ended': [['berths', berthId, 'reservations']],
|
||||
'berth_reservation:cancelled': [['berths', berthId, 'reservations']],
|
||||
'berth_tenancy:created': [['berths', berthId, 'tenancies']],
|
||||
'berth_tenancy:activated': [['berths', berthId, 'tenancies']],
|
||||
'berth_tenancy:ended': [['berths', berthId, 'tenancies']],
|
||||
'berth_tenancy:cancelled': [['berths', berthId, 'tenancies']],
|
||||
});
|
||||
|
||||
const reservations = data?.data ?? [];
|
||||
const active = reservations.find((r) => r.status === 'active');
|
||||
const history = reservations.filter((r) => r.status !== 'active');
|
||||
const tenancies = data?.data ?? [];
|
||||
const active = tenancies.find((r) => r.status === 'active');
|
||||
const history = tenancies.filter((r) => r.status !== 'active');
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-lg font-semibold">Reservations</h3>
|
||||
<PermissionGate resource="reservations" action="create">
|
||||
<h3 className="text-lg font-semibold">Tenancies</h3>
|
||||
<PermissionGate resource="tenancies" action="manage">
|
||||
<Button size="sm" onClick={() => setReserveOpen(true)}>
|
||||
<Plus className="mr-1.5 h-4 w-4" aria-hidden />
|
||||
Reserve this berth
|
||||
Create tenancy
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</div>
|
||||
|
||||
{/* Active reservation card */}
|
||||
{/* Active tenancy card */}
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="text-sm font-medium">Active reservation</CardTitle>
|
||||
<CardTitle className="text-sm font-medium">Active tenancy</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{active ? (
|
||||
<ReservationList reservations={[active]} portSlug={portSlug} />
|
||||
<TenancyList tenancies={[active]} portSlug={portSlug} />
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">No active reservation.</p>
|
||||
<p className="text-sm text-muted-foreground">No active tenancy.</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -77,9 +77,9 @@ export function BerthReservationsTab({ berthId }: BerthReservationsTabProps) {
|
||||
{isLoading ? (
|
||||
<p className="text-sm text-muted-foreground">Loading…</p>
|
||||
) : history.length === 0 ? (
|
||||
<EmptyState title="No past reservations" description="Nothing here yet." />
|
||||
<EmptyState title="No past tenancies" description="Nothing here yet." />
|
||||
) : (
|
||||
<ReservationList reservations={history} portSlug={portSlug} />
|
||||
<TenancyList tenancies={history} portSlug={portSlug} />
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
Reference in New Issue
Block a user