import { Component, Input, OnInit } from '@angular/core'; import { EmailNotificationType } 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'; export interface NotifyStatusFormGroup { customMessage: string; attachments: GenericFile[]; cc: string[]; bcc: string[]; clientEmailTemplateId: number; } @Component({ selector: 'gc-notify-status-modal', templateUrl: './notify-status-modal.component.html', styleUrls: ['./notify-status-modal.component.scss'] }) export class NotifyStatusModalComponent extends YCModalComponent implements OnInit { @Input() isNomination = false; @Input() single: boolean; modalHeader = ''; formGroup: TypeSafeFormGroup; confirmText = ''; constructor ( private i18n: I18nService, private formBuilder: TypeSafeFormBuilder, private analyticsService: AnalyticsService ) { super(); } get singleTurnary () { return this.single ? '' : 's'; } get emailType () { return this.isNomination ? EmailNotificationType.NominationStatusWithCustomMsgForApplicant : EmailNotificationType.ApplicationStatusWithCustomMsgForApplicant; } ngOnInit () { if (this.isNomination) { this.modalHeader = this.i18n.translate( this.single ? 'MANAGE:textNotifyNominatorOfStatus' : 'MANAGE:textNotifyNominatorsOfStatus', {}, `Notify Nominator${this.singleTurnary} of Status` ); this.confirmText = this.i18n.translate( this.single ? 'MANAGE:textNotifyNominatorOfStatusDesc' : 'MANAGE:textNotifyNominatorsOfStatusDesc', {}, `You are about to send an email to the nominator${this.singleTurnary} that will inform them of the current status of their nomination.` ); } else { this.modalHeader = this.i18n.translate( this.single ? 'MANAGE:textNotifyApplicantOfStatus' : 'MANAGE:textNotifyApplicantsOfStatus', {}, `Notify Applicant${this.singleTurnary} of Status` ); this.confirmText = this.i18n.translate( this.single ? 'MANAGE:textNotifyApplicantOfStatusDesc' : 'MANAGE:textNotifyApplicantsOfStatusDesc', {}, `You are about to send an email to the applicant${this.singleTurnary} that will inform them of the current status of their application.` ); } this.formGroup = this.formBuilder.group({ customMessage: '', attachments: [], cc: [ [], EmailValidator() ], bcc: [ [], EmailValidator() ], clientEmailTemplateId: 0 }, { validator: [ DuplicateCheckValidator( 'cc', 'bcc' ) ] }); } onCancel () { this.closeModal.emit(); } onSubmit () { this.closeModal.emit(this.formGroup.value); this.analyticsService.emitEvent({ eventName: 'Notify status modal submit', eventType: EventType.Click, extras: null }); } }