import { Component, Input, OnInit } from '@angular/core'; import { FormReminderModalResponse } from '@features/configure-forms/form.typing'; import { EmailService } from '@features/system-emails/email.service'; import { EmailNotificationType } from '@features/system-emails/email.typing'; import { DuplicateCheckValidator, EmailValidator, GenericFile, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; interface FormReminderGroup { comments: string; clientEmailTemplateId: number; attachments: GenericFile[]; cc: string[]; bcc: string[]; } @Component({ selector: 'gc-form-reminder-modal', templateUrl: './form-reminder-modal.component.html', styleUrls: ['./form-reminder-modal.component.scss'] }) export class FormReminderModalComponent extends YCModalComponent implements OnInit { @Input() formName: string; @Input() programId: number; @Input() isNomination = false; formGroup: TypeSafeFormGroup; confirmText: string; currentEmailActive: boolean; constructor ( private i18n: I18nService, private formBuilder: TypeSafeFormBuilder, private emailService: EmailService ) { super(); } get emailType (): EmailNotificationType { return this.isNomination ? EmailNotificationType.FormToCompleteNomination : EmailNotificationType.FormToCompleteApplication; } async ngOnInit () { this.currentEmailActive = await this.emailService.isProgramEmailActive( this.emailType, this.programId ); this.confirmText = this.i18n.translate( this.isNomination ? 'FORMS:textSendReminderConfirmNomination' : 'FORMS:textSendReminderConfirm', { formName: this.formName }, `You are about to send a reminder email to ${ this.isNomination ? 'nominators' : 'applicants' } on this ${this.isNomination ? 'nomination' : 'application'} to submit the __formName__ form.` ); this.formGroup = this.formBuilder.group({ comments: '', clientEmailTemplateId: 0, attachments: [], cc: [ [], EmailValidator() ], bcc: [ [], EmailValidator() ] }, { validator: [ DuplicateCheckValidator( 'cc', 'bcc' ) ] }); } onCancel () { this.closeModal.emit(); } onSubmit () { const payload = { ...this.formGroup.value, emailOptionsModel: { ccEmails: this.formGroup.value.cc, bccEmails: this.formGroup.value.bcc, attachments: this.formGroup.value.attachments } }; this.closeModal.emit(payload); } }