import { Component, Input, OnInit } from '@angular/core'; import { DuplicateCheckValidator, EmailValidator, GenericFile, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { YCModalComponent } from '@yourcause/common/modals'; import { InvitationService } from '../invitation.service'; import { InvitationRecord, SendReminderModalResponse } from '../invitation.typing'; interface ResendGroup { clientEmailTemplateId: number; cc: string[]; bcc: string[]; attachments: GenericFile[]; } @Component({ selector: 'gc-resend-invitation-modal', templateUrl: './resend-invitation-modal.component.html', styleUrls: ['./resend-invitation-modal.component.scss'] }) export class ResendInvitationModalComponent extends YCModalComponent< SendReminderModalResponse > implements OnInit { @Input() isReminder = false; @Input() invitation: InvitationRecord; formGroup: TypeSafeFormGroup; ready = false; reminderEmailType = this.invitationService.reminderEmailType; constructor ( private formBuilder: TypeSafeFormBuilder, private invitationService: InvitationService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { this.formGroup = this.formBuilder.group({ clientEmailTemplateId: 0, attachments: [], cc: [ [], EmailValidator() ], bcc: [ [], EmailValidator() ] }, { validator: [ DuplicateCheckValidator( 'cc', 'bcc' ) ] }); this.ready = true; } onSubmit () { const payload: SendReminderModalResponse = { clientEmailTemplateId: this.formGroup.value.clientEmailTemplateId, emailOptionsModel: { ccEmails: this.formGroup.value.cc, bccEmails: this.formGroup.value.bcc, attachments: this.formGroup.value.attachments } }; this.closeModal.emit(payload); this.analyticsService.emitEvent({ eventName: 'Resend invitation modal submit', eventType: EventType.Click, extras: null }); } }