From 05f2448eb10fa58f7a118b1e3aac67a062dc02cc Mon Sep 17 00:00:00 2001 From: jr-98 Date: Mon, 1 Mar 2021 15:43:21 -0500 Subject: [PATCH] fix: TT-29 Warn-of-unsaved-changes-on-customer-page --- .../create-customer/create-customer.html | 20 +++++++++++--- .../create-customer/create-customer.ts | 7 +++++ .../customer-list.component.html | 27 ++++++++++++------- .../customer-list/customer-list.component.ts | 15 +++++++++-- .../management-customer-projects.component.ts | 2 +- .../create-project-type.component.html | 21 ++++++++++++--- .../create-project.component.html | 8 +++--- 7 files changed, 78 insertions(+), 22 deletions(-) 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..a6fda73bf 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 @@ -1,5 +1,8 @@
-
+
@@ -23,10 +27,20 @@ rows="3" formControlName="description" placeholder="Customer description" + (keydown)="getStatusCreateCustomerForm()" >
- - +
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..9274b7bc2 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 @@ -27,6 +27,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy { @Output() closeCustomerComponent = new EventEmitter(); customerToEdit: Customer; editSubscription: Subscription; + statusForm = false; constructor(private formBuilder: FormBuilder, private store: Store) { this.customerForm = this.formBuilder.group({ @@ -94,4 +95,10 @@ export class CreateCustomerComponent implements OnInit, OnDestroy { this.store.dispatch(new ResetCustomerToEdit()); this.closeCustomerComponent.emit(false); } + getStatusCreateCustomerForm(){ + if (this.customerForm.dirty){ + this.statusForm = true; + console.log(this.statusForm) + } + } } 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..e0e08cc8c 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 @@ -4,8 +4,7 @@ class="table table-bordered table-striped mb-0" datatable [dtTrigger]="dtTrigger" - [dtOptions]="dtOptions" - > + [dtOptions]="dtOptions"> Customer ID @@ -20,10 +19,11 @@ {{ customer.name }} @@ -50,6 +49,16 @@ aria-hidden="true" [title]="'Delete Customer'" [body]="message" - (closeModalEvent)="deleteCustomer()" -> + (closeModalEvent)="deleteCustomer()"> + + diff --git a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts index e5c9785ed..2a66ad54a 100644 --- a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts +++ b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts @@ -13,6 +13,7 @@ import { } from './../../../../store/customer-management.actions'; import { ResetProjectToEdit } from '../../../projects/components/store/project.actions'; import { ResetProjectTypeToEdit } from '../../../projects-type/store'; +import { EntryState } from 'src/app/modules/time-clock/store/entry.reducer'; @Component({ selector: 'app-customer-list', templateUrl: './customer-list.component.html', @@ -31,6 +32,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit { changeCustomerSubscription: Subscription; showModal = false; idToDelete: string; + idToEdit: string; message: string; isLoading$: Observable; @@ -76,10 +78,10 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit { this.dtTrigger.unsubscribe(); } - editCustomer(customerId: string) { + editCustomer() { this.showCustomerForm = true; this.changeValueShowCustomerForm.emit(this.showCustomerForm); - this.store.dispatch(new SetCustomerToEdit(customerId)); + this.store.dispatch(new SetCustomerToEdit(this.idToEdit)); this.resetProjectFieldsToEdit(); } @@ -110,4 +112,13 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit { this.showModal = true; } + openEditModal(item: Customer) { + this.idToEdit = item.id; + if (this.showCustomerForm === true) { + this.message = `The changes will lose. Are you sure you change to customer ${item.name}?`; + this.showModal = true; + } else { + this.editCustomer(); + } + } } diff --git a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts index 83caacb26..725f9ac1f 100644 --- a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts +++ b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts @@ -2,6 +2,7 @@ import { getCustomerUnderEdition } from './../../store/customer-management.selec import { Customer } from 'src/app/modules/shared/models'; import { Store, select } from '@ngrx/store'; import { Component, Output, EventEmitter, OnInit } from '@angular/core'; +import { Form } from '@angular/forms'; @Component({ selector: 'app-management-customer-projects', @@ -41,5 +42,4 @@ export class ManagementCustomerProjectsComponent implements OnInit { showTab(activeTab: string) { this.activeTab = activeTab; } - } diff --git a/src/app/modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component.html b/src/app/modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component.html index 69ef61d4e..3752351e3 100644 --- a/src/app/modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component.html +++ b/src/app/modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component.html @@ -1,13 +1,26 @@ -
+
- +
Name is required.
-