import * as React from 'react'; import { Button, Box, Typography, IconButton } from '@mui/material'; import { Add as AddIcon, Delete as DeleteIcon, UploadFile as UploadFileIcon, Refresh as RefreshIcon } from '@mui/icons-material'; import UploadDialog from './UploadDialog'; import { Shipment_Input, Dewar, DefaultService } from '../../openapi'; import { SxProps } from '@mui/material'; import bottleGrey from '/src/assets/icons/bottle-svgrepo-com-grey.svg' import bottleYellow from '/src/assets/icons/bottle-svgrepo-com-yellow.svg' import bottleGreen from '/src/assets/icons/bottle-svgrepo-com-green.svg' import bottleRed from '/src/assets/icons/bottle-svgrepo-com-red.svg' interface ShipmentPanelProps { setCreatingShipment: (value: boolean) => void; selectedPage?: string; selectShipment: (shipment: Shipment_Input | null) => void; sx?: SxProps; shipments: Shipment_Input[]; refreshShipments: () => void; error: string | null; } const statusIconMap: Record = { 'In Transit': bottleYellow, 'Delivered': bottleGreen, 'Pending': bottleGrey, 'Unknown': bottleRed, }; const ShipmentPanel: React.FC = ({ setCreatingShipment, selectShipment, sx, shipments, refreshShipments, error }) => { const [selectedShipment, setSelectedShipment] = React.useState(null); const [uploadDialogOpen, setUploadDialogOpen] = React.useState(false); const handleDeleteShipment = async () => { if (selectedShipment) { const confirmed = window.confirm(`Are you sure you want to delete the shipment: ${selectedShipment.shipment_name}?`); if (confirmed) { await deleteShipment(selectedShipment.shipment_id); } } }; const deleteShipment = async (shipmentId: string | undefined) => { if (!shipmentId) return; try { // Assumes DefaultService.deleteShipmentShipmentsShipmentIdDelete is already defined await DefaultService.deleteShipmentShipmentsShipmentIdDelete(shipmentId); refreshShipments(); // Call the refresh function after deletion setSelectedShipment(null); } catch (error) { // Handle error } }; const handleShipmentSelection = (shipment: Shipment_Input) => { const isSelected = selectedShipment?.shipment_id === shipment.shipment_id; const updatedShipment = isSelected ? null : shipment; setSelectedShipment(updatedShipment); selectShipment(updatedShipment); }; const openUploadDialog = () => setUploadDialogOpen(true); const closeUploadDialog = () => setUploadDialogOpen(false); const getNumberOfDewars = (shipment: Shipment_Input): number => { return shipment.dewars ? shipment.dewars.length : 0; }; return ( {error && {error}} Shipments {shipments.map((shipment) => ( ))} ); }; export default ShipmentPanel;