Skip to content

Commit f0bd386

Browse files
authored
Merge pull request #290 from ioet/256_Display_Customer_name_during_their_edition
256 display customer name during their edition
2 parents f8c4b1c + bd68d30 commit f0bd386

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FormGroup, FormBuilder, Validators } from '@angular/forms';
33
import { Store, select } from '@ngrx/store';
44

55
import { Subscription } from 'rxjs';
6-
import { getCustomerById } from './../../../../store/customer-management.selectors';
6+
import { getCustomerUnderEdition } from './../../../../store/customer-management.selectors';
77
import { Customer } from 'src/app/modules/shared/models';
88
import {
99
CustomerState,
@@ -24,7 +24,6 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
2424
@Input() areTabsActive: boolean;
2525
@Output() changeValueAreTabsActives = new EventEmitter<boolean>();
2626
@Output() closeCustomerComponent = new EventEmitter<boolean>();
27-
@Output() sendActivityName = new EventEmitter<string>();
2827
customerToEdit: Customer;
2928
editSubscription: Subscription;
3029

@@ -38,7 +37,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
3837
ngOnInit() {
3938
this.areTabsActive = true;
4039
this.changeValueAreTabsActives.emit(this.areTabsActive);
41-
const customers$ = this.store.pipe(select(getCustomerById));
40+
const customers$ = this.store.pipe(select(getCustomerUnderEdition));
4241
this.editSubscription = customers$.subscribe((customer) => {
4342
this.customerToEdit = customer;
4443
this.setDataToUpdate(this.customerToEdit);
@@ -60,7 +59,6 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
6059
} else {
6160
this.store.dispatch(new CreateCustomer(customerData));
6261
}
63-
this.sendActivityName.emit(customerData.name);
6462
this.areTabsActive = true;
6563
this.changeValueAreTabsActives.emit(this.areTabsActive);
6664
}
@@ -70,11 +68,12 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
7068
this.store.dispatch(new LoadProjectTypes(customerData.id));
7169
this.store.dispatch(new LoadCustomerProjects(customerData.id));
7270
this.changeValueAreTabsActives.emit(true);
73-
this.sendActivityName.emit(customerData.name);
7471
this.customerForm.setValue({
7572
name: customerData.name,
7673
description: customerData.description,
7774
});
75+
} else {
76+
this.customerForm.reset();
7877
}
7978
}
8079

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('CustomerTableListComponent', () => {
8181

8282
params.map((param) =>
8383
it(`on success ${param.actionName} customer, the load all customer action should be triggered`, () => {
84-
const actionSubject = TestBed.get(ActionsSubject) as ActionsSubject;
84+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
8585
const action = {
8686
type: param.actionType,
8787
};
@@ -95,7 +95,7 @@ describe('CustomerTableListComponent', () => {
9595

9696
params.map((param) =>
9797
it(`on success ${param.actionName} customer, the customer form should be disabled`, () => {
98-
const actionSubject = TestBed.get(ActionsSubject) as ActionsSubject;
98+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
9999
const action = {
100100
type: param.actionType,
101101
};
@@ -106,7 +106,7 @@ describe('CustomerTableListComponent', () => {
106106
);
107107

108108
it('on success load customers, the customer list should be populated', () => {
109-
const actionSubject = TestBed.get(ActionsSubject) as ActionsSubject;
109+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
110110
const action = {
111111
type: CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS,
112112
payload: state.data,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export class CustomerListComponent implements OnInit, OnDestroy {
3131
loadCustomersSubscription: Subscription;
3232
changeCustomerSubscription: Subscription;
3333

34-
constructor(private store: Store<Customer>, private actionsSubject$: ActionsSubject) {
35-
}
34+
constructor(private store: Store<Customer>, private actionsSubject$: ActionsSubject) { }
3635

3736
ngOnInit(): void {
3837
this.dtOptions = {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ <h4 class="navbar-brand nav-title">{{customerName}}</h4>
5656
[areTabsActive]="areTabsActive"
5757
(changeValueAreTabsActives)="activeTabs($event)"
5858
(closeCustomerComponent)="closeCustomer($event)"
59-
(sendActivityName)="sendActivityName($event)"
6059
></app-create-customer>
6160
</div>
6261
<div
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
import { Component, Output, EventEmitter } from '@angular/core';
1+
import { getCustomerUnderEdition } from './../../store/customer-management.selectors';
2+
import { Customer } from 'src/app/modules/shared/models';
3+
import { Store, select } from '@ngrx/store';
4+
import { Component, Output, EventEmitter, OnInit } from '@angular/core';
25

36
@Component({
47
selector: 'app-management-customer-projects',
58
templateUrl: './management-customer-projects.component.html',
69
styleUrls: ['./management-customer-projects.component.scss'],
710
})
8-
export class ManagementCustomerProjectsComponent {
11+
export class ManagementCustomerProjectsComponent implements OnInit {
912
@Output() closeCustemerForm = new EventEmitter<boolean>();
1013
areTabsActive: boolean;
1114
activeTab: string;
1215
customerName: string;
13-
constructor() {}
16+
17+
constructor(private store: Store<Customer>) { }
18+
19+
ngOnInit(): void {
20+
const customers$ = this.store.pipe(select(getCustomerUnderEdition));
21+
customers$.subscribe((customer) => {
22+
if (customer) {
23+
this.customerName = customer.name;
24+
} else {
25+
this.customerName = undefined;
26+
}
27+
});
28+
}
1429

1530
activeTabs($areTabsActive: boolean) {
1631
setTimeout(() => {
@@ -26,9 +41,5 @@ export class ManagementCustomerProjectsComponent {
2641
showTab(activeTab: string) {
2742
this.activeTab = activeTab;
2843
}
29-
sendActivityName(event) {
30-
setTimeout(() => {
31-
this.customerName = event;
32-
}, 1);
33-
}
44+
3445
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
1+
import { SetCustomerToEdit } from 'src/app/modules/customer-management/store';
2+
import { provideMockStore, MockStore } from '@ngrx/store/testing';
3+
import { Customer } from 'src/app/modules/shared/models';
14
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
25

36
import { CustomerComponent } from './customer.component';
47

58
describe('CustomerComponent', () => {
69
let component: CustomerComponent;
710
let fixture: ComponentFixture<CustomerComponent>;
11+
let store: MockStore<Customer>;
812

913
beforeEach(async(() => {
1014
TestBed.configureTestingModule({
1115
declarations: [CustomerComponent],
16+
providers: [provideMockStore({ initialState: {} })],
1217
}).compileComponents();
1318
}));
1419

1520
beforeEach(() => {
1621
fixture = TestBed.createComponent(CustomerComponent);
1722
component = fixture.componentInstance;
1823
fixture.detectChanges();
24+
store = TestBed.inject(MockStore);
1925
});
2026

2127
it('should be created', () => {
2228
expect(component).toBeTruthy();
2329
});
2430

31+
it('dispatches an action on activateCustomerForm', () => {
32+
spyOn(store, 'dispatch');
33+
34+
component.activateCustomerForm();
35+
36+
expect(store.dispatch).toHaveBeenCalledWith(new SetCustomerToEdit(null));
37+
});
38+
2539
it('should change te value of var when method is called', () => {
2640
component.showCustomerForm = false;
2741
component.activateCustomerForm();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { Store } from '@ngrx/store';
2+
import { Customer } from 'src/app/modules/shared/models';
3+
import { SetCustomerToEdit } from 'src/app/modules/customer-management/store';
14
import { Component } from '@angular/core';
25

36
@Component({
@@ -9,7 +12,10 @@ export class CustomerComponent {
912
showCustomerForm = false;
1013
activityName: string;
1114

15+
constructor(private store: Store<Customer>) { }
16+
1217
activateCustomerForm() {
18+
this.store.dispatch(new SetCustomerToEdit(null));
1319
this.showCustomerForm = true;
1420
}
1521
closeCustomerForm(event) {

src/app/modules/customer-management/store/customer-management.selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getCustomerId = createSelector(getCustomerState, (state: CustomerSt
2727
}
2828
});
2929

30-
export const getCustomerById = createSelector(allCustomers, customerIdtoEdit, (customers, customerIdToEdit) => {
30+
export const getCustomerUnderEdition = createSelector(allCustomers, customerIdtoEdit, (customers, customerIdToEdit) => {
3131
if (customers) {
3232
return customers.find((customer) => {
3333
return customer.id === customerIdToEdit;

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4343
showlist: boolean;
4444
errorDate: boolean;
4545

46-
constructor(private formBuilder: FormBuilder, private store: Store<Merged>, private renderer: Renderer2) {
46+
constructor(private formBuilder: FormBuilder, private store: Store<Merged>) {
4747
this.entryForm = this.formBuilder.group({
4848
project_id: '',
4949
activity_id: '',

0 commit comments

Comments
 (0)