diff --git a/src/client/app/components/unit/CreateUnitModalComponent.tsx b/src/client/app/components/unit/CreateUnitModalComponent.tsx index 57c265dad..66c149093 100644 --- a/src/client/app/components/unit/CreateUnitModalComponent.tsx +++ b/src/client/app/components/unit/CreateUnitModalComponent.tsx @@ -76,6 +76,10 @@ export default function CreateUnitModalComponent() { setState({ ...state, [e.target.name]: JSON.parse(e.target.value) }); }; + const handleNumberChange = (e: React.ChangeEvent) => { + setState({ ...state, [e.target.name]: Number(e.target.value) }); + }; + /** * Updates the rate (both custom and regular state) including setting if custom. * @param newRate The new rate to set. @@ -129,9 +133,6 @@ export default function CreateUnitModalComponent() { // Keeps canSave state up to date. Checks if valid and if edit made. useEffect(() => { - setValidUnit(state.name !== '' && state.secInRate > 0 && - (state.typeOfUnit !== UnitType.suffix || state.suffix !== '') && (state?.minVal < MIN_VAL || state?.minVal > state?.maxVal)); - }, [state.name, state.secInRate, state.typeOfUnit, state.suffix]); // This checks: // - Name cannot be blank @@ -140,6 +141,7 @@ export default function CreateUnitModalComponent() { // - The custom rate is a positive integer const validUnit = state.name !== '' && (state.typeOfUnit !== UnitType.suffix || state.suffix !== '') && state.secInRate !== Number(CUSTOM_INPUT) + && (state?.minVal < MIN_VAL || state?.minVal > state?.maxVal) && customRateValid(Number(state.secInRate)); setCanSave(validUnit); }, [state]); @@ -431,59 +433,59 @@ export default function CreateUnitModalComponent() { - - {/* minVal input */} - - - handleNumberChange(e)} - min={MIN_VAL} - max={state.maxVal} - defaultValue={state.minVal} - invalid={state?.minVal < MIN_VAL || state?.minVal > state?.maxVal} /> - - - - - {/* maxVal input */} - - - handleNumberChange(e)} - min={state.minVal} - max={MAX_VAL} - defaultValue={state.maxVal} - invalid={state?.maxVal > MAX_VAL || state?.minVal > state?.maxVal} /> - - - - - - - {/* DisableChecks input */} - - - + {/* minVal input */} + + + handleNumberChange(e)} + min={MIN_VAL} + max={state.maxVal} + defaultValue={state.minVal} + invalid={state?.minVal < MIN_VAL || state?.minVal > state?.maxVal} /> + + + + + {/* maxVal input */} + + + handleNumberChange(e)} + min={state.minVal} + max={MAX_VAL} + defaultValue={state.maxVal} + invalid={state?.maxVal > MAX_VAL || state?.minVal > state?.maxVal} /> + + + + + + + {/* DisableChecks input */} + + + handleStringChange(e)} + defaultValue={state.disableChecks}> + {Object.keys(DisableChecksType).map(key => { + return (); + })} + + + + {/* Note input */} + + + handleStringChange(e)} - defaultValue={state.disableChecks}> - {Object.keys(DisableChecksType).map(key => { - return (); - })} - - - - {/* Note input */} - - - handleStringChange(e)} - value={state.note} /> - - + value={state.note} /> + + {/* Hides the modal */}