diff --git a/backend/main.py b/backend/main.py index 7b27575..e26e95c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -137,12 +137,12 @@ dewars = [ number_of_samples=33, return_address=[return_addresses[1]], contact_person=[contacts[1]], - status='In Transit', + status='In Preparation', ready_date='2023-10-01', shipping_date='2023-10-02', arrival_date='2023-10-04', - shippingStatus='In Transit', - arrivalStatus='Pending', + shippingStatus='not shipped', + arrivalStatus='not arrived', qrcode='QR123DEWAR002' ), Dewar( @@ -158,6 +158,32 @@ dewars = [ arrivalStatus='Pending', qrcode='QR123DEWAR003' ), + Dewar( + id='DEWAR004', + dewar_name='Dewar Four', + tracking_number='', + number_of_pucks=4, + number_of_samples=47, + return_address=[return_addresses[0]], + contact_person=[contacts[2]], + status='In Preparation', + shippingStatus='not shipped', + arrivalStatus='not arrived', + qrcode='QR123DEWAR003' + ), + Dewar( + id='DEWAR005', + dewar_name='Dewar Five', + tracking_number='', + number_of_pucks=4, + number_of_samples=47, + return_address=[return_addresses[0]], + contact_person=[contacts[2]], + status='Ready for Shipping', + shippingStatus='shipped', + arrivalStatus='not arrived', + qrcode='QR123DEWAR003' + ), ] # Proposal data inspired by the Lord of the Rings @@ -171,11 +197,15 @@ proposals = [ # Example: Attach specific Dewars by their ids to shipments specific_dewar_ids1 = ['DEWAR003'] # The IDs of the Dewars you want to attach to the first shipment -specific_dewar_ids2 = ['DEWAR001', 'DEWAR002'] # The IDs of the Dewars you want to attach to the second shipment +specific_dewar_ids2 = ['DEWAR001', 'DEWAR002'] +specific_dewar_ids3 = ['DEWAR003', 'DEWAR004', 'DEWAR005'] +# The IDs of the Dewars you want to attach to the second shipment # Find the Dewars with the matching ids specific_dewars1 = [dewar for dewar in dewars if dewar.id in specific_dewar_ids1] specific_dewars2 = [dewar for dewar in dewars if dewar.id in specific_dewar_ids2] +specific_dewars3 = [dewar for dewar in dewars if dewar.id in specific_dewar_ids3] + # Define shipments with the selected Dewars shipments = [ @@ -200,7 +230,19 @@ shipments = [ return_address=[return_addresses[1]], # Changed index to a valid one comments='Contains the one ring', dewars=specific_dewars2 # Attach specific Dewars for this shipment + ), + Shipment( + shipment_id='SHIPMORDOR3', + shipment_date='2024-10-28', + shipment_name='Shipment from Mordor', + shipment_status='In Transit', + contact_person=[contacts[4]], + proposal_number=[proposals[3]], + return_address=[return_addresses[0]], # Changed index to a valid one + comments='Contains the one ring', + dewars=specific_dewars3 ) + ] @app.get("/contacts", response_model=List[ContactPerson]) @@ -239,13 +281,6 @@ async def create_dewar(shipment: Dewar): return dewars # Return the list of all dewars - -# Endpoint to get the number of dewars in each shipment -@app.get("/shipment_dewars") -async def get_shipment_dewars(): - return [{"shipment_id": shipment.shipment_id, "number_of_dewars": shipment.get_number_of_dewars()} for shipment in - shipments] - @app.get("/shipment_contact_persons") async def get_shipment_contact_persons(): return [{"shipment_id": shipment.shipment_id, "contact_person": shipment.get_shipment_contact_persons()} for shipment in diff --git a/frontend/src/components/ShipmentPanel.tsx b/frontend/src/components/ShipmentPanel.tsx index 3771d25..3b20c3b 100644 --- a/frontend/src/components/ShipmentPanel.tsx +++ b/frontend/src/components/ShipmentPanel.tsx @@ -1,16 +1,14 @@ -// ShipmentPanel.tsx - import * as React from 'react'; import { useEffect, useState } 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'; // Ensure the file extension is correct +import UploadDialog from './UploadDialog'; +import { Shipment_Input, DefaultService, OpenAPI, Dewar } from '../../openapi'; // Import relevant types import { SxProps } from '@mui/material'; -import bottleGrey from '../assets/icons/bottle-svgrepo-com-grey.svg'; -import bottleYellow from '../assets/icons/bottle-svgrepo-com-yellow.svg'; -import bottleGreen from '../assets/icons/bottle-svgrepo-com-green.svg'; -import bottleRed from '../assets/icons/bottle-svgrepo-com-red.svg'; -import { Shipment_Input, DefaultService, OpenAPI } from '../../openapi'; +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; @@ -81,6 +79,10 @@ const ShipmentPanel: React.FC = ({ setCreatingShipment, sele const closeUploadDialog = () => setUploadDialogOpen(false); const refreshShipments = () => fetchAndSetShipments(); + const getNumberOfDewars = (shipment: Shipment_Input): number => { + return shipment.dewars ? shipment.dewars.length : 0; + }; + return ( {error && {error}} @@ -151,14 +153,14 @@ const ShipmentPanel: React.FC = ({ setCreatingShipment, sele borderRadius: '50%', padding: '0 2px', }}> - {shipment.number_of_dewars} + {getNumberOfDewars(shipment)} {/* Calculate number of dewars */}
{shipment.shipment_name}
{shipment.shipment_date}
- Total Pucks: {shipment.dewars.reduce((total, dewar) => total + dewar.number_of_pucks, 0)} + Total Pucks: {shipment.dewars.reduce((total, dewar: Dewar) => total + dewar.number_of_pucks, 0)}