import { useEffect, useRef, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Alert, Badge, Button, Card, Divider, Group, Paper, SimpleGrid, Stack, Text, ThemeIcon, Title, rem, } from '@mantine/core'; import { IconAnchor, IconCheck, IconCircleCheck, IconAlertCircle, IconFileDescription, IconShieldCheck, IconCertificate, IconDownload, IconInfoCircle, IconClockHour4, IconTransferIn, } from '@tabler/icons-react'; import { useApiMutation } from '@ema-platform/api'; import { authStorage } from '@ema-platform/auth'; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- type VesselRegStatus = 'Pending' | 'Under Review' | 'Approved' | 'Rejected' | 'Correction Required'; type VesselCategory = 'Inland Waterway Vessel' | 'Sea-going Vessel (International)'; type RenewalStatus = 'Valid' | 'Due Soon' | 'Overdue' | 'Not Applicable'; interface VesselRegistration { id: string; vesselName: string; category: VesselCategory; vesselType: string; flagState: string; portOfRegistry: string; capacityLabel: 'Passenger Capacity' | 'Gross Tonnage (GT)'; capacityValue: number; vesselLengthM: number; imoOrHullNumber: string; ownerName: string; status: VesselRegStatus; submittedDate: string; approvalDate: string | null; remarks: string; renewalStatus: RenewalStatus; expiryDate: string | null; } const STATUS_COLOR: Record = { Pending: 'gray', 'Under Review': 'yellow', Approved: 'teal', Rejected: 'red', 'Correction Required': 'orange', }; // Inland vessel certificates (1) const INLAND_CERTIFICATES = [ { label: 'Inland Vessel Registration Certificate', description: 'Official government registration document for inland waterway operation' }, ]; // Sea-going vessel certificates (4) const SEAGOING_CERTIFICATES = [ { label: 'Certificate of Nationality', description: 'Certifies the vessel\'s nationality and right to fly the Ethiopian flag' }, { label: 'Certificate of Ownership', description: 'Confirms legal ownership of the vessel' }, { label: 'Certificate of Registration', description: 'Official registration document for international sea-going operation' }, { label: 'Minimum Safe Manning Certificate', description: 'Specifies the minimum crew required for safe operation of the vessel' }, ]; // --------------------------------------------------------------------------- // Requirements list // --------------------------------------------------------------------------- function RequirementItem({ label }: { label: string }) { return ( {label} ); } // --------------------------------------------------------------------------- // Certificate card (shown after approval) // --------------------------------------------------------------------------- function CertificateCard({ label, description }: { label: string; description: string }) { return (
{label} {description}
); } // --------------------------------------------------------------------------- // Component // --------------------------------------------------------------------------- export function VesselRegistrationPage() { const navigate = useNavigate(); const [registration, setRegistration] = useState(null); const [fetchTrigger] = useApiMutation(); const fetched = useRef(false); useEffect(() => { const profileId = authStorage.getProfileId(); if (!profileId || fetched.current) return; fetched.current = true; fetchTrigger({ url: '/vessel-registrations/my', method: 'GET' }) .unwrap() .then((data) => setRegistration(data)) .catch(() => {/* no registration yet */}); }, [fetchTrigger]); const certs = registration?.category === 'Sea-going Vessel (International)' ? SEAGOING_CERTIFICATES : INLAND_CERTIFICATES; return (
Vessel Registration Register your vessel with the Ethiopian Maritime Authority
{/* ── No registration yet ───────────────────────────────────────── */} {!registration && ( <>
Register Your Vessel Obtain official registration for inland waterway or sea-going vessels
Requirements
About Vessel Registration Registration is valid for 5 years from the date of approval. After approval, inland vessels receive an Inland Vessel Registration Certificate, while sea-going vessels receive four certificates: Certificate of Nationality, Certificate of Ownership, Certificate of Registration, and Minimum Safe Manning Certificate. )} {/* ── Registration exists ──────────────────────────────────────── */} {registration && ( <> {/* Renewal alert */} {registration.renewalStatus === 'Due Soon' && ( } color="orange" title="Renewal Due Soon" > Your vessel registration expires on {registration.expiryDate}. Please initiate renewal to avoid expiry. )} {registration.renewalStatus === 'Overdue' && ( } color="red" title="Registration Expired"> Your vessel registration expired on {registration.expiryDate}. Immediate renewal is required. )} {/* Status card */}
{registration.vesselName} {registration.id}
{registration.status}
{[ { label: 'Category', value: registration.category }, { label: 'Vessel Type', value: registration.vesselType }, { label: 'Flag State', value: registration.flagState }, { label: 'Port of Registry', value: registration.portOfRegistry }, { label: registration.capacityLabel, value: String(registration.capacityValue) }, { label: 'Submitted', value: registration.submittedDate }, ].map((row) => (
{row.label} {row.value || '—'}
))}
{registration.remarks && ( <> Officer Remarks {registration.remarks} )}
{/* Timeline / status info */} {registration.status !== 'Approved' && ( Application Status {[ { label: 'Submitted', done: true }, { label: 'Under Review', done: registration.status !== 'Pending' }, // Always pending here: this whole block only renders while the // registration is *not* approved, so the step cannot be done. { label: 'Approved', done: false }, ].map((step) => ( {step.label} ))} )} {/* Transfer ownership — only when approved */} {registration.status === 'Approved' && (
Transfer Ownership Transfer this vessel to a new owner
)} {/* Certificates section — shown after approval */} {registration.status === 'Approved' && (
{registration.category === 'Sea-going Vessel (International)' ? 'Issued Certificates (4)' : 'Issued Certificate'} } mb="md"> Your vessel registration has been approved. You may download your certificate(s) below. {certs.map((cert) => ( ))}
)} )}
); }