import { Component, OnInit } from '@angular/core'; import { Validators } from '@angular/forms'; import { SpinnerService } from '@core/services/spinner.service'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { ProgramService } from '@features/programs/program.service'; import { AllProgramsResolver } from '@features/programs/resolvers/all-programs.resolver'; import { TypeaheadSelectOption, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { YCModalComponent } from '@yourcause/common/modals'; export interface ExportEmailModalResponse { programId: number; emailLanguage: string; } @Component({ selector: 'gc-export-emails-modal', templateUrl: './export-emails-modal.component.html', styleUrls: ['./export-emails-modal.component.scss'] }) export class ExportEmailsModalComponent extends YCModalComponent< ExportEmailModalResponse > implements OnInit { formGroup: TypeSafeFormGroup; programOptions: TypeaheadSelectOption[] = []; langOptions: TypeaheadSelectOption[] = []; defaultLang = this.clientSettingsService.defaultLanguage; langKeys = this.clientSettingsService.selectedLanguages; hasInternational = this.clientSettingsService.clientSettings.hasInternational; constructor ( private formBuilder: TypeSafeFormBuilder, private programService: ProgramService, private clientSettingsService: ClientSettingsService, private spinnerService: SpinnerService, private allProgramsResolver: AllProgramsResolver ) { super(); } async ngOnInit () { this.spinnerService.startSpinner(); await this.allProgramsResolver.resolve(); this.spinnerService.stopSpinner(); this.setOptions(); this.formGroup = this.formBuilder.group({ programId: [null, Validators.required], emailLanguage: [this.defaultLang, Validators.required] }); } setOptions () { this.programOptions = this.programService.allPrograms.map((prog) => { return { label: prog.grantProgramName, value: prog.grantProgramId }; }); } doExport () { this.closeModal.emit(this.formGroup.value); } }