import { Component, Input, OnInit } from '@angular/core'; import { CommunicationVisibility } from '@features/communications/communications.typing'; import { FileService, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { YCModalComponent } from '@yourcause/common/modals'; import { ExternalFileFormGroup, ExternalFileModalResponse } from '../application-attachments.typing'; @Component({ selector: 'gc-external-file-modal', templateUrl: './external-file-modal.component.html', styleUrls: ['./external-file-modal.component.scss'] }) export class ExternalFileModalComponent extends YCModalComponent implements OnInit { @Input() isNomination = false; formGroup: TypeSafeFormGroup; selectedFile: File; constructor ( private formBuilder: TypeSafeFormBuilder, private fileService: FileService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { this.formGroup = this.formBuilder.group({ documentVisibility: CommunicationVisibility.ALL_GRANT_MANAGERS, applicantCanView: false }); } async selectFile () { const file = await this.fileService.uploadFile(); if (file) { this.selectedFile = file; } } save (addAnother = false) { this.closeModal.emit({ ...this.formGroup.value, selectedFile: this.selectedFile, addAnother }); this.analyticsService.emitEvent({ eventName: 'Add external file', eventType: EventType.Click, extras: null }); } }