import { Component, Input, OnInit } from '@angular/core'; import { SpinnerService } from '@core/services/spinner.service'; import { EmailService } from '@features/system-emails/email.service'; import { EmailNotificationType } from '@features/system-emails/email.typing'; import { GenericFile, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { YCModalComponent } from '@yourcause/common/modals'; interface SendFormToApplicantGroup { clientEmailTemplateId: number; cc: string[]; bcc: string[]; attachments: GenericFile[]; } export interface SendFormModalResponse { ccEmails: string[]; bccEmails: string[]; attachments: number[]; clientEmailTemplateId: number; } @Component({ selector: 'gc-send-form-to-applicant-modal', templateUrl: './send-form-to-applicant-modal.component.html', styleUrls: ['./send-form-to-applicant-modal.component.scss'] }) export class SendFormToApplicantModalComponent extends YCModalComponent implements OnInit { @Input() programId: number; @Input() isNomination = false; @Input() applicationId: number; @Input() formName: string; saving = false; formGroup: TypeSafeFormGroup; currentEmailActive = false; emailType: EmailNotificationType; constructor ( private formBuilder: TypeSafeFormBuilder, private emailService: EmailService, private spinnerService: SpinnerService, private analyticsService: AnalyticsService ) { super(); } async ngOnInit () { this.spinnerService.startSpinner(); await this.setEmailAttrs(); this.formGroup = this.formBuilder.group({ clientEmailTemplateId: 0, cc: [], bcc: [], attachments: [] }); this.spinnerService.stopSpinner(); } async setEmailAttrs () { this.emailType = this.isNomination ? EmailNotificationType.NominationFormSent : EmailNotificationType.ApplicationFormSent; this.currentEmailActive = await this.emailService.isProgramEmailActive( this.emailType, this.programId ); } async onSend () { this.saving = true; const formValue = this.formGroup.value; const attachments = await this.emailService.returnIdsFromMixedAttachments( formValue.attachments, this.applicationId ); this.saving = false; this.closeModal.emit({ ccEmails: formValue.cc, bccEmails: formValue.bcc, attachments, clientEmailTemplateId: formValue.clientEmailTemplateId }); this.analyticsService.emitEvent({ eventName: 'Send form to applicant modal submit', eventType: EventType.Click, extras: null }); } }