import { Component, Input, OnInit } from '@angular/core'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; import { SaveForm, SaveFormOptions } from '../form.typing'; @Component({ selector: 'gc-save-form-modal', templateUrl: './save-form-modal.component.html', styleUrls: ['./save-form-modal.component.scss'] }) export class SaveFormModalComponent extends YCModalComponent implements OnInit { @Input() data: SaveForm; @Input() revisionVersion: string; @Input() updatingLatest = true; @Input() doNotAllowUpdateCurrentRevision = false; SaveFormOptions = SaveFormOptions; confirmText: string; alertText: string; constructor ( private i18n: I18nService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { if (this.updatingLatest) { this.confirmText = this.i18n.translate( this.doNotAllowUpdateCurrentRevision ? 'FORMS:textConfirmSaveFormModalDesc2' : 'FORMS:textConfirmSaveFormModalDesc', {}, this.doNotAllowUpdateCurrentRevision ? 'You have updated a published form. You must create a new revision to save your changes.' : `You have updated the form. If you want to update this form for new submissions only, click 'Create new revision'. If you want to update this form for all previous and new submissions, click 'Update current revision'.` ); this.alertText = this.i18n.translate( 'FORMS:textConfirmSaveFormModalAlert', {}, 'Please be aware historical responses may be lost if you remove components or component values when updating the current revision. Form exports and downloads will no longer display removed component data.' ); } else { this.confirmText = this.i18n.translate( 'FORMS:textConfirmSaveFormOldRevision', {}, 'You have updated the form for a previous revision. Saving these changes will update the form for all submissions using this revision.' ); this.alertText = this.i18n.translate( 'FORMS:textConfirmSaveFormModalPreviousAlert', {}, 'Please be aware historical responses may be lost if you remove components or component values when updating the previous revision. Form exports and downloads will no longer display removed component data.' ); } } onPrimaryClick () { if (this.updatingLatest) { this.closeModal.emit(SaveFormOptions.CREATE_NEW_REVISION); this.analyticsService.emitEvent({ eventName: 'Create new revision', eventType: EventType.Click, extras: null }); } else { this.closeModal.emit(SaveFormOptions.UPDATE_CURRENT_REVISION); this.analyticsService.emitEvent({ eventName: 'Update current revision', eventType: EventType.Click, extras: null }); } } onSecondaryClick () { this.closeModal.emit(SaveFormOptions.UPDATE_CURRENT_REVISION); this.analyticsService.emitEvent({ eventName: 'Update current revision', eventType: EventType.Click, extras: null }); } }