import { Component, Input, OnInit } from '@angular/core'; import { EmailService } from '@features/system-emails/email.service'; import { EmailNotificationType, RecallPayload } from '@features/system-emails/email.typing'; import { DuplicateCheckValidator, EmailValidator, GenericFile, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; interface RecallFormGroup { clientEmailTemplateId: 0; cc: string[]; bcc: string[]; attachments: GenericFile[]; } @Component({ selector: 'gc-recall-form-modal', templateUrl: './recall-form-modal.component.html', styleUrls: ['./recall-form-modal.component.scss'] }) export class RecallFormModalComponent extends YCModalComponent implements OnInit { @Input() programId: number; @Input() isNomination = false; modalHeader = this.i18n.translate( 'FORMS:textRecallApplicationForm', {}, 'Recall Application Form' ); confirmText = this.i18n.translate( 'FORMS:textAreYouSureRecall', {}, 'Are you sure you want to recall this application form?' ); primaryButtonText = this.i18n.translate( 'FORMS:textRecall', {}, 'Recall' ); currentEmailActive = false; emailType: EmailNotificationType; formGroup: TypeSafeFormGroup; constructor ( private i18n: I18nService, private emailService: EmailService, private formBuilder: TypeSafeFormBuilder, private analyticsService: AnalyticsService ) { super(); } async ngOnInit () { this.emailType = this.isNomination ? EmailNotificationType.NominationFormRecalled : EmailNotificationType.ApplicationFormRecalled; await this.setCurrentEmailActive(); this.formGroup = this.formBuilder.group({ clientEmailTemplateId: 0, cc: [ [], EmailValidator() ], bcc: [ [], EmailValidator() ], attachments: [] }, { validator: [ DuplicateCheckValidator( 'cc', 'bcc' ) ] }); } async setCurrentEmailActive () { this.currentEmailActive = await this.emailService.isProgramEmailActive( this.emailType, this.programId ); } onCancel () { this.closeModal.emit(); } onSubmit () { this.closeModal.emit({ clientEmailTemplateId: this.formGroup.value.clientEmailTemplateId, emailOptionsModel: { ccEmails: this.formGroup.value.cc, bccEmails: this.formGroup.value.bcc, attachments: this.formGroup.value.attachments } }); this.analyticsService.emitEvent({ eventName: 'Recall form modal submit', eventType: EventType.Click, extras: null }); } }