diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html index 8279155e5..33b40f522 100644 --- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html +++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html @@ -8,6 +8,7 @@ formControlName="name" placeholder="Customer name" [class.is-invalid]="customerForm.invalid && customerForm.touched" + (input)="onSearchChanges($event.target.value)" required /> diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts index df28e9d44..8d531eecb 100644 --- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts +++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.spec.ts @@ -140,4 +140,23 @@ describe('CreateCustomerComponent', () => { expect(component.changeValueAreTabsActives.emit).toHaveBeenCalledWith(component.areTabsActive); }); + it('if detect changes in customer information, it should emit a true', () => { + component.haveChanges = true; + spyOn(component.isHaveChanges, 'emit'); + + component.onSearchChanges('changes text'); + + expect(component.haveChanges).toBe(true); + expect(component.isHaveChanges.emit).toHaveBeenCalledWith(component.haveChanges); + }); + + it('if not detect changes in customer information, it should emit a false', () => { + component.haveChanges = false; + spyOn(component.isHaveChanges, 'emit'); + + component.onSearchChanges(''); + + expect(component.haveChanges).toBe(false); + expect(component.isHaveChanges.emit).toHaveBeenCalledWith(component.haveChanges); + }); }); diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts index 9cb14ae8d..6243824c9 100644 --- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts +++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts @@ -23,6 +23,8 @@ import { LoadCustomerProjects, CleanCustomerProjects } from '../../../projects/c export class CreateCustomerComponent implements OnInit, OnDestroy { customerForm: FormGroup; @Input() areTabsActive: boolean; + @Input() haveChanges: boolean; + @Output() isHaveChanges = new EventEmitter(); @Output() changeValueAreTabsActives = new EventEmitter(); @Output() closeCustomerComponent = new EventEmitter(); customerToEdit: Customer; @@ -68,6 +70,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy { this.store.dispatch(new LoadProjectTypes(customerData.id)); this.store.dispatch(new LoadCustomerProjects(customerData.id)); this.changeValueAreTabsActives.emit(true); + this.isHaveChanges.emit(this.haveChanges = false); this.customerForm.setValue({ name: customerData.name, description: customerData.description, @@ -94,4 +97,9 @@ export class CreateCustomerComponent implements OnInit, OnDestroy { this.store.dispatch(new ResetCustomerToEdit()); this.closeCustomerComponent.emit(false); } + + onSearchChanges(searchValue: string): void { + return searchValue ? this.isHaveChanges.emit(this.haveChanges = true) : + this.isHaveChanges.emit(this.haveChanges = false); + } } diff --git a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html index 09b7a0b76..62db0a46f 100644 --- a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html +++ b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html @@ -20,12 +20,15 @@ {{ customer.name }} +