import { Component, Input, OnInit } from '@angular/core'; import { SFTPAPI } from '@core/typings/api/sftp.typing'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-delete-credentials-modal', templateUrl: './delete-credentials-modal.component.html', styleUrls: ['./delete-credentials-modal.component.scss'] }) export default class DeleteCredentialsModalComponent extends YCModalComponent implements OnInit { @Input() id: number; @Input() context: string; @Input() name: string; @Input() reports: SFTPAPI.Report[]; modalHeader: string; modalText: string; primaryButtonText: string; cancelButtonText: string; constructor ( private i18n: I18nService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { this.setModalText(); } handlePrimaryClick () { if (this.context === 'able') { this.closeModal.emit(this.id); this.analyticsService.emitEvent({ eventName: 'Delete SFTP credentials', eventType: EventType.Click, extras: null }); } else { this.closeModal.emit(); } } setModalText () { switch (this.context) { case 'able': this.modalHeader = this.i18n.translate( 'CONFIG:textDeleteConnectionUpdated', {}, 'Delete Connection' ); this.primaryButtonText = this.i18n.translate( 'common:btnDelete', {}, 'Delete' ); this.cancelButtonText = this.i18n.translate( 'common:btnCancel', {}, 'Cancel' ); this.modalText = this.i18n.translate( 'CONFIG:textDeleteConnectionText', {}, 'Deleting this SFTP connection will prevent it from being used for scheduled or manually sent reports. Are you sure you want to delete it?' ); break; case 'unable': this.modalHeader = this.i18n.translate( 'CONFIG:textUnableToDeleteConnection', {}, 'Unable to Delete Connection' ); this.primaryButtonText = this.i18n.translate( 'common:textClose', {}, 'Close' ); this.modalText = this.i18n.translate( 'CONFIG:textUnableToDeleteConnectionText', {}, 'This connection cannot be deleted because it is in use by one or more reports. In order to delete it, please remove it from the following reports:' ); break; } } }