Skip to content

Commit 3e6f3f2

Browse files
committed
fix: last name issue
1 parent b2056a3 commit 3e6f3f2

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

src/shared/components/Settings/ProfileSettings/index.jsx

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ProfileSettings extends ConsentComponent {
3232
this.onUpdateCountry = this.onUpdateCountry.bind(this);
3333
this.onUpdateInput = this.onUpdateInput.bind(this);
3434
this.onUpdateDate = this.onUpdateDate.bind(this);
35+
this.onSaveProfile = this.onSaveProfile.bind(this);
3536
this.onHandleSaveBasicInfo = this.onHandleSaveBasicInfo.bind(this);
3637
this.onSaveBasicInfo = this.onSaveBasicInfo.bind(this);
3738
this.onChange = this.onChange.bind(this);
@@ -80,6 +81,7 @@ class ProfileSettings extends ConsentComponent {
8081
graduated: false,
8182
},
8283
isSubmit: false,
84+
educationInputChanged: false,
8385
isMobileView: false,
8486
screenSM: 767,
8587
isEdit: false,
@@ -113,6 +115,7 @@ class ProfileSettings extends ConsentComponent {
113115
isSubmitHobby: false,
114116
indexNoHobby: null,
115117
isHobbyEdit: false,
118+
hobbyInputChanged: false,
116119
newHobby: {
117120
hobby: '',
118121
description: '',
@@ -240,38 +243,19 @@ class ProfileSettings extends ConsentComponent {
240243
onHandleSaveBasicInfo(e) {
241244
if (e) e.preventDefault();
242245
const { setIsSaving } = this.props;
243-
this.setState({ inputChange: true, isSubmit: true, isSubmitHobby: true });
246+
this.setState({ inputChange: true });
244247
setIsSaving(true);
245248
const {
246-
newBasicInfo, newProfileInfo, newEducation, newHobby,
249+
newBasicInfo, newProfileInfo,
247250
} = this.state;
248-
249-
if (!_.isEmpty(newEducation.timePeriodFrom)
250-
&& !_.isEmpty(newEducation.timePeriodTo)
251-
&& _.trim(newEducation.schoolCollegeName).length
252-
) {
253-
this.setState({ isSubmit: true });
254-
if (this.onCheckEducationFormValue(newEducation)) {
255-
setIsSaving(false);
256-
return;
257-
}
258-
}
259-
260-
if (!this.onCheckEducationFormValue(newEducation)) {
261-
this.showConsent(this.onAddEducation.bind(this));
262-
}
263-
264-
if (!this.onCheckFormValueHobby(newHobby)) {
265-
this.showConsent(this.onAddHobby.bind(this));
266-
}
267-
268-
if (!this.onCheckFormValue(newBasicInfo, newProfileInfo)) {
269-
this.showConsent(this.onSaveBasicInfo.bind(this));
270-
} else {
251+
if (this.onCheckFormValue(newBasicInfo, newProfileInfo)) {
271252
setIsSaving(false);
253+
return;
272254
}
255+
this.showConsent(this.onSaveBasicInfo.bind(this));
273256
}
274257

258+
275259
/**
276260
* Save Basic Info
277261
* @param answer user consent answer value
@@ -354,6 +338,49 @@ class ProfileSettings extends ConsentComponent {
354338
this.props.setIsSaving(false);
355339
}
356340

341+
/**
342+
* Save Changes
343+
*/
344+
onSaveProfile() {
345+
const { isSaving, setIsSaving } = this.props;
346+
const {
347+
inputChanged,
348+
educationInputChanged,
349+
hobbyInputChanged,
350+
newBasicInfo,
351+
newProfileInfo,
352+
newEducation,
353+
newHobby,
354+
} = this.state;
355+
356+
if (isSaving) {
357+
return;
358+
}
359+
360+
let valid = true;
361+
let dirty;
362+
363+
if (inputChanged) {
364+
dirty = true;
365+
valid = valid && !this.onCheckFormValue(newBasicInfo, newProfileInfo);
366+
this.onHandleSaveBasicInfo();
367+
}
368+
369+
if (educationInputChanged) {
370+
dirty = true;
371+
valid = valid && !this.onCheckEducationFormValue(newEducation);
372+
this.onHandleAddEducation();
373+
}
374+
375+
if (hobbyInputChanged) {
376+
dirty = true;
377+
valid = valid && !this.onCheckFormValueHobby(newHobby);
378+
this.onHandleAddHobby();
379+
}
380+
381+
if (valid && dirty) setIsSaving(true);
382+
}
383+
357384
onUpdateInput(e) {
358385
const { newBasicInfo: oldBasicInfo, newProfileInfo: oldProfileInfo } = this.state;
359386
const newBasicInfo = { ...oldBasicInfo };
@@ -582,7 +609,7 @@ class ProfileSettings extends ConsentComponent {
582609
const { newEducation: oldEducation } = this.state;
583610
const newEducation = { ...oldEducation };
584611
newEducation[timePeriod] = date || '';
585-
this.setState({ newEducation, isSubmit: false });
612+
this.setState({ newEducation, isSubmit: false, educationInputChanged: true });
586613
}
587614

588615
/**
@@ -705,6 +732,7 @@ class ProfileSettings extends ConsentComponent {
705732
newEducation: empty,
706733
isEdit: false,
707734
indexNo: null,
735+
educationInputChanged: false,
708736
isSubmit: false,
709737
});
710738
// save personalization
@@ -740,7 +768,7 @@ class ProfileSettings extends ConsentComponent {
740768
}
741769
}
742770

743-
this.setState({ newEducation, isSubmit: false });
771+
this.setState({ newEducation, isSubmit: false, educationInputChanged: true });
744772
}
745773

746774
/**
@@ -800,7 +828,7 @@ class ProfileSettings extends ConsentComponent {
800828
* @param e event
801829
*/
802830
onHandleAddHobby(e) {
803-
e.preventDefault();
831+
if (e) e.preventDefault();
804832
const { newHobby } = this.state;
805833
this.setState({ isSubmitHobby: true });
806834
if (this.onCheckFormValueHobby(newHobby)) {
@@ -905,7 +933,7 @@ class ProfileSettings extends ConsentComponent {
905933
newHobby: empty,
906934
isHobbyEdit: false,
907935
indexNoHobby: null,
908-
inputChanged: false,
936+
hobbyInputChanged: false,
909937
});
910938

911939
// save personalization
@@ -929,7 +957,7 @@ class ProfileSettings extends ConsentComponent {
929957
const { newHobby: oldHobby } = this.state;
930958
const newHobby = { ...oldHobby };
931959
newHobby[e.target.name] = e.target.value;
932-
this.setState({ newHobby, isSubmitHobby: false });
960+
this.setState({ newHobby, isSubmitHobby: false, hobbyInputChanged: true });
933961
}
934962

935963
/**
@@ -1146,7 +1174,7 @@ class ProfileSettings extends ConsentComponent {
11461174
<div styleName="footer">
11471175
<PrimaryButton
11481176
disabled={!canModifyTrait}
1149-
onClick={this.onHandleSaveBasicInfo}
1177+
onClick={this.onSaveProfile}
11501178
theme={{
11511179
button: style['save-changes-btn'],
11521180
}}

src/shared/components/Settings/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default function Settings(props) {
6060
if (newProps.settingsTab === TABS.TRACKS) {
6161
tracksRef.current.onSaveTopcoderAndYou();
6262
} else if (newProps.settingsTab === TABS.PROFILE) {
63-
profileRef.current.onHandleSaveBasicInfo();
63+
profileRef.current.onSaveProfile();
6464
} else if (newProps.settingsTab === TABS.SKILLS) {
6565
experienceAndSkillsRef.current.save();
6666
} else if (newProps.settingsTab === TABS.TOOLS) {

0 commit comments

Comments
 (0)