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

Commit ee4604a

Browse files
git push origin developMerge branch 'issue-148' into develop
2 parents f44a64b + 77ee37c commit ee4604a

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

client/src/components/EditProfileModal/index.jsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import PT from "prop-types";
3+
import { trim, findIndex } from "lodash";
34

45
import Button from "../Button";
56
import Input from "../Input";
@@ -87,6 +88,38 @@ export default function EditProfileModal({
8788
setLocalUser({ ...localUser, skills });
8889
};
8990

91+
/**
92+
* Checks if all required fields are field
93+
* @param {Object} localUser user's new data
94+
*/
95+
const isValid = (localUser) => {
96+
let fieldName;
97+
if (!trim(localUser.firstName)) {
98+
fieldName = "First name";
99+
} else if (!trim(localUser.lastName)) {
100+
fieldName = "Last name";
101+
} else if (!trim(localUser.title.value)) {
102+
fieldName = "Current role";
103+
} else if (!trim(localUser.company.value)) {
104+
fieldName = "Company";
105+
} else if (!trim(localUser.location.value)) {
106+
fieldName = "Location";
107+
} else {
108+
let fieldIndex = findIndex(
109+
localUser.companyAttributes,
110+
(a) => !trim(a.value)
111+
);
112+
if (fieldIndex !== -1) {
113+
fieldName = localUser.companyAttributes[fieldIndex].name;
114+
}
115+
}
116+
if (fieldName) {
117+
alert(`Please enter a value for the "${fieldName}" field`);
118+
return false;
119+
}
120+
return true;
121+
};
122+
90123
return (
91124
<Modal className={style.container} onCancel={onCancel}>
92125
<ProfileCard
@@ -111,8 +144,10 @@ export default function EditProfileModal({
111144
isSavingChanges ? style.disabledButton : style.saveButton
112145
}
113146
onClick={() => {
114-
setIsSavingChanges(true);
115-
updateUser(localUser);
147+
if (isValid(localUser)) {
148+
setIsSavingChanges(true);
149+
updateUser(localUser);
150+
}
116151
}}
117152
disabled={isSavingChanges || isDeactivatingUser}
118153
>
@@ -132,6 +167,7 @@ export default function EditProfileModal({
132167
setImmediate(() => target.focus());
133168
}}
134169
value={localUser.firstName}
170+
required
135171
/>
136172
<Input
137173
label="Last name"
@@ -143,6 +179,7 @@ export default function EditProfileModal({
143179
setImmediate(() => target.focus());
144180
}}
145181
value={localUser.lastName}
182+
required
146183
/>
147184
<Input
148185
label="Current role"
@@ -157,6 +194,7 @@ export default function EditProfileModal({
157194
setImmediate(() => target.focus());
158195
}}
159196
value={localUser.title.value}
197+
required
160198
/>
161199
<Input
162200
label="Company"
@@ -171,6 +209,7 @@ export default function EditProfileModal({
171209
setImmediate(() => target.focus());
172210
}}
173211
value={localUser.company.value}
212+
required
174213
/>
175214
<Input
176215
label="Location"
@@ -185,6 +224,7 @@ export default function EditProfileModal({
185224
setImmediate(() => target.focus());
186225
}}
187226
value={localUser.location.value}
227+
required
188228
/>
189229
</div>
190230
<h3>Skills</h3>
@@ -234,6 +274,7 @@ export default function EditProfileModal({
234274
setImmediate(() => target.focus());
235275
}}
236276
value={localUser.companyAttributes[key].value}
277+
required
237278
/>
238279
))}
239280
</div>

client/src/components/Input/index.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import _ from "lodash";
44

55
import style from "./style.module.scss";
66

7-
export default function Input({ className, label, onChange, value }) {
7+
export default function Input({ className, label, onChange, value, required }) {
88
let containerStyle = style.container;
9+
let labelStyle = style.label;
910
if (className) containerStyle += ` ${className}`;
11+
if (required) labelStyle += ` ${style.required}`;
1012
const id = _.uniqueId("input_");
1113

1214
return (
1315
<div className={containerStyle}>
14-
<label htmlFor={id} className={style.label}>
16+
<label htmlFor={id} className={labelStyle}>
1517
{label}
1618
</label>
1719
<input
@@ -22,6 +24,7 @@ export default function Input({ className, label, onChange, value }) {
2224
if (event.keyCode === 8) {
2325
event.preventDefault();
2426
event.currentTarget.value = event.currentTarget.value.slice(0, -1);
27+
onChange(event);
2528
}
2629
}}
2730
value={value}
@@ -35,4 +38,9 @@ Input.propTypes = {
3538
label: PT.string,
3639
onChange: PT.func,
3740
value: PT.string,
41+
required: PT.bool,
42+
};
43+
44+
Input.defaultProps = {
45+
required: false,
3846
};

client/src/components/Input/style.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@
3030
font: 400 12pt/1.25 Inter;
3131
width: 180px;
3232
}
33+
34+
.label.required:after {
35+
content: "*";
36+
color: red;
37+
margin-left: 5px;
38+
}

0 commit comments

Comments
 (0)