From 628f5774e9dbb05ffbe509fd79f88f943e82ab04 Mon Sep 17 00:00:00 2001 From: yoution Date: Fri, 16 Jul 2021 18:10:04 +0800 Subject: [PATCH] fix: issue #356 --- .../components/EditRoleForm/index.jsx | 42 +++++++++++-------- .../EditRoleForm/styles.module.scss | 11 ++++- .../EditRoleForm/utils/validator.js | 4 +- .../components/ResultCard/index.jsx | 6 +-- .../components/SearchAndSubmit/index.jsx | 11 ++++- .../components/SearchContainer/index.jsx | 30 +++++++++---- 6 files changed, 68 insertions(+), 36 deletions(-) diff --git a/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx b/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx index 64d9a3de..c2c651dd 100644 --- a/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx +++ b/src/routes/CreateNewTeam/components/EditRoleForm/index.jsx @@ -27,12 +27,19 @@ const Error = ({ name }) => { return dirty && error ? {error} : null; }; -function EditRoleForm({ submitForm, role }) { +function EditRoleForm({ onChange, role }) { const [startMonthVisible, setStartMonthVisible] = useState(false); + const onRoleChange = (state) => { + if (state.hasValidationErrors) { + onChange(false); + }else { + onChange(true, state.values); + } + }; return (
{}} mutators={{ clearField: ([fieldName], state, { changeValue }) => { changeValue(state, fieldName, () => undefined); @@ -41,15 +48,13 @@ function EditRoleForm({ submitForm, role }) { validate={validator} > {({ - handleSubmit, - hasValidationErrors, form: { mutators: { clearField }, getState, }, }) => { return ( -
+
@@ -59,7 +64,7 @@ function EditRoleForm({ submitForm, role }) {
# of resources
@@ -67,7 +72,10 @@ function EditRoleForm({ submitForm, role }) { { + input.onChange(v); + onRoleChange(getState()); + }} onBlur={input.onBlur} onFocus={input.onFocus} min="1" @@ -79,7 +87,7 @@ function EditRoleForm({ submitForm, role }) { @@ -87,7 +95,10 @@ function EditRoleForm({ submitForm, role }) { { + input.onChange(v); + onRoleChange(getState()); + }} onBlur={input.onBlur} onFocus={input.onFocus} min="4" @@ -105,7 +116,10 @@ function EditRoleForm({ submitForm, role }) { { + props.input.onChange(v); + onRoleChange(getState()); + }} onBlur={props.input.onBlur} onFocus={props.input.onFocus} /> @@ -130,14 +144,6 @@ function EditRoleForm({ submitForm, role }) {
-
); }} diff --git a/src/routes/CreateNewTeam/components/EditRoleForm/styles.module.scss b/src/routes/CreateNewTeam/components/EditRoleForm/styles.module.scss index 1c47d84f..d9f635f9 100644 --- a/src/routes/CreateNewTeam/components/EditRoleForm/styles.module.scss +++ b/src/routes/CreateNewTeam/components/EditRoleForm/styles.module.scss @@ -36,7 +36,13 @@ .role-row { td { + > div { + margin-left: auto; + margin-right: auto; + } + padding: 18px 18px 18px 0; + width: 30%; vertical-align: top; @include font-barlow; font-weight: 600; @@ -90,11 +96,12 @@ } } -.modal-body { +.table-container { > button { margin: 0 auto; } - overflow-x: auto; + padding: 0 30px; + width: 80%; textarea { height: 95px; } diff --git a/src/routes/CreateNewTeam/components/EditRoleForm/utils/validator.js b/src/routes/CreateNewTeam/components/EditRoleForm/utils/validator.js index 60cb16a8..704f1099 100644 --- a/src/routes/CreateNewTeam/components/EditRoleForm/utils/validator.js +++ b/src/routes/CreateNewTeam/components/EditRoleForm/utils/validator.js @@ -1,8 +1,8 @@ const composeValidators = (...validators) => (value) => validators.reduce((error, validator) => error || validator(value), undefined); -const validateMin = (min) => (value) => - isNaN(value) || value >= min ? undefined : `Should be greater than ${min}`; +const validateMin = (min, message) => (value) => + isNaN(value) || value >= min ? undefined : message; const validateName = (name) => { if (!name || name.trim().length === 0) { diff --git a/src/routes/CreateNewTeam/components/ResultCard/index.jsx b/src/routes/CreateNewTeam/components/ResultCard/index.jsx index 38bd0690..8aa4fa42 100644 --- a/src/routes/CreateNewTeam/components/ResultCard/index.jsx +++ b/src/routes/CreateNewTeam/components/ResultCard/index.jsx @@ -27,7 +27,7 @@ function formatPercent(value) { return `${Math.round(value * 100)}%`; } -function ResultCard({ role, currentRole, onSubmitEditRole }) { +function ResultCard({ role, currentRole, onSaveEditRole }) { const { numberOfMembersAvailable, isExternalMember, @@ -269,7 +269,7 @@ function ResultCard({ role, currentRole, onSubmitEditRole }) {
{currentRole && ( - + )} )} @@ -280,7 +280,7 @@ function ResultCard({ role, currentRole, onSubmitEditRole }) { ResultCard.propTypes = { role: PT.object, currentRole: PT.object, - onSubmitEditRole: PT.func, + onSaveEditRole: PT.func, }; export default ResultCard; diff --git a/src/routes/CreateNewTeam/components/SearchAndSubmit/index.jsx b/src/routes/CreateNewTeam/components/SearchAndSubmit/index.jsx index e24ed940..cd55604d 100644 --- a/src/routes/CreateNewTeam/components/SearchAndSubmit/index.jsx +++ b/src/routes/CreateNewTeam/components/SearchAndSubmit/index.jsx @@ -57,8 +57,15 @@ function SearchAndSubmit(props) { const name = _.get(res, "data.name"); const searchId = _.get(res, "data.roleSearchRequestId"); if (name && !isCustomRole({ name })) { - dispatch(addSearchedRole({ searchId, name, numberOfResources: 1, durationWeeks: 4 })); - setIsNewRole(true) + dispatch( + addSearchedRole({ + searchId, + name, + numberOfResources: 1, + durationWeeks: 4, + }) + ); + setIsNewRole(true); } else if (searchId) { dispatch(addRoleSearchId(searchId)); } diff --git a/src/routes/CreateNewTeam/components/SearchContainer/index.jsx b/src/routes/CreateNewTeam/components/SearchContainer/index.jsx index 4529b9c2..2c35d8eb 100644 --- a/src/routes/CreateNewTeam/components/SearchContainer/index.jsx +++ b/src/routes/CreateNewTeam/components/SearchContainer/index.jsx @@ -7,6 +7,7 @@ */ import React, { useCallback, useState, useMemo, useEffect } from "react"; import PT from "prop-types"; +import _ from "lodash"; import { useDispatch } from "react-redux"; import { editRoleAction } from "../../actions"; import AddedRolesAccordion from "../AddedRolesAccordion"; @@ -30,6 +31,7 @@ function SearchContainer({ }) { const [addAnotherOpen, setAddAnotherOpen] = useState(false); const [showEditModal, setShowEditModal] = useState(false); + const [buttonClickable, setButtonClickable] = useState(true); const dispatch = useDispatch(); const currentRole = useMemo(() => { @@ -38,14 +40,19 @@ function SearchContainer({ useEffect(() => { if (isNewRole) { - setShowEditModal(true) + setShowEditModal(true); } }, [isNewRole]); - const onSubmitEditRole = useCallback((role) => { - setShowEditModal(false) - dispatch(editRoleAction({...role, searchId: previousSearchId})) - }, [addedRoles, previousSearchId]); + const onSaveEditRole = useCallback( + (isValid, role) => { + setButtonClickable(isValid) + if (isValid) { + dispatch(editRoleAction({ ...role, searchId: previousSearchId })); + } + }, + [addedRoles, previousSearchId] + ); const onSubmit = useCallback(() => { setAddAnotherOpen(false); @@ -58,10 +65,14 @@ function SearchContainer({ const renderLeftSide = () => { if (searchState === "searching") return ; - if (!isCustomRole(matchingRole)) return ; + if (!isCustomRole(matchingRole)) + return ( + + ); return ; }; @@ -78,6 +89,7 @@ function SearchContainer({