Skip to content

Commit e536584

Browse files
committed
fix: TT-29 refactor function
1 parent 673c472 commit e536584

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
111111
this.showModal = false;
112112
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
113113
this.resetProjectFieldsToEdit();
114-
if (this.currentCustomerIdToEdit === this.idToEdit) {
115-
this.store.dispatch(new ResetCustomerToEdit());
116-
}
114+
this.checkResetCustomerToEdit(this.idToEdit);
117115
this.store.dispatch(new SetCustomerToEdit(this.idToEdit));
118116
}
119117

@@ -125,8 +123,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
125123
}
126124

127125
deleteCustomer() {
128-
if (this.idToDelete === this.currentCustomerIdToEdit) {
129-
this.store.dispatch(new ResetCustomerToEdit());
126+
if (this.checkResetCustomerToEdit(this.idToDelete)) {
130127
this.resetProjectFieldsToEdit();
131128
}
132129
this.store.dispatch(new DeleteCustomer(this.idToDelete));
@@ -144,6 +141,14 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
144141
}
145142
}
146143

144+
private checkResetCustomerToEdit(id: string): boolean {
145+
const isResetCustomerToEdit = this.currentCustomerIdToEdit === id;
146+
if (isResetCustomerToEdit) {
147+
this.store.dispatch(new ResetCustomerToEdit());
148+
}
149+
return isResetCustomerToEdit;
150+
}
151+
147152
openModal(item: Customer) {
148153
this.idToDelete = item.id;
149154
this.message = `Are you sure you want to delete ${item.name}?`;

0 commit comments

Comments
 (0)