updated models and schemas for shipments and dewars

This commit is contained in:
GotthardG
2024-11-11 11:43:49 +01:00
parent d5c7e7e6f3
commit 701c42c0dd
8 changed files with 96 additions and 91 deletions

View File

@ -79,7 +79,7 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
const confirmed = window.confirm('Are you sure you want to delete this dewar?');
if (confirmed && selectedShipment) {
try {
const updatedShipment = await ShipmentsService.removeDewarFromShipmentShipmentsShipmentIdRemoveDewarDewarIdDelete(selectedShipment.shipment_id, dewarId);
const updatedShipment = await ShipmentsService.removeDewarFromShipmentShipmentsShipmentIdRemoveDewarDewarIdDelete(selectedShipment.id, dewarId);
setSelectedShipment(updatedShipment);
setLocalSelectedDewar(null);
refreshShipments();
@ -116,7 +116,7 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
const createdDewar = await DewarsService.createDewarDewarsPost(newDewarToPost);
if (createdDewar && selectedShipment) {
const updatedShipment = await ShipmentsService.addDewarToShipmentShipmentsShipmentIdAddDewarPost(selectedShipment.shipment_id, createdDewar.id);
const updatedShipment = await ShipmentsService.addDewarToShipmentShipmentsShipmentIdAddDewarPost(selectedShipment.id, createdDewar.id);
setSelectedShipment(updatedShipment);
setIsAddingDewar(false);
setNewDewar(initialNewDewarState);
@ -137,12 +137,12 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
};
const handleSaveComments = async () => {
if (selectedShipment && selectedShipment.shipment_id) {
if (selectedShipment && selectedShipment.id) {
try {
const payload = { comments };
// Assuming `updateShipmentCommentsShipmentsShipmentIdCommentsPut` only needs the shipment ID
const updatedShipment = await ShipmentsService.updateShipmentCommentsShipmentsShipmentIdCommentsPut(selectedShipment.shipment_id, payload);
const updatedShipment = await ShipmentsService.updateShipmentCommentsShipmentsShipmentIdCommentsPut(selectedShipment.id, payload);
setSelectedShipment({ ...selectedShipment, comments: updatedShipment.comments });
setInitialComments(comments);
@ -344,7 +344,7 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
initialReturnAddresses={localSelectedDewar?.return_address ? [localSelectedDewar.return_address] : []} // Focus on dewar return address
defaultContactPerson={localSelectedDewar?.contact_person}
defaultReturnAddress={localSelectedDewar?.return_address}
shipmentId={selectedShipment?.shipment_id || ''}
shipmentId={selectedShipment?.id || ''}
refreshShipments={refreshShipments}
/>
</Box>

View File

@ -41,7 +41,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
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);
await deleteShipment(selectedShipment.id);
}
}
};
@ -58,7 +58,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
};
const handleShipmentSelection = (shipment: ShipmentsService) => {
const isSelected = selectedShipment?.shipment_id === shipment.shipment_id;
const isSelected = selectedShipment?.id === shipment.id;
const updatedShipment = isSelected ? null : shipment;
console.log("Shipment selected:", updatedShipment); // debug log
selectShipment(updatedShipment);
@ -102,7 +102,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
</Box>
{shipments.map((shipment) => (
<Button
key={shipment.shipment_id}
key={shipment.id}
onClick={() => handleShipmentSelection(shipment)}
sx={{
width: '100%',
@ -117,12 +117,12 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: selectedShipment?.shipment_id === shipment.shipment_id ? '#52893e' : '#424242',
backgroundColor: selectedShipment?.id === shipment.id ? '#52893e' : '#424242',
'&:hover': {
backgroundColor: selectedShipment?.shipment_id === shipment.shipment_id ? '#9aca8c' : '#616161',
backgroundColor: selectedShipment?.id === shipment.id ? '#9aca8c' : '#616161',
},
'&:active': {
backgroundColor: selectedShipment?.shipment_id === shipment.shipment_id ? '#915151' : '#212121',
backgroundColor: selectedShipment?.id === shipment.id ? '#915151' : '#212121',
},
}}
>
@ -160,7 +160,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
</Box>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
{selectedShipment?.shipment_id === shipment.shipment_id && (
{selectedShipment?.id === shipment.id && (
<>
<IconButton
onClick={openUploadDialog}