Skip to content

Commit

Permalink
Units of type suffix should have a suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Bodin committed Oct 4, 2023
1 parent 6d21ed3 commit 63f1472
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/client/app/components/unit/CreateUnitModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ export default function CreateUnitModalComponent() {
/* Create Unit Validation:
Name cannot be blank
Sec in Rate must be greater than zero
If Unit is type Suffix a 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
Expand Down Expand Up @@ -238,7 +240,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 === ''}/>
<FormFeedback>
<FormattedMessage id="error.required" />
</FormFeedback>
</FormGroup></Col>
</Row>
{/* Note input */}
Expand Down

0 comments on commit 63f1472

Please sign in to comment.