/** * Bookings List Page * * Display all bookings with filters and search */ 'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { bookingsApi } from '@/lib/api'; import Link from 'next/link'; export default function BookingsListPage() { const [searchTerm, setSearchTerm] = useState(''); const [statusFilter, setStatusFilter] = useState(''); const [page, setPage] = useState(1); const { data, isLoading } = useQuery({ queryKey: ['bookings', page, statusFilter, searchTerm], queryFn: () => bookingsApi.list({ page, limit: 10, status: statusFilter || undefined, search: searchTerm || undefined, }), }); const statusOptions = [ { value: '', label: 'All Statuses' }, { value: 'draft', label: 'Draft' }, { value: 'pending', label: 'Pending' }, { value: 'confirmed', label: 'Confirmed' }, { value: 'in_transit', label: 'In Transit' }, { value: 'delivered', label: 'Delivered' }, { value: 'cancelled', label: 'Cancelled' }, ]; const getStatusColor = (status: string) => { const colors: Record = { draft: 'bg-gray-100 text-gray-800', pending: 'bg-yellow-100 text-yellow-800', confirmed: 'bg-green-100 text-green-800', in_transit: 'bg-blue-100 text-blue-800', delivered: 'bg-purple-100 text-purple-800', cancelled: 'bg-red-100 text-red-800', }; return colors[status] || 'bg-gray-100 text-gray-800'; }; return (
{/* Header */}

Bookings

Manage and track your shipments

New Booking
{/* Filters */}
setSearchTerm(e.target.value)} className="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md leading-5 bg-white placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-1 focus:ring-blue-500 focus:border-blue-500 sm:text-sm" placeholder="Search by booking number or description..." />
{/* Bookings Table */}
{isLoading ? (
Loading bookings...
) : data?.data && data.data.length > 0 ? ( <>
{data.data.map((booking) => ( ))}
Booking Number Cargo Status Created Actions
{booking.bookingNumber}
{booking.cargoDescription}
{booking.containers?.length || 0} container(s)
{booking.status} {new Date(booking.createdAt).toLocaleDateString()} View
{/* Pagination */} {data.total > 10 && (

Showing{' '} {(page - 1) * 10 + 1}{' '} to{' '} {Math.min(page * 10, data.total)} {' '} of {data.total}{' '} results

)} ) : (

No bookings found

{searchTerm || statusFilter ? 'Try adjusting your filters' : 'Get started by creating your first booking'}

New Booking
)}
); }