diff --git a/src/components/berths/berth-reservations-tab.tsx b/src/components/berths/berth-reservations-tab.tsx new file mode 100644 index 0000000..a5c4ae8 --- /dev/null +++ b/src/components/berths/berth-reservations-tab.tsx @@ -0,0 +1,90 @@ +'use client'; + +import { useState } from 'react'; +import { useParams } from 'next/navigation'; +import { useQuery } from '@tanstack/react-query'; +import { Plus } from 'lucide-react'; + +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 { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation'; +import { apiFetch } from '@/lib/api/client'; + +interface BerthReservationsTabProps { + berthId: string; +} + +export function BerthReservationsTab({ berthId }: BerthReservationsTabProps) { + 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'], + queryFn: () => + apiFetch( + `/api/v1/berths/${berthId}/reservations?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']], + }); + + const reservations = data?.data ?? []; + const active = reservations.find((r) => r.status === 'active'); + const history = reservations.filter((r) => r.status !== 'active'); + + return ( +
No active reservation.
+ )} +Loading…
+ ) : history.length === 0 ? ( +