import { Component, Input, OnInit } from '@angular/core'; import { Validators } from '@angular/forms'; import { SpinnerService } from '@core/services/spinner.service'; import { ReminderResponse } from '@core/typings/application.typing'; import { WorkflowLevelUser } from '@core/typings/workflow.typing'; import { EmailService } from '@features/system-emails/email.service'; import { EmailNotificationType } from '@features/system-emails/email.typing'; import { UserService } from '@features/users/user.service'; import { WorkflowService } from '@features/workflow/workflow.service'; import { ArrayHelpersService, GenericFile, TypeaheadSelectOption, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { YCModalComponent } from '@yourcause/common/modals'; interface ReminderFormGroup { users: number[]; clientEmailTemplateId: number; attachments: GenericFile[]; } @Component({ selector: 'gc-reminder-modal', templateUrl: './reminder-modal.component.html' }) export class ReminderModalComponent extends YCModalComponent implements OnInit { @Input() workflowId: number; @Input() workflowLevelId: number; @Input() programId: number; @Input() applicationId: number; @Input() isNomination = false; userId = this.userService.user.id; formGroup: TypeSafeFormGroup; EmailTypes = EmailNotificationType; userOptions: TypeaheadSelectOption[] = []; workflowLevelUsers: WorkflowLevelUser[] = []; constructor ( private formBuilder: TypeSafeFormBuilder, private userService: UserService, private emailService: EmailService, private spinnerService: SpinnerService, private arrayHelper: ArrayHelpersService, private workflowService: WorkflowService, private analyticsService: AnalyticsService ) { super(); } get emailType () { return this.isNomination ? this.EmailTypes.NominationReviewReminder : this.EmailTypes.ApplicationReviewReminderForClientUser; } async ngOnInit () { this.spinnerService.startSpinner(); this.workflowLevelUsers = await this.workflowService.getWorkflowLevelUsers( this.workflowId, this.workflowLevelId ); this.userOptions = this.arrayHelper.sort( this.workflowLevelUsers .filter((user) => +user.clientUserId !== +this.userId) .map((user) => { return { label: user.firstName + ' ' + user.lastName, value: user.clientUserId }; }), 'label' ); this.formGroup = this.formBuilder.group({ users: [[], Validators.required], clientEmailTemplateId: 0, attachments: [] }); this.spinnerService.stopSpinner(); } async onSave () { this.spinnerService.startSpinner(); const formValue = this.formGroup.value; const attachments = await this.emailService.returnIdsFromMixedAttachments( formValue.attachments, this.applicationId ); this.closeModal.emit({ users: formValue.users, clientEmailTemplateId: formValue.clientEmailTemplateId, emailOptionsModel: { ccEmails: [], bccEmails: [], attachments } }); this.spinnerService.stopSpinner(); this.analyticsService.emitEvent({ eventName: 'Reminder modal submit', eventType: EventType.Click, extras: null }); } }