Skip to content

Commit 7f449f9

Browse files
committed
Fix validations
1 parent 5648af5 commit 7f449f9

File tree

4 files changed

+15
-54
lines changed

4 files changed

+15
-54
lines changed

src/shared/components/Settings/Profile/Education/index.jsx

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ export default class Education extends ConsentComponent {
9797
invalid = true;
9898
}
9999

100-
if (_.isEmpty(newEducation.timePeriodFrom) && !_.isEmpty(newEducation.timePeriodTo)) {
101-
// If enter End Date, the other becomes mandatory.
102-
// Not as per requirement, both are optional
103-
invalid = true;
104-
} else if (!_.isEmpty(newEducation.timePeriodFrom) && _.isEmpty(newEducation.timePeriodTo)) {
100+
if (!_.isEmpty(newEducation.timePeriodFrom) && _.isEmpty(newEducation.timePeriodTo)) {
105101
const fromDate = new Date(newEducation.timePeriodFrom).setHours(0, 0, 0, 0);
106102

107103
if (fromDate > currentDate) {
@@ -111,19 +107,12 @@ export default class Education extends ConsentComponent {
111107
const fromDate = new Date(newEducation.timePeriodFrom).setHours(0, 0, 0, 0);
112108
const toDate = new Date(newEducation.timePeriodTo).setHours(0, 0, 0, 0);
113109

114-
if (fromDate > currentDate) {
115-
invalid = true; // Start Date should be in past or current
116-
}
110+
if (fromDate > currentDate // Start Date is in past or current
111+
|| fromDate >= toDate // Start Date is before End Date
112+
|| (newEducation.graduated && toDate > currentDate)) { // End Date is in past or current
117113

118-
if (fromDate >= toDate) { // Start Date should be before End Date
119114
invalid = true;
120115
}
121-
122-
if (newEducation.graduated) {
123-
if (toDate > currentDate) {
124-
invalid = true; // End Date should be in past or current
125-
}
126-
}
127116
}
128117

129118
this.setState({ formInvalid: invalid });
@@ -138,13 +127,7 @@ export default class Education extends ConsentComponent {
138127
message: '',
139128
};
140129

141-
142-
if (_.isEmpty(newEducation.timePeriodFrom) && !_.isEmpty(newEducation.timePeriodTo)) {
143-
// If enter End Date, the other becomes mandatory.
144-
// Not as per requirement, both are optional
145-
result.invalid = true;
146-
result.message = 'Start Date cannot be empty';
147-
} else if (!_.isEmpty(newEducation.timePeriodFrom) && _.isEmpty(newEducation.timePeriodTo)) {
130+
if (!_.isEmpty(newEducation.timePeriodFrom) && _.isEmpty(newEducation.timePeriodTo)) {
148131
const fromDate = new Date(newEducation.timePeriodFrom).setHours(0, 0, 0, 0);
149132

150133
if (fromDate > currentDate) {
@@ -343,6 +326,13 @@ export default class Education extends ConsentComponent {
343326
newEducation[e.target.name] = e.target.value;
344327
} else {
345328
newEducation[e.target.name] = e.target.checked;
329+
if(e.target.checked) { // if gradated and toDate is in Future, nullify it
330+
const toDate = new Date(newEducation.timePeriodTo).setHours(0, 0, 0, 0);
331+
const currentDate = new Date().setHours(0, 0, 0, 0);
332+
if (toDate > currentDate) {
333+
newEducation.timePeriodTo = ''
334+
}
335+
}
346336
}
347337

348338
this.setState({ newEducation, inputChanged: true });
@@ -511,11 +501,6 @@ export default class Education extends ConsentComponent {
511501
</label>
512502
</div>
513503
<div styleName="field col-2">
514-
{
515-
!_.isEmpty(newEducation.timePeriodTo) && (
516-
<span styleName="text-required">* Required</span>
517-
)
518-
}
519504
<DatePicker
520505
readOnly
521506
numberOfMonths={1}

src/shared/components/Settings/Profile/Work/index.jsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ export default class Work extends ConsentComponent {
169169
};
170170

171171
if (newWork.working) {
172-
// if (!_.isEmpty(newWork.timePeriodTo)) {
173-
// result.invalid = true;
174-
// result.message = 'End Date should be null';
175-
// }
176-
177172
if (!_.isEmpty(newWork.timePeriodFrom)) {
178173
const fromDate = new Date(newWork.timePeriodFrom).setHours(0, 0, 0, 0);
179174

@@ -183,13 +178,6 @@ export default class Work extends ConsentComponent {
183178
}
184179
}
185180
} else if (!newWork.working) {
186-
if (_.isEmpty(newWork.timePeriodFrom) && !_.isEmpty(newWork.timePeriodTo)) {
187-
// If enter End Date, the other becomes mandatory.
188-
// Not as per requirement, both are optional
189-
result.invalid = true;
190-
result.message = 'Start Date cannot be empty';
191-
}
192-
193181
if (!_.isEmpty(newWork.timePeriodFrom)) {
194182
const fromDate = new Date(newWork.timePeriodFrom).setHours(0, 0, 0, 0);
195183

@@ -206,13 +194,6 @@ export default class Work extends ConsentComponent {
206194
}
207195
}
208196
}
209-
210-
// if (!_.isEmpty(newWork.timePeriodTo)) {
211-
// const toDate = new Date(newWork.timePeriodTo).setHours(0, 0, 0, 0);
212-
// if (toDate > currentDate) {
213-
// invalid = true; // End Date should be in past or current
214-
// }
215-
// }
216197
}
217198
return result;
218199
}
@@ -555,11 +536,6 @@ export default class Work extends ConsentComponent {
555536
</label>
556537
</div>
557538
<div styleName="field col-2">
558-
{
559-
!_.isEmpty(newWork.timePeriodTo) && !newWork.working && (
560-
<span styleName="text-required">* Required</span>
561-
)
562-
}
563539
<DatePicker
564540
readOnly
565541
numberOfMonths={1}

src/shared/components/Settings/Tools/Devices/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ export default class Devices extends ConsentComponent {
485485
<div styleName="row">
486486
<div styleName="field col-1">
487487
<label htmlFor="deviceType">
488-
Device Type
488+
Type
489489
<span styleName="text-required">* Required</span>
490490
<input type="hidden" />
491491
</label>

src/shared/components/Settings/Tools/Software/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export default class Software extends ConsentComponent {
411411
<div styleName="row">
412412
<div styleName="field col-1">
413413
<label htmlFor="softwareType">
414-
Software Type
414+
Type
415415
<span styleName="text-required">* Required</span>
416416
<input type="hidden" />
417417
</label>
@@ -426,7 +426,7 @@ export default class Software extends ConsentComponent {
426426
clearable={false}
427427
disabled={!canModifyTrait}
428428
/>
429-
<ErrorMessage invalid={_.isEmpty(newSoftware.softwareType) && inputChanged} addMargin message="Software Type cannot be empty" />
429+
<ErrorMessage invalid={_.isEmpty(newSoftware.softwareType) && inputChanged} addMargin message="Type cannot be empty" />
430430
</div>
431431
<div styleName="field col-2">
432432
<label htmlFor="name">

0 commit comments

Comments
 (0)