Integration of sqlite3 database now fully functional with all implemented functions
This commit is contained in:
@ -12,7 +12,7 @@ import QRCode from 'react-qr-code';
|
||||
import {
|
||||
ContactPerson,
|
||||
Address,
|
||||
Dewar, ContactsService, AddressesService, ShipmentsService,
|
||||
Dewar, ContactsService, AddressesService, ShipmentsService, DewarsService,
|
||||
} from '../../openapi';
|
||||
|
||||
interface DewarDetailsProps {
|
||||
@ -200,10 +200,10 @@ const DewarDetails: React.FC<DewarDetailsProps> = ({
|
||||
const handleSaveChanges = async () => {
|
||||
console.log('handleSaveChanges called');
|
||||
|
||||
const formatDate = (dateString: string | undefined): string => {
|
||||
if (!dateString) return '';
|
||||
const formatDate = (dateString: string | undefined): string | null => {
|
||||
if (!dateString) return null;
|
||||
const date = new Date(dateString);
|
||||
if (isNaN(date.getTime())) return '';
|
||||
if (isNaN(date.getTime())) return null;
|
||||
return date.toISOString().split('T')[0];
|
||||
};
|
||||
|
||||
@ -231,7 +231,7 @@ const DewarDetails: React.FC<DewarDetailsProps> = ({
|
||||
}
|
||||
|
||||
const updatedDewar = {
|
||||
id: dewar.id,
|
||||
dewar_id: dewar.id,
|
||||
dewar_name: dewar.dewar_name,
|
||||
tracking_number: dewar.tracking_number,
|
||||
number_of_pucks: dewar.number_of_pucks,
|
||||
@ -243,7 +243,7 @@ const DewarDetails: React.FC<DewarDetailsProps> = ({
|
||||
returning_date: dewar.returning_date,
|
||||
qrcode: dewar.qrcode,
|
||||
return_address_id: selectedReturnAddress,
|
||||
contact_person_id: selectedContactPerson,
|
||||
contact_person_id: selectedContactPerson, // Set dewar-specific contact person
|
||||
};
|
||||
|
||||
const payload = {
|
||||
@ -252,26 +252,29 @@ const DewarDetails: React.FC<DewarDetailsProps> = ({
|
||||
shipment_date: existingShipment.shipment_date,
|
||||
shipment_status: existingShipment.shipment_status,
|
||||
comments: existingShipment.comments,
|
||||
contact_person_id: selectedContactPerson,
|
||||
contact_person_id: existingShipment.contact_person.id, // Keep main shipment contact person
|
||||
return_address_id: selectedReturnAddress,
|
||||
proposal_id: existingShipment.proposal?.id,
|
||||
dewars: [
|
||||
updatedDewar
|
||||
],
|
||||
dewars: [updatedDewar], // Updated dewars array
|
||||
};
|
||||
|
||||
console.log('Payload for update:', JSON.stringify(payload, null, 2));
|
||||
|
||||
try {
|
||||
await ShipmentsService.updateShipmentShipmentsShipmentsShipmentIdPut(shipmentId, payload);
|
||||
await ShipmentsService.updateShipmentShipmentsShipmentIdPut(shipmentId, payload);
|
||||
setFeedbackMessage('Changes saved successfully.');
|
||||
setChangesMade(false);
|
||||
refreshShipments();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('Update Shipment Error:', error);
|
||||
setFeedbackMessage('Failed to save changes. Please try again later.');
|
||||
|
||||
if (error.response && error.response.data) {
|
||||
setFeedbackMessage(`Failed to save shipment. Validation errors: ${JSON.stringify(error.response.data)}`);
|
||||
} else {
|
||||
setFeedbackMessage('Failed to save changes. Please try again later.');
|
||||
}
|
||||
setOpenSnackbar(true);
|
||||
}
|
||||
setOpenSnackbar(true);
|
||||
};
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user