diff --git a/client/src/pages/spools/create.tsx b/client/src/pages/spools/create.tsx index 02f36ae..c7059a7 100644 --- a/client/src/pages/spools/create.tsx +++ b/client/src/pages/spools/create.tsx @@ -1,7 +1,7 @@ import React, {useState} from "react"; import {IResourceComponentsProps, useTranslate} from "@refinedev/core"; import {Create, useForm, useSelect} from "@refinedev/antd"; -import {Form, Input, DatePicker, Select, InputNumber} from "antd"; +import {Form, Input, DatePicker, Select, InputNumber, Radio} from "antd"; import dayjs from "dayjs"; import TextArea from "antd/es/input/TextArea"; import {IFilament} from "../filaments/model"; @@ -55,6 +55,7 @@ export const SpoolCreate: React.FC a.label.localeCompare(b.label, undefined, {sensitivity: "base"})); + const [weightToEnter, setWeightToEnter] = useState(1); const [usedWeight, setUsedWeight] = useState(0); const selectedFilamentID = Form.useWatch('filament_id', form); @@ -64,6 +65,21 @@ export const SpoolCreate: React.FC { + const newSelectedFilament = filamentOptions?.find((obj) => { + return obj.value === newID; + }); + const newFilamentWeight = newSelectedFilament?.weight || 0; + const newSpoolWeight = newSelectedFilament?.spool_weight || 0; + + if (!(newFilamentWeight && newSpoolWeight)) { + setWeightToEnter(2); + } + if (!newFilamentWeight) { + setWeightToEnter(1); + } + }; + const weightChange = (weight: number) => { setUsedWeight(weight); form.setFieldsValue( @@ -122,8 +138,12 @@ export const SpoolCreate: React.FC typeof option?.label === "string" && option?.label.toLowerCase().includes(input.toLowerCase()) } + onChange={(value) => { + filamentChange(value); + }} /> + + + { + setWeightToEnter(value.target.value); + }} + defaultValue={1} + value={weightToEnter} + > + {t("spool.fields.used_weight")} + {t("spool.fields.remaining_weight")} + {t("spool.fields.measured_weight")} + + + { weightChange(value ?? 0); @@ -164,7 +199,7 @@ export const SpoolCreate: React.FC { weightChange(filamentWeight - (value ?? 0)); @@ -183,7 +218,7 @@ export const SpoolCreate: React.FC { weightChange(filamentWeight - ((value ?? 0) - spoolWeight));