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

Commit 63bbcb8

Browse files
authored
Merge pull request #385 from yoution/issue-356
Issue #356
2 parents a28ded8 + 628f577 commit 63bbcb8

File tree

6 files changed

+68
-36
lines changed

6 files changed

+68
-36
lines changed

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

+24-18
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ const Error = ({ name }) => {
2727
return dirty && error ? <span styleName="error">{error}</span> : null;
2828
};
2929

30-
function EditRoleForm({ submitForm, role }) {
30+
function EditRoleForm({ onChange, role }) {
3131
const [startMonthVisible, setStartMonthVisible] = useState(false);
32+
const onRoleChange = (state) => {
33+
if (state.hasValidationErrors) {
34+
onChange(false);
35+
}else {
36+
onChange(true, state.values);
37+
}
38+
};
3239

3340
return (
3441
<Form
35-
onSubmit={submitForm}
42+
onSubmit={() => {}}
3643
mutators={{
3744
clearField: ([fieldName], state, { changeValue }) => {
3845
changeValue(state, fieldName, () => undefined);
@@ -41,15 +48,13 @@ function EditRoleForm({ submitForm, role }) {
4148
validate={validator}
4249
>
4350
{({
44-
handleSubmit,
45-
hasValidationErrors,
4651
form: {
4752
mutators: { clearField },
4853
getState,
4954
},
5055
}) => {
5156
return (
52-
<div styleName="modal-body">
57+
<div styleName="table-container">
5358
<table styleName="table">
5459
<tr>
5560
<th># of resources</th>
@@ -59,15 +64,18 @@ function EditRoleForm({ submitForm, role }) {
5964
<tr styleName="role-row">
6065
<td>
6166
<Field
62-
validate={composeValidators(validateExists, validateMin(1))}
67+
validate={composeValidators(validateExists, validateMin(1, 'should be greater then 1'))}
6368
name="numberOfResources"
6469
initialValue={role.numberOfResources}
6570
>
6671
{({ input, meta }) => (
6772
<NumberInput
6873
name={input.name}
6974
value={input.value}
70-
onChange={input.onChange}
75+
onChange={(v) => {
76+
input.onChange(v);
77+
onRoleChange(getState());
78+
}}
7179
onBlur={input.onBlur}
7280
onFocus={input.onFocus}
7381
min="1"
@@ -79,15 +87,18 @@ function EditRoleForm({ submitForm, role }) {
7987
</td>
8088
<td>
8189
<Field
82-
validate={composeValidators(validateExists, validateMin(4))}
90+
validate={composeValidators(validateExists, validateMin(4, 'Talent as a Service engagements have a 4 week minimum commitment.'))}
8391
name="durationWeeks"
8492
initialValue={role.durationWeeks}
8593
>
8694
{({ input, meta }) => (
8795
<NumberInput
8896
name={input.name}
8997
value={input.value}
90-
onChange={input.onChange}
98+
onChange={(v) => {
99+
input.onChange(v);
100+
onRoleChange(getState());
101+
}}
91102
onBlur={input.onBlur}
92103
onFocus={input.onFocus}
93104
min="4"
@@ -105,7 +116,10 @@ function EditRoleForm({ submitForm, role }) {
105116
<MonthPicker
106117
name={props.input.name}
107118
value={props.input.value}
108-
onChange={props.input.onChange}
119+
onChange={(v) => {
120+
props.input.onChange(v);
121+
onRoleChange(getState());
122+
}}
109123
onBlur={props.input.onBlur}
110124
onFocus={props.input.onFocus}
111125
/>
@@ -130,14 +144,6 @@ function EditRoleForm({ submitForm, role }) {
130144
</td>
131145
</tr>
132146
</table>
133-
<Button
134-
type="primary"
135-
size="medium"
136-
onClick={handleSubmit}
137-
disabled={hasValidationErrors}
138-
>
139-
Save
140-
</Button>
141147
</div>
142148
);
143149
}}

src/routes/CreateNewTeam/components/EditRoleForm/styles.module.scss

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@
3636

3737
.role-row {
3838
td {
39+
> div {
40+
margin-left: auto;
41+
margin-right: auto;
42+
}
43+
3944
padding: 18px 18px 18px 0;
45+
width: 30%;
4046
vertical-align: top;
4147
@include font-barlow;
4248
font-weight: 600;
@@ -90,11 +96,12 @@
9096
}
9197
}
9298

93-
.modal-body {
99+
.table-container {
94100
> button {
95101
margin: 0 auto;
96102
}
97-
overflow-x: auto;
103+
padding: 0 30px;
104+
width: 80%;
98105
textarea {
99106
height: 95px;
100107
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const composeValidators = (...validators) => (value) =>
22
validators.reduce((error, validator) => error || validator(value), undefined);
33

4-
const validateMin = (min) => (value) =>
5-
isNaN(value) || value >= min ? undefined : `Should be greater than ${min}`;
4+
const validateMin = (min, message) => (value) =>
5+
isNaN(value) || value >= min ? undefined : message;
66

77
const validateName = (name) => {
88
if (!name || name.trim().length === 0) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function formatPercent(value) {
2727
return `${Math.round(value * 100)}%`;
2828
}
2929

30-
function ResultCard({ role, currentRole, onSubmitEditRole }) {
30+
function ResultCard({ role, currentRole, onSaveEditRole }) {
3131
const {
3232
numberOfMembersAvailable,
3333
isExternalMember,
@@ -269,7 +269,7 @@ function ResultCard({ role, currentRole, onSubmitEditRole }) {
269269
</div>
270270
</div>
271271
{currentRole && (
272-
<EditRoleForm role={currentRole} submitForm={onSubmitEditRole} />
272+
<EditRoleForm role={currentRole} onChange={onSaveEditRole} />
273273
)}
274274
</div>
275275
)}
@@ -280,7 +280,7 @@ function ResultCard({ role, currentRole, onSubmitEditRole }) {
280280
ResultCard.propTypes = {
281281
role: PT.object,
282282
currentRole: PT.object,
283-
onSubmitEditRole: PT.func,
283+
onSaveEditRole: PT.func,
284284
};
285285

286286
export default ResultCard;

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,15 @@ function SearchAndSubmit(props) {
5757
const name = _.get(res, "data.name");
5858
const searchId = _.get(res, "data.roleSearchRequestId");
5959
if (name && !isCustomRole({ name })) {
60-
dispatch(addSearchedRole({ searchId, name, numberOfResources: 1, durationWeeks: 4 }));
61-
setIsNewRole(true)
60+
dispatch(
61+
addSearchedRole({
62+
searchId,
63+
name,
64+
numberOfResources: 1,
65+
durationWeeks: 4,
66+
})
67+
);
68+
setIsNewRole(true);
6269
} else if (searchId) {
6370
dispatch(addRoleSearchId(searchId));
6471
}

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import React, { useCallback, useState, useMemo, useEffect } from "react";
99
import PT from "prop-types";
10+
import _ from "lodash";
1011
import { useDispatch } from "react-redux";
1112
import { editRoleAction } from "../../actions";
1213
import AddedRolesAccordion from "../AddedRolesAccordion";
@@ -30,6 +31,7 @@ function SearchContainer({
3031
}) {
3132
const [addAnotherOpen, setAddAnotherOpen] = useState(false);
3233
const [showEditModal, setShowEditModal] = useState(false);
34+
const [buttonClickable, setButtonClickable] = useState(true);
3335

3436
const dispatch = useDispatch();
3537
const currentRole = useMemo(() => {
@@ -38,14 +40,19 @@ function SearchContainer({
3840

3941
useEffect(() => {
4042
if (isNewRole) {
41-
setShowEditModal(true)
43+
setShowEditModal(true);
4244
}
4345
}, [isNewRole]);
4446

45-
const onSubmitEditRole = useCallback((role) => {
46-
setShowEditModal(false)
47-
dispatch(editRoleAction({...role, searchId: previousSearchId}))
48-
}, [addedRoles, previousSearchId]);
47+
const onSaveEditRole = useCallback(
48+
(isValid, role) => {
49+
setButtonClickable(isValid)
50+
if (isValid) {
51+
dispatch(editRoleAction({ ...role, searchId: previousSearchId }));
52+
}
53+
},
54+
[addedRoles, previousSearchId]
55+
);
4956

5057
const onSubmit = useCallback(() => {
5158
setAddAnotherOpen(false);
@@ -58,10 +65,14 @@ function SearchContainer({
5865

5966
const renderLeftSide = () => {
6067
if (searchState === "searching") return <SearchCard />;
61-
if (!isCustomRole(matchingRole)) return <ResultCard
62-
role={matchingRole}
63-
onSubmitEditRole={onSubmitEditRole}
64-
currentRole={currentRole}/>;
68+
if (!isCustomRole(matchingRole))
69+
return (
70+
<ResultCard
71+
role={matchingRole}
72+
onSaveEditRole={onSaveEditRole}
73+
currentRole={currentRole}
74+
/>
75+
);
6576
return <NoMatchingProfilesResultCard role={matchingRole} />;
6677
};
6778

@@ -78,6 +89,7 @@ function SearchContainer({
7889
<AddedRolesAccordion addedRoles={addedRoles} />
7990
<Completeness
8091
isDisabled={
92+
!buttonClickable ||
8193
searchState === "searching" ||
8294
(searchState === "done" && (!addedRoles || !addedRoles.length))
8395
}

0 commit comments

Comments
 (0)