import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { ApplicantFormForUI, BaseApplication } from '@core/typings/application.typing'; import { ApplicationViewFormForUI, BaseApplicationForLogic, FormData, FormDefinitionForUi, FormioChanges, FormResponse, FormTranslations } from '@features/configure-forms/form.typing'; import { FormsService } from '@features/configure-forms/services/forms/forms.service'; import { LogicState } from '@features/logic-builder/logic-builder.typing'; import { YcFile, YCTwoWayEmitter } from '@yourcause/common'; import { Observable } from 'rxjs'; @Component({ selector: 'gc-form-response', templateUrl: './form-response.component.html', styleUrls: ['./form-response.component.scss'] }) export class FormResponseComponent implements OnChanges { @Input() form: ApplicationViewFormForUI|ApplicantFormForUI; @Input() programId: number; @Input() formId: number; @Input() readOnly: boolean; @Input() hideSubmitButton = false; @Input() externalFields: Partial; @Input() response: FormResponse; @Input() statusText: string; @Input() statusIcon: string; @Input() statusColor: 'primary'|'secondary'; @Input() isManagerEditingApplicantForm = false; @Input() formSubmit: YCTwoWayEmitter>; @Input() maskingChanged: Observable; @Input() masked: boolean; @Input() savedSignature: YcFile; @Input() requireSignature: boolean; @Input() signatureDescription: string; @Input() supportsBypassSignature: boolean; @Input() orgId: number; @Output() formDataChanged = new EventEmitter(); @Output() externalFieldsChanged = new EventEmitter(); @Output() onChange = new EventEmitter(); @Output() onConditionalVisibilityStateChanged = new EventEmitter >(); @Output() onTranslationsReady = new EventEmitter(); formData: FormData; formDefinition: FormDefinitionForUi[]; completedByMeSection: boolean; isEligibilityForm = false; constructor ( private formService: FormsService ) { } get currentFormType () { if ('formType' in this.form) { return this.form.formType; } else if ('formTypeId' in this.form) { return this.form.formTypeId; } return null; } ngOnChanges (changes: SimpleChanges) { this.isEligibilityForm = this.formService.getIsEligibilityForm(this.formId); if (changes.form || changes.readOnly || changes.response) { this.formDefinition = null; this.formData = null; if (this.response) { setTimeout(() => { this.formData = this.response.formData; this.formDefinition = this.response.formDefinition; }); } } } setFormData (data: FormData) { this.formData = data; if (!this.readOnly) { this.formDataChanged.emit(data); } } }