Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 82f0a34

Browse files
committed
fix: validate resources and duration fields when both deleted.
1 parent 52c8fb6 commit 82f0a34

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/routes/CreateNewTeam/components/TeamDetailsModal/index.jsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { deleteSearchedRole } from "../../actions";
1818
import IconCrossLight from "../../../../assets/images/icon-cross-light.svg";
1919
import "./styles.module.scss";
2020
import NumberInput from "components/NumberInput";
21-
import validator from "./utils/validator";
21+
import { validator, validateExists } from "./utils/validator";
2222

2323
const Error = ({ name }) => {
2424
const {
@@ -137,7 +137,11 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
137137
<tr styleName="role-row" key={id}>
138138
<td>{name}</td>
139139
<td>
140-
<Field name={`${id}.numberOfResources`} initialValue="3">
140+
<Field
141+
validate={validateExists}
142+
name={`${id}.numberOfResources`}
143+
initialValue="3"
144+
>
141145
{({ input, meta }) => (
142146
<NumberInput
143147
name={input.name}
@@ -153,7 +157,11 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
153157
<Error name={`${id}.numberOfResources`} />
154158
</td>
155159
<td>
156-
<Field name={`${id}.durationWeeks`} initialValue="20">
160+
<Field
161+
validate={validateExists}
162+
name={`${id}.durationWeeks`}
163+
initialValue="20"
164+
>
157165
{({ input, meta }) => (
158166
<NumberInput
159167
name={input.name}

src/routes/CreateNewTeam/components/TeamDetailsModal/utils/validator.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const validateNumber = (number) => {
99
const converted = Number(number);
1010

1111
if (
12-
!number ||
1312
Number.isNaN(converted) ||
1413
converted !== Math.floor(converted) ||
1514
converted < 1
@@ -57,4 +56,8 @@ const validator = (values) => {
5756
return errors;
5857
};
5958

60-
export default validator;
59+
const validateExists = (value) => {
60+
return value === undefined ? "Please enter a positive integer" : undefined;
61+
};
62+
63+
export { validator, validateExists };

0 commit comments

Comments
 (0)