Skip to content

Commit

Permalink
Merge pull request #2563 from sam-warren/DEVOPS-175-Patch
Browse files Browse the repository at this point in the history
DEVOPS-175 Patch
  • Loading branch information
GeorgeWalker authored Jan 21, 2025
2 parents 46cf913 + 36ea684 commit f4ada62
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,9 @@

@if (
supportDetailsFormControl.fromDate.invalid &&
supportDetailsFormControl.fromDate.hasError('invalidDate')
supportDetailsFormControl.fromDate.hasError('invalidTaskDate')
) {
<mat-error> Please enter a valid date</mat-error>
}
@if (
supportDetailsFormControl.fromDate.invalid &&
supportDetailsFormControl.fromDate.hasError('invalidTaskDateTime')
) {
<mat-error>Date/time must fall within the task dates</mat-error>
<mat-error>Date must fall within the task dates</mat-error>
}
@if (
supportDetailsFormControl.fromDate.invalid &&
Expand All @@ -256,13 +250,13 @@
supportDetailsFormControl.fromTime.invalid &&
supportDetailsFormControl.fromTime.hasError('required')
) {
<mat-error> From Time is required</mat-error>
<mat-error>From Time is required</mat-error>
}
@if (
supportDetailsFormControl.fromTime.invalid &&
supportDetailsFormControl.fromTime.hasError('invalidTaskDateTime')
supportDetailsFormControl.fromTime.hasError('invalidTaskTime')
) {
<mat-error>Date/time must fall within the task dates</mat-error>
<mat-error>Time must fall within the task dates</mat-error>
}
</mat-form-field>
</div>
Expand Down Expand Up @@ -306,15 +300,9 @@

@if (
supportDetailsFormControl.toDate.invalid &&
supportDetailsFormControl.toDate.hasError('invalidDate')
) {
<mat-error> Please enter a valid date</mat-error>
}
@if (
supportDetailsFormControl.toDate.invalid &&
supportDetailsFormControl.toDate.hasError('invalidTaskDateTime')
supportDetailsFormControl.toDate.hasError('invalidTaskDate')
) {
<mat-error>Date/time must fall within the task dates</mat-error>
<mat-error>Date must fall within the task dates</mat-error>
}
@if (
supportDetailsFormControl.toDate.invalid &&
Expand All @@ -338,13 +326,13 @@
supportDetailsFormControl.toTime.invalid &&
supportDetailsFormControl.toTime.hasError('required')
) {
<mat-error> To Time Required</mat-error>
<mat-error>To Time is required</mat-error>
}
@if (
supportDetailsFormControl.toTime.invalid &&
supportDetailsFormControl.toTime.hasError('invalidTaskDateTime')
supportDetailsFormControl.toTime.hasError('invalidTaskTime')
) {
<mat-error>Date/time must fall within the task dates</mat-error>
<mat-error>Time must fall within the task dates</mat-error>
}
</mat-form-field>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
compareTaskDateTimeValidator({ controlType, other }: { controlType: 'date' | 'time'; other: string }): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
let isValid = false;
const error = controlType === 'date' ? { invalidTaskDate: true } : { invalidTaskTime: true };
const otherControl = this.supportDetailsForm?.get(other);
const error = { invalidTaskDateTime: true };

if (!control?.value || !otherControl?.value) {
if (
control?.value === null ||
control?.value === '' ||
control?.value === undefined ||
otherControl?.value === null ||
otherControl?.value === '' ||
otherControl?.value === undefined
) {
isValid = true;
} else {
let controlDate;
Expand All @@ -168,20 +175,22 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
if (this.evacueeSessionService?.evacFile?.task?.from && this.evacueeSessionService?.evacFile?.task?.to) {
const from = moment(this.evacueeSessionService?.evacFile?.task?.from);
const to = moment(this.evacueeSessionService?.evacFile?.task?.to);
isValid = moment(controlDate).isBetween(from, to, 'm', '[]');
} else {
isValid = true;
}
const current = moment(controlDate);

if (current.isSame(to, 'day') && current.isAfter(to)) {
isValid = false;
} else {
isValid = current.isBetween(from, to, 'm', '[]');
}
} else isValid = true;
}

if (!isValid) {
control.setErrors({ ...control.errors, ...error });
otherControl.setErrors({ ...otherControl.errors, ...error });
} else {
this.removeError(control, 'invalidTaskDateTime');
this.removeError(otherControl, 'invalidTaskDateTime');
otherControl?.setErrors(error);
return error;
}

otherControl?.setErrors(null);
return null;
};
}
Expand Down

0 comments on commit f4ada62

Please sign in to comment.