'use client'; import { useQuery } from '@tanstack/react-query'; import { getBooking } from '@/lib/api'; import { Link } from '@/i18n/navigation'; import { useParams } from 'next/navigation'; import { useTranslations, useLocale } from 'next-intl'; export default function BookingDetailPage() { const t = useTranslations('dashboard.bookingDetail'); const locale = useLocale(); const dateLocale = locale === 'fr' ? 'fr-FR' : 'en-US'; const params = useParams(); const bookingId = params.id as string; const { data: booking, isLoading } = useQuery({ queryKey: ['booking', bookingId], queryFn: () => getBooking(bookingId), enabled: !!bookingId, }); 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'; }; const getStatusLabel = (status: string) => { const key = `status.${status}`; try { return t(key as any); } catch { return status; } }; const downloadPDF = async () => { try { alert(t('pdfNotImplemented')); console.log('Download PDF for booking:', bookingId); } catch (error) { console.error('Failed to download PDF:', error); } }; if (isLoading) { return (
); } if (!booking) { return (

{t('notFound')}

{t('back')}
); } return (
{t('back')}

{booking.bookingNumber}

{getStatusLabel(booking.status)}

{t('createdOn', { date: new Date(booking.createdAt).toLocaleDateString(dateLocale) })}

{t('cargo.title')}

{t('cargo.description')}
{booking.cargoDescription}
{booking.specialInstructions && (
{t('cargo.specialInstructions')}
{booking.specialInstructions}
)}

{t('containers.title', { count: booking.containers?.length || 0 })}

{booking.containers?.map((container, index) => (

{t('containers.type')}

{container.type}

{container.containerNumber && (

{t('containers.number')}

{container.containerNumber}

)} {container.sealNumber && (

{t('containers.seal')}

{container.sealNumber}

)} {container.vgm && (

{t('containers.vgm')}

{container.vgm}

)}
))}

{t('shipper.title')}

{t('shipper.name')}
{booking.shipper.name}
{t('shipper.contact')}
{booking.shipper.contactName}
{t('shipper.email')}
{booking.shipper.contactEmail}
{t('shipper.phone')}
{booking.shipper.contactPhone}

{t('consignee.title')}

{t('consignee.name')}
{booking.consignee.name}
{t('consignee.contact')}
{booking.consignee.contactName}
{t('consignee.email')}
{booking.consignee.contactEmail}
{t('consignee.phone')}
{booking.consignee.contactPhone}

{t('timeline.title')}

  • {t('timeline.created')}

    {new Date(booking.createdAt).toLocaleString(dateLocale)}

{t('info.title')}

{t('info.bookingId')}
{booking.id}
{t('info.lastUpdated')}
{new Date(booking.updatedAt).toLocaleString(dateLocale)}
); }