import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; import { APIAdminClient } from '@core/typings/api/admin-client.typing'; import { PanelTypes, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { Subscription } from 'rxjs'; @Component({ selector: 'gc-client-features-page', templateUrl: './client-features-page.component.html', styleUrls: ['./client-features-page.component.scss'] }) export class ClientFeaturesPageComponent implements OnInit, OnDestroy { @Input() isEdit = false; @Input() client: APIAdminClient.Client; @Output() clientChange = new EventEmitter(); PanelTypes = PanelTypes; formGroup: TypeSafeFormGroup; sub = new Subscription(); constructor ( private formBuilder: TypeSafeFormBuilder ) { } ngOnInit () { this.setFormGroup(); } setFormGroup () { this.formGroup = this.formBuilder.group({ hasInternational: this.client?.hasInternational ?? false, hasNominations: this.client?.hasNominations ?? false, allowApplicantPaymentDesignations: this.client?.allowApplicantPaymentDesignations ?? false, allowApplicantSpecialHandling: this.client?.allowApplicantSpecialHandling ?? false, allowExpeditedPayments: this.client?.allowExpeditedPayments ?? false, allowBudgetOverages: this.client?.allowBudgetOverages ?? false, apEnabled: this.client?.apEnabled ?? false, allowExternalApis: this.client?.allowExternalApis ?? false, canConfigureWebservices: this.client?.canConfigureWebservices ?? false, isTestClient: this.client?.isTestClient ?? false, reserveFunds: this.client?.reserveFunds ?? false, allowExternalEmails: this.client?.allowExternalEmails ?? true }); this.sub.add(this.formGroup.valueChanges.subscribe(() => { this.handleChange(); })); } handleChange () { const formGroupVal = this.formGroup.value; const payload: APIAdminClient.Client = { ...this.client, ...formGroupVal }; this.clientChange.emit(payload); } ngOnDestroy () { this.sub.unsubscribe(); } }