Skip to content

Commit 681b2b4

Browse files
committed
fix: TT-26 Warn of un-saved changes on customer page
1 parent 80ccc1f commit 681b2b4

File tree

9 files changed

+70
-6
lines changed

9 files changed

+70
-6
lines changed

src/app/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {NgxMaterialTimepickerModule} from 'ngx-material-timepicker';
7878
// tslint:disable-next-line: max-line-length
7979
import { TechnologyReportTableComponent } from './modules/technology-report/components/technology-report-table/technology-report-table.component';
8080
import { TechnologyReportComponent } from './modules/technology-report/pages/technology-report.component';
81+
import { ModalDialogModule } from 'ngx-modal-dialog';
8182

8283
const maskConfig: Partial<IConfig> = {
8384
validation: false,

src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
formControlName="name"
99
placeholder="Customer name"
1010
[class.is-invalid]="customerForm.invalid && customerForm.touched"
11+
(input)="onSearchChange($event.target.value)"
1112
required
1213
/>
1314
<span
@@ -23,6 +24,7 @@
2324
rows="3"
2425
formControlName="description"
2526
placeholder="Customer description"
27+
(input)="onSearchChange($event.target.value)"
2628
></textarea>
2729
</div>
2830
<button type="submit" class="btn btn-primary" [disabled]="!customerForm.valid">Save</button>

src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { LoadCustomerProjects, CleanCustomerProjects } from '../../../projects/c
2323
export class CreateCustomerComponent implements OnInit, OnDestroy {
2424
customerForm: FormGroup;
2525
@Input() areTabsActive: boolean;
26+
@Input() haveChanges: boolean;
27+
@Output() ishaveChanges = new EventEmitter<boolean>();
2628
@Output() changeValueAreTabsActives = new EventEmitter<boolean>();
2729
@Output() closeCustomerComponent = new EventEmitter<boolean>();
2830
customerToEdit: Customer;
@@ -68,6 +70,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
6870
this.store.dispatch(new LoadProjectTypes(customerData.id));
6971
this.store.dispatch(new LoadCustomerProjects(customerData.id));
7072
this.changeValueAreTabsActives.emit(true);
73+
this.ishaveChanges.emit(this.haveChanges = false);
7174
this.customerForm.setValue({
7275
name: customerData.name,
7376
description: customerData.description,
@@ -94,4 +97,14 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
9497
this.store.dispatch(new ResetCustomerToEdit());
9598
this.closeCustomerComponent.emit(false);
9699
}
100+
101+
onSearchChange(searchValue: string): void {
102+
if (searchValue) {
103+
this.haveChanges = true;
104+
this.ishaveChanges.emit(this.haveChanges);
105+
} else {
106+
this.haveChanges = false;
107+
this.ishaveChanges.emit(this.haveChanges);
108+
}
109+
}
97110
}

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,28 @@
2020
<td class="col-3 text-break">{{ customer.name }}</td>
2121
<td class="col-4 text-center">
2222
<button
23+
data-toggle="modal"
2324
(click)="editCustomer(customer.id)"
2425
type="button"
26+
data-target="#editModal"
2527
class="btn btn-sm btn-primary"
2628
>
27-
<i class="fa fa-pencil fa-xs"></i>
29+
<i class="fa fa-pencil fa-xs">{{ haveChanges}}</i>
2830
</button>
31+
32+
<app-dialog
33+
*ngIf="showModal"
34+
class="modal fade"
35+
id="editModal"
36+
tabindex="-1"
37+
role="dialog"
38+
aria-hidden="true"
39+
[title]="'Edit Customer'"
40+
[body]="message"
41+
(closeModalEvent)="discardChanges(customer.id)"
42+
>
43+
</app-dialog>
44+
2945
<button
3046
data-toggle="modal"
3147
data-target="#deleteModal"
@@ -52,4 +68,4 @@
5268
[body]="message"
5369
(closeModalEvent)="deleteCustomer()"
5470
>
55-
</app-dialog>
71+
</app-dialog>

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ResetProjectTypeToEdit } from '../../../projects-type/store';
2020
})
2121
export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
2222
@Input() showCustomerForm: boolean;
23+
@Input() haveChanges: boolean;
2324
@Output() changeValueShowCustomerForm = new EventEmitter<boolean>();
2425
@Input()
2526
customers: Customer[] = [];
@@ -31,6 +32,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
3132
changeCustomerSubscription: Subscription;
3233
showModal = false;
3334
idToDelete: string;
35+
idToEdit: string;
3436
message: string;
3537
isLoading$: Observable<boolean>;
3638

@@ -77,10 +79,24 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
7779
}
7880

7981
editCustomer(customerId: string) {
82+
if (this.haveChanges === true) {
83+
this.message = `Do you have changes in a client, do you want to discard them?`;
84+
this.showModal = true;
85+
} else {
86+
this.showCustomerForm = true;
87+
this.showModal = false;
88+
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
89+
this.resetProjectFieldsToEdit();
90+
this.store.dispatch(new SetCustomerToEdit(customerId));
91+
}
92+
}
93+
94+
discardChanges(customerId: string) {
8095
this.showCustomerForm = true;
96+
this.showModal = false;
8197
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
82-
this.store.dispatch(new SetCustomerToEdit(customerId));
8398
this.resetProjectFieldsToEdit();
99+
this.store.dispatch(new SetCustomerToEdit(customerId));
84100
}
85101

86102
private resetProjectFieldsToEdit() {
@@ -109,5 +125,4 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
109125
this.message = `Are you sure you want to delete ${item.name}?`;
110126
this.showModal = true;
111127
}
112-
113128
}

src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ <h4 class="navbar-brand nav-title">{{customerName}}</h4>
5555
<app-create-customer
5656
[areTabsActive]="areTabsActive"
5757
(changeValueAreTabsActives)="activeTabs($event)"
58+
(ishaveChanges)="getChangesInputs($event)"
5859
(closeCustomerComponent)="closeCustomer($event)"
5960
></app-create-customer>
6061
</div>

src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { Component, Output, EventEmitter, OnInit } from '@angular/core';
1010
})
1111
export class ManagementCustomerProjectsComponent implements OnInit {
1212
@Output() closeCustemerForm = new EventEmitter<boolean>();
13+
@Output() sendChanges = new EventEmitter<boolean>();
1314
areTabsActive: boolean;
15+
haveChanges: boolean;
1416
activeTab: string;
1517
customerName: string;
1618

@@ -42,4 +44,10 @@ export class ManagementCustomerProjectsComponent implements OnInit {
4244
this.activeTab = activeTab;
4345
}
4446

47+
getChangesInputs($haveChanges: boolean) {
48+
setTimeout(() => {
49+
this.haveChanges = $haveChanges;
50+
this.sendChanges.emit($haveChanges);
51+
}, 1);
52+
}
4553
}

src/app/modules/customer-management/pages/customer.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
</div>
77
<app-customer-list
88
[showCustomerForm]="showCustomerForm"
9+
[haveChanges]="haveChanges"
910
(changeValueShowCustomerForm)="showCustomerForm = $event"
1011
></app-customer-list>
1112
<div class="row" *ngIf="showCustomerForm">
1213
<div class="col">
13-
<app-management-customer-projects (closeCustemerForm)="closeCustomerForm($event)"></app-management-customer-projects>
14+
<app-management-customer-projects (sendChanges)="getChangesInputs($event)" (closeCustemerForm)="closeCustomerForm($event)"></app-management-customer-projects>
1415
</div>
1516
</div>
1617
</div>

src/app/modules/customer-management/pages/customer.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Store } from '@ngrx/store';
22
import { Customer } from 'src/app/modules/shared/models';
33
import { SetCustomerToEdit } from 'src/app/modules/customer-management/store';
4-
import { Component } from '@angular/core';
4+
import { Component, Output, EventEmitter } from '@angular/core';
55

66
@Component({
77
selector: 'app-customer',
@@ -10,6 +10,8 @@ import { Component } from '@angular/core';
1010
})
1111
export class CustomerComponent {
1212
showCustomerForm = false;
13+
haveChanges = false;
14+
1315
activityName: string;
1416

1517
constructor(private store: Store<Customer>) { }
@@ -21,4 +23,9 @@ export class CustomerComponent {
2123
closeCustomerForm(event) {
2224
this.showCustomerForm = event;
2325
}
26+
27+
getChangesInputs(event) {
28+
this.haveChanges = event;
29+
}
30+
2431
}

0 commit comments

Comments
 (0)