From 012c0ecb760c32c00423e61ef1c61547afecd313 Mon Sep 17 00:00:00 2001 From: Michael Baghel <31278895+mbaghel@users.noreply.github.com> Date: Mon, 19 Jul 2021 20:47:20 +0400 Subject: [PATCH] fix: #383 Restrict the duration field on Jobs to a 4 week minimum --- src/constants/index.js | 2 ++ .../CreateNewTeam/components/EditRoleForm/index.jsx | 3 ++- .../components/TeamDetailsModal/utils/validator.js | 5 +++-- src/routes/JobForm/utils.js | 13 +++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/constants/index.js b/src/constants/index.js index f36d2868..8e18b13d 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -367,3 +367,5 @@ export const MAX_ALLOWED_INTERVIEWS = 3; * Custom role names to remove from RoleList component */ export const CUSTOM_ROLE_NAMES = ["custom", "niche"]; + +export const MIN_DURATION = 4; diff --git a/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx b/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx index c2c651dd..959df7d6 100644 --- a/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx +++ b/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx @@ -19,6 +19,7 @@ import { validateMin, composeValidators, } from "./utils/validator"; +import { MIN_DURATION } from "constants"; const Error = ({ name }) => { const { @@ -87,7 +88,7 @@ function EditRoleForm({ onChange, role }) { diff --git a/src/routes/CreateNewTeam/components/TeamDetailsModal/utils/validator.js b/src/routes/CreateNewTeam/components/TeamDetailsModal/utils/validator.js index d5290486..059605e8 100644 --- a/src/routes/CreateNewTeam/components/TeamDetailsModal/utils/validator.js +++ b/src/routes/CreateNewTeam/components/TeamDetailsModal/utils/validator.js @@ -1,4 +1,5 @@ import { isUuid } from "utils/helpers"; +import { MIN_DURATION } from "constants"; const validateName = (name) => { if (!name || name.trim().length === 0) { @@ -25,7 +26,7 @@ const validateGreaterThan = (number, min) => { if (isInvalidNum) return isInvalidNum; return number < min - ? "Talent as a Service engagements have a 4 week minimum commitment." + ? `Talent as a Service engagements have a ${MIN_DURATION} week minimum commitment.` : undefined; }; @@ -46,7 +47,7 @@ const validateMonth = (monthString) => { const validateRole = (role) => { const roleErrors = {}; roleErrors.numberOfResources = validateNumber(role.numberOfResources); - roleErrors.durationWeeks = validateGreaterThan(role.durationWeeks, 4); + roleErrors.durationWeeks = validateGreaterThan(role.durationWeeks, MIN_DURATION); if (role.startMonth) { roleErrors.startMonth = validateMonth(role.startMonth); } diff --git a/src/routes/JobForm/utils.js b/src/routes/JobForm/utils.js index 0ee34141..095e0475 100644 --- a/src/routes/JobForm/utils.js +++ b/src/routes/JobForm/utils.js @@ -11,6 +11,7 @@ import { RESOURCE_TYPE_OPTIONS, FORM_ROW_TYPE, FORM_FIELD_TYPE, + MIN_DURATION, } from "../../constants"; const EDIT_JOB_ROWS = [ @@ -25,6 +26,17 @@ const EDIT_JOB_ROWS = [ { type: FORM_ROW_TYPE.SINGLE, fields: ["status"] }, ]; +const validateDuration = (x, y, {duration}) => { + if (duration === undefined) return undefined; + const converted = Number(duration); + + if (isNaN(converted) || converted !== Math.floor(converted) || converted < MIN_DURATION) { + return `Talent as a Service engagements have a ${MIN_DURATION} week minimum commitment.`; + } + + return undefined; +} + /** * return edit job configuration * @param {any} skillOptions skill options @@ -92,6 +104,7 @@ export const getEditJobConfig = ( placeholder: "Duration", disabled: onlyEnableStatus, step: 1, + customValidator: validateDuration, }, { label: "Resource Type",