import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; import { Validators } from '@angular/forms'; import { ProgramApplicantType } from '@core/typings/program.typing'; import { ProgramService } from '@features/programs/program.service'; import { TypeaheadSelectOption, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { YCModalComponent } from '@yourcause/common/modals'; export interface AutomationRouteFormGroup { programId: number; routeName: string; } @Component({ selector: 'gc-program-automation-route-modal', templateUrl: './program-automation-route-modal.component.html', styleUrls: ['./program-automation-route-modal.component.scss'] }) export class ProgramAutomationRouteModalComponent extends YCModalComponent implements OnInit, OnChanges { @Input() id: number; @Input() programId: number; @Input() routeName: string; @Input() programApplicantType: ProgramApplicantType; formGroup: TypeSafeFormGroup; programOptions: TypeaheadSelectOption[] = []; constructor ( private formBuilder: TypeSafeFormBuilder, private programService: ProgramService ) { super(); } ngOnInit () { this.formGroup = this.formBuilder.group({ programId: [this.programId, Validators.required], routeName: [this.routeName || '', Validators.required] }); this.programOptions = this.programService.getPublishedActiveProgramOptions(this.programApplicantType); } ngOnChanges (changes: SimpleChanges) { if (changes.programApplicantType) { this.programOptions = this.programService.getPublishedActiveProgramOptions(this.programApplicantType); } } }