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:
@@ -26,7 +26,7 @@ interface PreflightItem {
|
||||
stakeLevel: 'low' | 'high';
|
||||
highStakesStage: string | null;
|
||||
blockers: string[];
|
||||
summary: { berths: number; yachts: number; reservations: number; signedDocs: number };
|
||||
summary: { berths: number; yachts: number; tenancies: number; signedDocs: number };
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -215,8 +215,8 @@ function BulkArchiveWizardBody({ open, onOpenChange, clientIds, onSuccess }: Pro
|
||||
{currentHighStakes.summary.signedDocs > 0
|
||||
? `${currentHighStakes.summary.signedDocs} signed doc(s), `
|
||||
: ''}
|
||||
{currentHighStakes.summary.reservations > 0
|
||||
? `${currentHighStakes.summary.reservations} reservation(s)`
|
||||
{currentHighStakes.summary.tenancies > 0
|
||||
? `${currentHighStakes.summary.tenancies} tenancy(ies)`
|
||||
: ''}
|
||||
</span>
|
||||
</WarningCallout>
|
||||
|
||||
@@ -64,7 +64,7 @@ interface ClientData {
|
||||
status: string;
|
||||
};
|
||||
}>;
|
||||
activeReservations: Array<{
|
||||
activeTenancies: Array<{
|
||||
id: string;
|
||||
berthId: string;
|
||||
yachtId: string;
|
||||
@@ -113,9 +113,9 @@ export function ClientDetail({ clientId, currentUserId }: ClientDetailProps) {
|
||||
'yacht:ownership_transferred': [['clients', clientId]],
|
||||
'company_membership:added': [['clients', clientId]],
|
||||
'company_membership:ended': [['clients', clientId]],
|
||||
'berth_reservation:activated': [['clients', clientId]],
|
||||
'berth_reservation:ended': [['clients', clientId]],
|
||||
'berth_reservation:cancelled': [['clients', clientId]],
|
||||
'berth_tenancy:activated': [['clients', clientId]],
|
||||
'berth_tenancy:ended': [['clients', clientId]],
|
||||
'berth_tenancy:cancelled': [['clients', clientId]],
|
||||
});
|
||||
|
||||
if (error && !isLoading) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import { ClientInterestsTab } from '@/components/clients/client-interests-tab';
|
||||
import { ClientPipelineSummary } from '@/components/clients/client-pipeline-summary';
|
||||
import { ClientYachtsTab } from '@/components/clients/client-yachts-tab';
|
||||
import { ClientCompaniesTab } from '@/components/clients/client-companies-tab';
|
||||
import { ClientReservationsTab } from '@/components/clients/client-reservations-tab';
|
||||
import { ClientTenanciesTab } from '@/components/clients/client-tenancies-tab';
|
||||
import { ClientFilesTab } from '@/components/clients/client-files-tab';
|
||||
import { ContactsEditor } from '@/components/clients/contacts-editor';
|
||||
import { AddressesEditor, type Address } from '@/components/shared/addresses-editor';
|
||||
@@ -123,7 +123,7 @@ interface ClientTabsOptions {
|
||||
status: string;
|
||||
};
|
||||
}>;
|
||||
activeReservations: Array<{
|
||||
activeTenancies: Array<{
|
||||
id: string;
|
||||
berthId: string;
|
||||
yachtId: string;
|
||||
@@ -276,12 +276,10 @@ export function getClientTabs({ clientId, currentUserId, client }: ClientTabsOpt
|
||||
content: <ClientCompaniesTab clientId={clientId} companies={client.companies} />,
|
||||
},
|
||||
{
|
||||
id: 'reservations',
|
||||
label: 'Reservations',
|
||||
badge: client.activeReservations.length,
|
||||
content: (
|
||||
<ClientReservationsTab clientId={clientId} activeReservations={client.activeReservations} />
|
||||
),
|
||||
id: 'tenancies',
|
||||
label: 'Tenancies',
|
||||
badge: client.activeTenancies.length,
|
||||
content: <ClientTenanciesTab clientId={clientId} activeTenancies={client.activeTenancies} />,
|
||||
},
|
||||
{
|
||||
id: 'addresses',
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
import { useState } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { ReservationList, type ReservationRow } from '@/components/reservations/reservation-list';
|
||||
import { TenancyList, type TenancyRow } from '@/components/tenancies/tenancy-list';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
|
||||
interface ClientReservationsTabProps {
|
||||
interface ClientTenanciesTabProps {
|
||||
clientId: string;
|
||||
activeReservations: Array<{
|
||||
activeTenancies: Array<{
|
||||
id: string;
|
||||
berthId: string;
|
||||
yachtId: string;
|
||||
@@ -19,24 +19,21 @@ interface ClientReservationsTabProps {
|
||||
}>;
|
||||
}
|
||||
|
||||
interface ReservationListResponse {
|
||||
data: ReservationRow[];
|
||||
interface TenancyListResponse {
|
||||
data: TenancyRow[];
|
||||
pagination?: { total: number };
|
||||
}
|
||||
|
||||
export function ClientReservationsTab({
|
||||
clientId,
|
||||
activeReservations,
|
||||
}: ClientReservationsTabProps) {
|
||||
export function ClientTenanciesTab({ clientId, activeTenancies }: ClientTenanciesTabProps) {
|
||||
const [showHistory, setShowHistory] = useState(false);
|
||||
|
||||
const activeRows: ReservationRow[] = activeReservations.map((r) => ({
|
||||
const activeRows: TenancyRow[] = activeTenancies.map((r) => ({
|
||||
id: r.id,
|
||||
berthId: r.berthId,
|
||||
portId: '',
|
||||
clientId,
|
||||
yachtId: r.yachtId,
|
||||
status: r.status as ReservationRow['status'],
|
||||
status: r.status as TenancyRow['status'],
|
||||
startDate: typeof r.startDate === 'string' ? r.startDate : r.startDate.toISOString(),
|
||||
endDate: null,
|
||||
tenureType: r.tenureType,
|
||||
@@ -48,23 +45,23 @@ export function ClientReservationsTab({
|
||||
// Lazy-load history (ended + cancelled). Two parallel queries because
|
||||
// the API takes one status at a time; combining once both resolve.
|
||||
const endedQuery = useQuery({
|
||||
queryKey: ['reservations', { clientId, status: 'ended' }],
|
||||
queryKey: ['tenancies', { clientId, status: 'ended' }],
|
||||
queryFn: () =>
|
||||
apiFetch<ReservationListResponse>(
|
||||
`/api/v1/berth-reservations?clientId=${encodeURIComponent(clientId)}&status=ended&pageSize=50`,
|
||||
apiFetch<TenancyListResponse>(
|
||||
`/api/v1/tenancies?clientId=${encodeURIComponent(clientId)}&status=ended&pageSize=50`,
|
||||
),
|
||||
enabled: showHistory,
|
||||
});
|
||||
const cancelledQuery = useQuery({
|
||||
queryKey: ['reservations', { clientId, status: 'cancelled' }],
|
||||
queryKey: ['tenancies', { clientId, status: 'cancelled' }],
|
||||
queryFn: () =>
|
||||
apiFetch<ReservationListResponse>(
|
||||
`/api/v1/berth-reservations?clientId=${encodeURIComponent(clientId)}&status=cancelled&pageSize=50`,
|
||||
apiFetch<TenancyListResponse>(
|
||||
`/api/v1/tenancies?clientId=${encodeURIComponent(clientId)}&status=cancelled&pageSize=50`,
|
||||
),
|
||||
enabled: showHistory,
|
||||
});
|
||||
|
||||
const historyRows: ReservationRow[] = [
|
||||
const historyRows: TenancyRow[] = [
|
||||
...(endedQuery.data?.data ?? []),
|
||||
...(cancelledQuery.data?.data ?? []),
|
||||
].sort((a, b) => (a.startDate < b.startDate ? 1 : -1));
|
||||
@@ -75,12 +72,12 @@ export function ClientReservationsTab({
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-medium">Active reservations</h3>
|
||||
<h3 className="text-sm font-medium">Active tenancies</h3>
|
||||
</div>
|
||||
<ReservationList
|
||||
reservations={activeRows}
|
||||
<TenancyList
|
||||
tenancies={activeRows}
|
||||
showBerth
|
||||
emptyMessage="This client has no active reservations."
|
||||
emptyMessage="This client has no active tenancies."
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -100,15 +97,15 @@ export function ClientReservationsTab({
|
||||
isHistoryLoading ? (
|
||||
<p className="text-xs text-muted-foreground">Loading…</p>
|
||||
) : (
|
||||
<ReservationList
|
||||
reservations={historyRows}
|
||||
<TenancyList
|
||||
tenancies={historyRows}
|
||||
showBerth
|
||||
emptyMessage="No ended or cancelled reservations."
|
||||
emptyMessage="No ended or cancelled tenancies."
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Click “Show history” to load ended and cancelled reservations.
|
||||
Click “Show history” to load ended and cancelled tenancies.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
@@ -47,8 +47,8 @@ interface DossierYacht {
|
||||
hullNumber: string | null;
|
||||
status: string;
|
||||
}
|
||||
interface DossierReservation {
|
||||
reservationId: string;
|
||||
interface DossierTenancy {
|
||||
tenancyId: string;
|
||||
berthId: string;
|
||||
mooringNumber: string;
|
||||
status: string;
|
||||
@@ -75,7 +75,7 @@ interface ArchiveDossier {
|
||||
berths: DossierBerth[];
|
||||
yachts: DossierYacht[];
|
||||
companies: Array<{ companyId: string; name: string; membershipRole: string | null }>;
|
||||
reservations: DossierReservation[];
|
||||
tenancies: DossierTenancy[];
|
||||
invoices: DossierInvoice[];
|
||||
documents: DossierDocument[];
|
||||
hasPortalUser: boolean;
|
||||
@@ -84,7 +84,7 @@ interface ArchiveDossier {
|
||||
|
||||
type BerthAction = 'release' | 'retain';
|
||||
type YachtAction = 'transfer' | 'mark_sold_away' | 'retain';
|
||||
type ReservationAction = 'cancel' | 'transfer';
|
||||
type TenancyAction = 'cancel' | 'transfer';
|
||||
type InvoiceAction = 'void' | 'write_off' | 'leave';
|
||||
type DocumentAction = 'void_documenso' | 'leave';
|
||||
|
||||
@@ -168,13 +168,9 @@ function SmartArchiveDialogBody({
|
||||
? Object.fromEntries(dossier.yachts.map((y) => [y.yachtId, 'retain' as YachtAction]))
|
||||
: {},
|
||||
);
|
||||
const [reservationDecisions, setReservationDecisions] = useState<
|
||||
Record<string, ReservationAction>
|
||||
>(() =>
|
||||
const [tenancyDecisions, setTenancyDecisions] = useState<Record<string, TenancyAction>>(() =>
|
||||
dossier
|
||||
? Object.fromEntries(
|
||||
dossier.reservations.map((r) => [r.reservationId, 'cancel' as ReservationAction]),
|
||||
)
|
||||
? Object.fromEntries(dossier.tenancies.map((r) => [r.tenancyId, 'cancel' as TenancyAction]))
|
||||
: {},
|
||||
);
|
||||
const [invoiceDecisions, setInvoiceDecisions] = useState<Record<string, InvoiceAction>>(() =>
|
||||
@@ -233,9 +229,9 @@ function SmartArchiveDialogBody({
|
||||
yachtId: y.yachtId,
|
||||
action: yachtDecisions[y.yachtId] ?? 'retain',
|
||||
})),
|
||||
reservationDecisions: dossier.reservations.map((r) => ({
|
||||
reservationId: r.reservationId,
|
||||
action: reservationDecisions[r.reservationId] ?? 'cancel',
|
||||
tenancyDecisions: dossier.tenancies.map((r) => ({
|
||||
tenancyId: r.tenancyId,
|
||||
action: tenancyDecisions[r.tenancyId] ?? 'cancel',
|
||||
})),
|
||||
invoiceDecisions: dossier.invoices.map((i) => ({
|
||||
invoiceId: i.invoiceId,
|
||||
@@ -459,33 +455,30 @@ function SmartArchiveDialogBody({
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Reservations */}
|
||||
{dossier.reservations.length > 0 && (
|
||||
{/* Tenancies */}
|
||||
{dossier.tenancies.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium flex items-center gap-2">
|
||||
<Anchor className="h-4 w-4" aria-hidden /> Active reservations (
|
||||
{dossier.reservations.length})
|
||||
<Anchor className="h-4 w-4" aria-hidden /> Active tenancies (
|
||||
{dossier.tenancies.length})
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
{dossier.reservations.map((r) => (
|
||||
<div
|
||||
key={r.reservationId}
|
||||
className="flex items-center justify-between text-xs"
|
||||
>
|
||||
{dossier.tenancies.map((r) => (
|
||||
<div key={r.tenancyId} className="flex items-center justify-between text-xs">
|
||||
<span>Berth {r.mooringNumber}</span>
|
||||
<select
|
||||
className="rounded border bg-background px-2 py-1 text-xs"
|
||||
value={reservationDecisions[r.reservationId] ?? 'cancel'}
|
||||
value={tenancyDecisions[r.tenancyId] ?? 'cancel'}
|
||||
onChange={(e) =>
|
||||
setReservationDecisions((prev) => ({
|
||||
setTenancyDecisions((prev) => ({
|
||||
...prev,
|
||||
[r.reservationId]: e.target.value as ReservationAction,
|
||||
[r.tenancyId]: e.target.value as TenancyAction,
|
||||
}))
|
||||
}
|
||||
>
|
||||
<option value="cancel">Cancel reservation</option>
|
||||
<option value="cancel">Cancel tenancy</option>
|
||||
</select>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user