Skip to content

Commit

Permalink
initial commit (#2490)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergomi02 authored Apr 19, 2024
1 parent 30b61ff commit f423d09
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { HealthAuthoritySiteFormStateService } from '@health-auth/shared/service
import { AbstractHealthAuthoritySiteRegistrationPage } from '@health-auth/shared/classes/abstract-health-authority-site-registration-page.class';
import { SiteInformationFormState } from './site-information-form-state.class';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
import { SiteResource } from '@core/resources/site-resource.service';
import { Observable, of } from 'rxjs';
import { asyncValidator } from '@lib/validators/form-async.validators';

@Component({
selector: 'app-site-information-page',
Expand All @@ -40,6 +43,7 @@ export class SiteInformationPageComponent extends AbstractHealthAuthoritySiteReg
protected healthAuthoritySiteService: HealthAuthoritySiteService,
protected healthAuthoritySiteFormStateService: HealthAuthoritySiteFormStateService,
protected healthAuthoritySiteResource: HealthAuthoritySiteResource,
protected siteResource: SiteResource,
private fb: FormBuilder,
private configService: ConfigService,
router: Router
Expand Down Expand Up @@ -69,6 +73,9 @@ export class SiteInformationPageComponent extends AbstractHealthAuthoritySiteReg
public ngOnInit(): void {
this.createFormInstance();
this.patchForm();

//add validation to PEC
this.formState.pec.addAsyncValidators(asyncValidator(this.checkPecIsAssignable(), 'assignable'));
}

protected createFormInstance(): void {
Expand Down Expand Up @@ -120,4 +127,8 @@ export class SiteInformationPageComponent extends AbstractHealthAuthoritySiteReg
protected onSubmitFormIsInvalid(): void {
this.showAddressFields = true;
}

private checkPecIsAssignable(): (value: string) => Observable<boolean> {
return (value: string) => value ? this.siteResource.pecAssignable(this.route.snapshot.params.sid, value) : of(true);
}
}

0 comments on commit f423d09

Please sign in to comment.