diff --git a/src/client/app/components/unit/CreateUnitModalComponent.tsx b/src/client/app/components/unit/CreateUnitModalComponent.tsx index 5a10c9c1d..6bd7c6112 100644 --- a/src/client/app/components/unit/CreateUnitModalComponent.tsx +++ b/src/client/app/components/unit/CreateUnitModalComponent.tsx @@ -69,11 +69,13 @@ export default function CreateUnitModalComponent() { /* Create Unit Validation: Name cannot be blank Sec in Rate must be greater than zero + If type of unit is suffix their must be a suffix */ const [validUnit, setValidUnit] = useState(false); useEffect(() => { - setValidUnit(state.name !== '' && state.secInRate > 0); - }, [state.name, state.secInRate]); + setValidUnit(state.name !== '' && state.secInRate > 0 && + (state.typeOfUnit !== UnitType.suffix || (state.typeOfUnit === UnitType.suffix && state.suffix !== ''))); + }, [state.name, state.secInRate, state.typeOfUnit, state.suffix]); /* End State */ // Reset the state to default values @@ -91,9 +93,13 @@ export default function CreateUnitModalComponent() { // Set default identifier as name if left blank state.identifier = (!state.identifier || state.identifier.length === 0) ? state.name : state.identifier; // set displayable to none if unit is meter - if(state.typeOfUnit == UnitType.meter && state.displayable != DisplayableType.none) { + if (state.typeOfUnit == UnitType.meter && state.displayable != DisplayableType.none) { state.displayable = DisplayableType.none; } + // set unit to suffix if suffix is not empty + if (state.typeOfUnit != UnitType.suffix && state.suffix != '') { + state.typeOfUnit = UnitType.suffix; + } // Add the new unit and update the store dispatch(addUnit(state)); resetState(); @@ -142,7 +148,7 @@ export default function CreateUnitModalComponent() { autoComplete='on' onChange={e => handleStringChange(e)} value={state.name} - invalid={state.name === ''}/> + invalid={state.name === ''} /> @@ -157,11 +163,16 @@ export default function CreateUnitModalComponent() { name='typeOfUnit' type='select' onChange={e => handleStringChange(e)} - value={state.typeOfUnit}> + value={state.typeOfUnit} + invalid={state.typeOfUnit != UnitType.suffix && state.suffix != ''}> {Object.keys(UnitType).map(key => { - return () + return () })} + + + {/* Unit represent input */} @@ -226,7 +237,7 @@ export default function CreateUnitModalComponent() { min='1' invalid={state.secInRate <= 0} /> - + {/* Suffix input */} @@ -238,7 +249,11 @@ export default function CreateUnitModalComponent() { type='text' autoComplete='off' onChange={e => handleStringChange(e)} - value={state.suffix} /> + value={state.suffix} + invalid={state.typeOfUnit === UnitType.suffix && state.suffix === ''} /> + + + {/* Note input */} diff --git a/src/client/app/components/unit/EditUnitModalComponent.tsx b/src/client/app/components/unit/EditUnitModalComponent.tsx index 983f3b6dc..f1766c299 100644 --- a/src/client/app/components/unit/EditUnitModalComponent.tsx +++ b/src/client/app/components/unit/EditUnitModalComponent.tsx @@ -73,11 +73,13 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp Name cannot be blank Sec in Rate must be greater than zero Unit type mismatches checked on submit + If type of unit is suffix their must be a suffix */ const [validUnit, setValidUnit] = useState(false); useEffect(() => { - setValidUnit(state.name !== '' && state.secInRate > 0); - }, [state.name, state.secInRate]); + setValidUnit(state.name !== '' && state.secInRate > 0 && + (state.typeOfUnit !== UnitType.suffix || (state.typeOfUnit === UnitType.suffix && state.suffix !== ''))); + }, [state.name, state.secInRate, state.typeOfUnit, state.suffix]); /* End State */ // Reset the state to default values @@ -151,9 +153,13 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp || (props.unit.secInRate !== state.secInRate && (props.unit.unitRepresent === UnitRepresentType.flow || props.unit.unitRepresent === UnitRepresentType.raw)); // set displayable to none if unit is meter - if(state.typeOfUnit == UnitType.meter && state.displayable != DisplayableType.none) { + if (state.typeOfUnit == UnitType.meter && state.displayable != DisplayableType.none) { state.displayable = DisplayableType.none; } + // set unit to suffix if suffix is not empty + if (state.typeOfUnit != UnitType.suffix && state.suffix != '') { + state.typeOfUnit = UnitType.suffix; + } // Save our changes by dispatching the submitEditedUnit action dispatch(submitEditedUnit(state, shouldRedoCik, shouldRefreshReadingViews)); // The updated unit is not fetched to save time. However, the identifier might have been @@ -217,7 +223,7 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp autoComplete='on' onChange={e => handleStringChange(e)} value={state.name} - invalid={state.name === ''}/> + invalid={state.name === ''} /> @@ -232,11 +238,16 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp name='typeOfUnit' type='select' onChange={e => handleStringChange(e)} - value={state.typeOfUnit}> + value={state.typeOfUnit} + invalid={state.typeOfUnit != UnitType.suffix && state.suffix != ''}> {Object.keys(UnitType).map(key => { - return () + return () })} + + + {/* Unit represent input */} @@ -304,7 +315,7 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp min='1' invalid={state.secInRate <= 0} /> - + {/* Suffix input */} @@ -316,7 +327,11 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp type='text' value={state.suffix} placeholder='Suffix' - onChange={e => handleStringChange(e)} /> + onChange={e => handleStringChange(e)} + invalid={state.typeOfUnit === UnitType.suffix && state.suffix === ''} /> + + + {/* Note input */} diff --git a/src/client/app/translations/data.js b/src/client/app/translations/data.js index 48babe625..3ce1a4acb 100644 --- a/src/client/app/translations/data.js +++ b/src/client/app/translations/data.js @@ -431,6 +431,7 @@ const localeData = { "unit.successfully.edited.unit": "Successfully edited unit.", "unit.suffix": "Suffix:", "unit.type.of.unit": "Type of Unit:", + "unit.type.of.unit.suffix" : "Added suffix will set type of unit to suffix", "units": "Units", "unsaved.warning": "You have unsaved change(s). Are you sure you want to leave?", "update": "update", @@ -882,6 +883,7 @@ const localeData = { "unit.successfully.edited.unit": "(Need French) Successfully edited unit.", "unit.suffix": "(Need French) Suffix:", "unit.type.of.unit": "(Need French) Type of Unit:", + "unit.type.of.unit.suffix" : "(Need French) Added suffix will set type of unit to suffix", "units": "(Need French) Units", "unsaved.warning": "(Need French) You have unsaved change(s). Are you sure you want to leave?", "update": "update", @@ -1333,6 +1335,7 @@ const localeData = { "unit.successfully.edited.unit": "(Need Spanish) Successfully edited unit.", "unit.suffix": "(Need Spanish) Suffix:", "unit.type.of.unit": "(Need Spanish) Type of Unit:", + "unit.type.of.unit.suffix" : "(Need Spanish) Added suffix will set type of unit to suffix", "units": "(Need Spanish) Units", "unsaved.warning": "Tienes cambios sin guardar. ¿Estás seguro que quieres irte?", "update": "Actualizado",