diff --git a/src/components/BlenderLogbook/components/FillingTile.tsx b/src/components/BlenderLogbook/components/FillingTile.tsx index 5fc5517..b7b0e85 100644 --- a/src/components/BlenderLogbook/components/FillingTile.tsx +++ b/src/components/BlenderLogbook/components/FillingTile.tsx @@ -49,16 +49,10 @@ const FillingEventRowComponent: React.FC = ({ (sc) => sc.id === storageCylinderId ); - // User has managed to select cylinder that has invalid id from the dropdown menu - // => programming error - if (storageCylinder === undefined) { - throw new Error('Storage cylinder not found!'); - } - const gasPriceEurCents = gases.find( - (price) => price.gasId === storageCylinder.gasId + (price) => price.gasId === storageCylinder?.gasId )?.priceEurCents; - const storageCylinderVolume = storageCylinder.volume; + const storageCylinderVolume = storageCylinder?.volume; // Calculate price and consumption when row values change useEffect(() => { @@ -66,7 +60,7 @@ const FillingEventRowComponent: React.FC = ({ `fillingEventRows.${index}.priceEurCents`, formatEurCentsToEur( calculateGasConsumption( - storageCylinderVolume, + storageCylinderVolume ?? 0, startPressure ?? 0, endPressure ?? 0 ) * (gasPriceEurCents ?? 0) @@ -85,7 +79,7 @@ const FillingEventRowComponent: React.FC = ({ setFieldValue( `fillingEventRows.${index}.consumption`, calculateGasConsumption( - storageCylinderVolume, + storageCylinderVolume ?? 0, startPressure ?? 0, endPressure ?? 0 ) @@ -107,7 +101,13 @@ const FillingEventRowComponent: React.FC = ({ errorText={errors.fillingEventRows?.at(index)?.storageCylinderId} > {storageCylinders.map((sc) => ( -