Skip to content

Commit 05f2448

Browse files
jr-98scastillo-jp
authored andcommitted
fix: TT-29 Warn-of-unsaved-changes-on-customer-page
1 parent 597c66e commit 05f2448

File tree

7 files changed

+78
-22
lines changed

7 files changed

+78
-22
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<div class="container">
2-
<form style="width: 600px;" [formGroup]="customerForm" (ngSubmit)="onSubmit(customerForm.value)">
2+
<form
3+
style="width: 600px;"
4+
[formGroup]="customerForm"
5+
(ngSubmit)="onSubmit(customerForm.value)">
36
<div class="form-group">
47
<input
58
class="form-control form-control-sm"
69
id="customerName"
710
type="text"
811
formControlName="name"
912
placeholder="Customer name"
13+
(keydown)="getStatusCreateCustomerForm()"
1014
[class.is-invalid]="customerForm.invalid && customerForm.touched"
1115
required
1216
/>
@@ -23,10 +27,20 @@
2327
rows="3"
2428
formControlName="description"
2529
placeholder="Customer description"
30+
(keydown)="getStatusCreateCustomerForm()"
2631
></textarea>
2732
</div>
28-
<button type="submit" class="btn btn-primary" [disabled]="!customerForm.valid">Save</button>
29-
<button (click)="resetCustomerForm()" id="cancel" type="button" class="btn btn-secondary mb-2 ml-2 mt-2">
33+
<button
34+
type="submit"
35+
class="btn btn-primary"
36+
[disabled]="!customerForm.valid">
37+
Save
38+
</button>
39+
<button
40+
(click)="resetCustomerForm()"
41+
id="cancel"
42+
type="button"
43+
class="btn btn-secondary mb-2 ml-2 mt-2">
3044
Cancel
3145
</button>
3246
</form>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
2727
@Output() closeCustomerComponent = new EventEmitter<boolean>();
2828
customerToEdit: Customer;
2929
editSubscription: Subscription;
30+
statusForm = false;
3031

3132
constructor(private formBuilder: FormBuilder, private store: Store<CustomerState>) {
3233
this.customerForm = this.formBuilder.group({
@@ -94,4 +95,10 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
9495
this.store.dispatch(new ResetCustomerToEdit());
9596
this.closeCustomerComponent.emit(false);
9697
}
98+
getStatusCreateCustomerForm(){
99+
if (this.customerForm.dirty){
100+
this.statusForm = true;
101+
console.log(this.statusForm)
102+
}
103+
}
97104
}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
class="table table-bordered table-striped mb-0"
55
datatable
66
[dtTrigger]="dtTrigger"
7-
[dtOptions]="dtOptions"
8-
>
7+
[dtOptions]="dtOptions">
98
<thead class="thead-blue">
109
<tr class="d-flex">
1110
<th class="col-5 text-center">Customer ID</th>
@@ -20,19 +19,19 @@
2019
<td class="col-3 text-break">{{ customer.name }}</td>
2120
<td class="col-4 text-center">
2221
<button
23-
(click)="editCustomer(customer.id)"
22+
data-toggle="modal"
23+
data-target="#editModal"
24+
(click)="openEditModal(customer)"
2425
type="button"
25-
class="btn btn-sm btn-primary"
26-
>
26+
class="btn btn-sm btn-primary">
2727
<i class="fa fa-pencil fa-xs"></i>
2828
</button>
2929
<button
3030
data-toggle="modal"
3131
data-target="#deleteModal"
3232
(click)="openModal(customer)"
3333
type="button"
34-
class="btn btn-sm btn-danger ml-2"
35-
>
34+
class="btn btn-sm btn-danger ml-2">
3635
<i class="fa fa-trash-alt fa-xs"></i>
3736
</button>
3837
</td>
@@ -50,6 +49,16 @@
5049
aria-hidden="true"
5150
[title]="'Delete Customer'"
5251
[body]="message"
53-
(closeModalEvent)="deleteCustomer()"
54-
>
52+
(closeModalEvent)="deleteCustomer()">
53+
</app-dialog>
54+
<app-dialog
55+
*ngIf="showModal"
56+
class="modal fade"
57+
id="editModal"
58+
tabindex="-1"
59+
role="dialog"
60+
aria-hidden="true"
61+
[title]="'Edit Customer'"
62+
[body]="message"
63+
(closeModalEvent)="editCustomer()">
5564
</app-dialog>

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from './../../../../store/customer-management.actions';
1414
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
1515
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
16+
import { EntryState } from 'src/app/modules/time-clock/store/entry.reducer';
1617
@Component({
1718
selector: 'app-customer-list',
1819
templateUrl: './customer-list.component.html',
@@ -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

@@ -76,10 +78,10 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
7678
this.dtTrigger.unsubscribe();
7779
}
7880

79-
editCustomer(customerId: string) {
81+
editCustomer() {
8082
this.showCustomerForm = true;
8183
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
82-
this.store.dispatch(new SetCustomerToEdit(customerId));
84+
this.store.dispatch(new SetCustomerToEdit(this.idToEdit));
8385
this.resetProjectFieldsToEdit();
8486
}
8587

@@ -110,4 +112,13 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
110112
this.showModal = true;
111113
}
112114

115+
openEditModal(item: Customer) {
116+
this.idToEdit = item.id;
117+
if (this.showCustomerForm === true) {
118+
this.message = `The changes will lose. Are you sure you change to customer ${item.name}?`;
119+
this.showModal = true;
120+
} else {
121+
this.editCustomer();
122+
}
123+
}
113124
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getCustomerUnderEdition } from './../../store/customer-management.selec
22
import { Customer } from 'src/app/modules/shared/models';
33
import { Store, select } from '@ngrx/store';
44
import { Component, Output, EventEmitter, OnInit } from '@angular/core';
5+
import { Form } from '@angular/forms';
56

67
@Component({
78
selector: 'app-management-customer-projects',
@@ -41,5 +42,4 @@ export class ManagementCustomerProjectsComponent implements OnInit {
4142
showTab(activeTab: string) {
4243
this.activeTab = activeTab;
4344
}
44-
4545
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
<form style="width: 600px;" [formGroup]="projectTypeForm" (ngSubmit)="onSubmit(projectTypeForm.value)">
1+
<form
2+
style="width: 600px;"
3+
[formGroup]="projectTypeForm"
4+
(ngSubmit)="onSubmit(projectTypeForm.value)">
25
<div class="form-group">
3-
<input type="text" class="form-control form-control-sm" id="name" formControlName="name" aria-describedby=""
4-
[class.is-invalid]="name.invalid && name.touched" required placeholder="Name" />
6+
<input
7+
type="text"
8+
class="form-control form-control-sm"
9+
id="name"
10+
formControlName="name"
11+
aria-describedby=""
12+
[class.is-invalid]="name.invalid && name.touched"
13+
required placeholder="Name" />
514
<div class="text-danger" *ngIf="(name.dirty || name.touched) && name.invalid && name.errors.required">
615
Name is required.
716
</div>
817
</div>
918
<div class="form-group">
10-
<textarea class="form-control form-control-sm mt-2" id="descriptionTextArea" rows="3" placeholder="Description"
19+
<textarea
20+
class="form-control form-control-sm mt-2"
21+
id="descriptionTextArea"
22+
rows="3"
23+
placeholder="Description"
1124
formControlName="description"></textarea>
1225
</div>
1326
<button type="submit" class="btn btn-primary" [disabled]="!projectTypeForm.valid">

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<form style="width: 600px;" [formGroup]="projectForm" (ngSubmit)="onSubmit(projectForm.value)">
1+
<form
2+
style="width: 600px;"
3+
[formGroup]="projectForm"
4+
(ngSubmit)="onSubmit(projectForm.value)">
25
<div class="form-group">
36
<input
47
type="text"
@@ -28,8 +31,7 @@
2831
type="reset"
2932
[hidden]="!projectToEdit"
3033
(click)="cancelButton()"
31-
class="btn btn-secondary mb-2 ml-2 mt-2"
32-
>
34+
class="btn btn-secondary mb-2 ml-2 mt-2">
3335
Cancel
3436
</button>
3537
</form>

0 commit comments

Comments
 (0)