import { Component, Input, OnInit } from '@angular/core'; import { Validators } from '@angular/forms'; import { AddApplicantModalComponentReturn } from '@core/typings/applicant.typing'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { EmailExtensionValidator, 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 ApplicantFormGroup { firstName: string; lastName: string; email: string; addApplicantAddress: boolean; notifyApplicant: boolean; isEmployeeOfClient: boolean; } @Component({ selector: 'gc-add-applicant-modal', templateUrl: './add-applicant-modal.component.html', styleUrls: ['./add-applicant-modal.component.scss'] }) export class AddApplicantModalComponent extends YCModalComponent implements OnInit { @Input() showAddressOption = false; formGroup: TypeSafeFormGroup; addressFormGroup: TypeSafeFormGroup<{ address1: string; address2: string; city: string; stateProvRegCode: string; countryCode: string; postalCode: string; }>; page = 0; clientName = this.clientSettingsService.clientBranding.name; isNomination = false; primaryButtonText = this.i18n.translate('common:btnSave'); cancelButtonText = this.i18n.translate('common:btnCancel'); showEmployeeCheckbox = this.clientSettingsService.showIsEmployeeOfClientCheckbox; constructor ( private formBuilder: TypeSafeFormBuilder, private i18n: I18nService, private clientSettingsService: ClientSettingsService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { this.formGroup = this.formBuilder.group({ firstName: ['', Validators.required], lastName: ['', Validators.required], email: ['', [ Validators.required, EmailExtensionValidator ]], addApplicantAddress: false, notifyApplicant: false, isEmployeeOfClient: false }); this.addressFormGroup = this.formBuilder.group({ address1: ['', Validators.required], address2: '', city: ['', Validators.required], stateProvRegCode: ['', Validators.required], countryCode: ['', Validators.required], postalCode: ['', Validators.required] }); } applicantCanReceiveEmails () { const email = this.formGroup.get('email').value || ''; if (email.toLowerCase().includes('deactivateduser')) { return false; } else { return true; } } save () { this.closeModal.emit({ ...this.formGroup.value, isEmployeeOfClient: this.clientSettingsService.getIsEmployeeOfClientForPayload( this.formGroup.value.isEmployeeOfClient ), address: { ...this.addressFormGroup.value, address: this.addressFormGroup.value.address1 } }); this.analyticsService.emitEvent({ eventName: 'Add applicant modal submit', eventType: EventType.Click, extras: null }); } _onCancel () { this.closeModal.emit(); } }