diff --git a/src/components/BlenderLogbook/BlenderLogbook.tsx b/src/components/BlenderLogbook/BlenderLogbook.tsx index aad9198..fdad63c 100644 --- a/src/components/BlenderLogbook/BlenderLogbook.tsx +++ b/src/components/BlenderLogbook/BlenderLogbook.tsx @@ -11,7 +11,7 @@ import { FillingTile } from './components/FillingTile'; import { SavingTile } from './components/SavingTile'; import { AvailableMixtureCompositions, - type AvailableMixtures, + AvailableMixtures, formalizeGasMixture, formatEurToEurCents, } from '../../lib/utils'; @@ -60,7 +60,7 @@ const EMPTY_FILLING_EVENT_BASIC_INFO: FillingEventBasicInfo = { divingCylinderSetId: '', heliumPercentage: '0', gasMixture: AvailableMixtureCompositions[0].id, - oxygenPercentage: '0', + oxygenPercentage: '21', userConfirm: false, compressorId: '', }; @@ -112,11 +112,16 @@ export const NewBlenderFillingEvent: React.FC = ({ .reduce((partialSum, price) => partialSum + price, 0), ); + // Allow user to do pure air fills via Happihäkki page + const filledAir = + values.gasMixture === AvailableMixtures.Nitrox && + values.fillingEventRows.length === 0; + fillEventMutation.mutate( { cylinderSetId: values.divingCylinderSetId, description: values.additionalInformation, - filledAir: false, + filledAir, gasMixture: formalizedGasMixture, price: totalPriceEurCents, storageCylinderUsageArr: diff --git a/src/components/BlenderLogbook/components/FillingTile.tsx b/src/components/BlenderLogbook/components/FillingTile.tsx index 1251880..eb0c5c9 100644 --- a/src/components/BlenderLogbook/components/FillingTile.tsx +++ b/src/components/BlenderLogbook/components/FillingTile.tsx @@ -20,9 +20,7 @@ import { type CommonTileProps, emptyFillingRow } from '../BlenderLogbook'; type FillingEventRowProps = CommonTileProps & { index: number; - replace: (index: number, newValue: unknown) => void; remove: (index: number) => void; - push: (value: unknown) => void; setFieldValue: ( field: string, value: unknown, @@ -30,20 +28,16 @@ type FillingEventRowProps = CommonTileProps & { ) => void; storageCylinders: StorageCylinder[]; gases: GasWithPricing[]; - lastItem: boolean; }; const FillingEventRowComponent: React.FC = ({ index, errors, values, - replace, remove, - push, setFieldValue, storageCylinders, gases, - lastItem, }) => { const startPressure = values.fillingEventRows.at(index)?.startPressure; const endPressure = values.fillingEventRows.at(index)?.endPressure; @@ -106,11 +100,7 @@ const FillingEventRowComponent: React.FC = ({ disabled={values.userConfirm} element={} onClick={() => { - index === 0 && values.fillingEventRows.length === 1 - ? replace(index, { - ...emptyFillingRow(), - }) - : remove(index); + remove(index); }} /> @@ -164,20 +154,6 @@ const FillingEventRowComponent: React.FC = ({ unit="€" /> - {lastItem ? ( -
- { - push({ - ...emptyFillingRow(), - }); - }} - type={ButtonType.button} - text="Lisää uusi rivi" - /> -
- ) : null} ); }; @@ -203,23 +179,32 @@ export const FillingTile: React.FC = ({

Täyttö

- {({ replace, remove, push }) => ( + {({ remove, push }) => ( <> {values.fillingEventRows.map((row, index) => ( ))} +
+ { + push({ + ...emptyFillingRow(), + }); + }} + type={ButtonType.button} + text="Lisää uusi rivi" + /> +
)}
diff --git a/src/components/BlenderLogbook/validation.ts b/src/components/BlenderLogbook/validation.ts index a90c45f..fe76712 100644 --- a/src/components/BlenderLogbook/validation.ts +++ b/src/components/BlenderLogbook/validation.ts @@ -18,31 +18,27 @@ export const BLENDER_FILLING_EVENT_VALIDATION_SCHEMA = yup.object().shape({ .max(100) .optional(), userConfirm: yup.boolean().isTrue(), - fillingEventRows: yup - .array() - .of( - yup.object().shape({ - consumption: yup.number(), - priceEurCents: yup.number(), - startPressure: yup - .number() - .typeError(FIELD_NUMBER) - .min(0) - .required(FIELD_REQUIRED), - endPressure: yup - .number() - .typeError(FIELD_NUMBER) - .min(0) - .required(FIELD_REQUIRED) - .when(['startPressure'], (startPressure, schema) => - schema.max( - startPressure as unknown as number, - 'Loppupaine liian korkea', - ), + fillingEventRows: yup.array().of( + yup.object().shape({ + consumption: yup.number(), + priceEurCents: yup.number(), + startPressure: yup + .number() + .typeError(FIELD_NUMBER) + .min(0) + .required(FIELD_REQUIRED), + endPressure: yup + .number() + .typeError(FIELD_NUMBER) + .min(0) + .required(FIELD_REQUIRED) + .when(['startPressure'], (startPressure, schema) => + schema.max( + startPressure as unknown as number, + 'Loppupaine liian korkea', ), - storageCylinderId: yup.string().required(FIELD_REQUIRED), - }), - ) - .required() - .min(1), + ), + storageCylinderId: yup.string().required(FIELD_REQUIRED), + }), + ), });