/* eslint-disable @next/next/no-img-element */ /* eslint-disable jsx-a11y/alt-text */ /* eslint-disable @typescript-eslint/no-explicit-any */ import Link from 'next/link'; import React from 'react' import { dateFormaShipmentCard, formatDate, getSettlementServiceType, getShipmentStatusInfo, returnShipmentDetails, shipmentModeOfTransportIconsById, truncateWithTooltip } from '../../../../lib/Helper'; import { ShipmentStatus } from '@/Constant/enums'; const ShipmentCard = ({ shipments = [], handleEdit, handleView, handlePrint }: any) => { const [showDropdown, setShowDropdown] = React.useState(null); const dropdownContainerRefs = React.useRef< Record >({}); React.useEffect(() => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const handleClickOutside = (event: MouseEvent) => { const isClickInside = Object.values(dropdownContainerRefs.current).some( (ref) => ref && ref.contains(event.target as Node) ); if (!isClickInside) { setShowDropdown(null); } }; }) React.useEffect(() => { const handleClickOutside = (event: MouseEvent) => { const isClickInside = Object.values(dropdownContainerRefs.current).some( (ref) => ref && ref.contains(event.target as Node) ); if (!isClickInside) { setShowDropdown(null); } }; // Attach listener document.addEventListener("mousedown", handleClickOutside); // Cleanup return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, []); const toggleDropdown = (id: string) => { setShowDropdown(showDropdown === id ? null : id); }; return ( <> {shipments?.map((shipment: any, index: any) => (
{ dropdownContainerRefs.current[shipment?.id] = el; }} >
{shipment?.status?.name} {getSettlementServiceType(shipment?.shipmentTypeForCustomer?.id, shipment)?.text}{" "} {shipmentModeOfTransportIconsById(shipment?.mode?.id || null)}
{ e.preventDefault(); toggleDropdown(shipment?.id); }} className="ms-auto" > {showDropdown === shipment?.id && (
e.stopPropagation()} > {shipment?.status?.id === ShipmentStatus?.Created ? ( ) : ''} {false && ( )}
)}
{ e.preventDefault(); e.stopPropagation(); handleView(shipment) }} className="font-500 font-14 mb-0"> {shipment?.shipmentId}

{shipment?.shipmentNumber ? ` - ${truncateWithTooltip(shipment?.shipmentNumber)?.text}` : ''}

{returnShipmentDetails(shipment)?._name}

{shipment?.vesselName ? `(${shipment?.vesselName})` : ''}
{/*

Vessael Name: Maersk Mc-Kinney Miller

*/}

{returnShipmentDetails(shipment)?._address ?? ''}

{/*

{shipment?.shipmentTypeForCustomer?.name}{" "}

*/}

{dateFormaShipmentCard(shipment?.shipmentDate)}
Shipment Date

{dateFormaShipmentCard(shipment?.etaDate)}
ETA Date

{/*

{shipment?.status?.name}{" "}

*/}

{formatDate(shipment?.shipmentDate || "")}{" "}

{/*
{formatDate(shipment?.shipmentDate || "")} {" "}
*/}
{formatDate(shipment?.shipmentDate || "")} {" "}
{/*
200
*/}
))} ) } export default ShipmentCard