Skip to content
Snippets Groups Projects
Commit f434e59b authored by Fadil Zemmari's avatar Fadil Zemmari
Browse files

[US TRTL-389] Add customer internal code edition

parent 33df55c0
No related branches found
No related tags found
1 merge request!1Feature/design/1
...@@ -109,6 +109,16 @@ ...@@ -109,6 +109,16 @@
</div> </div>
</ng-container> </ng-container>
<div class="row">
<div class="col-12 form-control">
<vitamui-common-editable-input
formControlName="internalCode"
maxlength="20"
label="Code interne" i18n-label="Internal code@@customerPreviewLabelInternalCode"
></vitamui-common-editable-input>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-12 form-control"> <div class="col-12 form-control">
<vitamui-common-editable-select <vitamui-common-editable-select
......
...@@ -71,6 +71,7 @@ let expectedCustomer: Customer = { ...@@ -71,6 +71,7 @@ let expectedCustomer: Customer = {
city: 'paris', city: 'paris',
country: 'france' country: 'france'
}, },
internalCode: '1',
owners: [], owners: [],
themeColors: {} themeColors: {}
}; };
...@@ -149,6 +150,7 @@ describe('Customer InformationTabComponent', () => { ...@@ -149,6 +150,7 @@ describe('Customer InformationTabComponent', () => {
city: 'paris', city: 'paris',
country: 'france' country: 'france'
}, },
internalCode: '1',
owners: [], owners: [],
themeColors: {} themeColors: {}
}; };
...@@ -201,6 +203,7 @@ describe('Customer InformationTabComponent', () => { ...@@ -201,6 +203,7 @@ describe('Customer InformationTabComponent', () => {
expect(testhost.component.form.get('address.zipCode')).not.toBeNull(); expect(testhost.component.form.get('address.zipCode')).not.toBeNull();
expect(testhost.component.form.get('address.city')).not.toBeNull(); expect(testhost.component.form.get('address.city')).not.toBeNull();
expect(testhost.component.form.get('address.country')).not.toBeNull(); expect(testhost.component.form.get('address.country')).not.toBeNull();
expect(testhost.component.form.get('internalCode')).not.toBeNull();
expect(testhost.component.form.get('language')).not.toBeNull(); expect(testhost.component.form.get('language')).not.toBeNull();
expect(testhost.component.form.get('emailDomains')).not.toBeNull(); expect(testhost.component.form.get('emailDomains')).not.toBeNull();
expect(testhost.component.form.get('defaultEmailDomain')).not.toBeNull(); expect(testhost.component.form.get('defaultEmailDomain')).not.toBeNull();
...@@ -221,6 +224,7 @@ describe('Customer InformationTabComponent', () => { ...@@ -221,6 +224,7 @@ describe('Customer InformationTabComponent', () => {
city: null, city: null,
country: null country: null
}, },
internalCode: null,
language: null, language: null,
emailDomains: null, emailDomains: null,
defaultEmailDomain: null defaultEmailDomain: null
...@@ -269,6 +273,7 @@ describe('Customer InformationTabComponent', () => { ...@@ -269,6 +273,7 @@ describe('Customer InformationTabComponent', () => {
city: expectedCustomer.address.city, city: expectedCustomer.address.city,
country: expectedCustomer.address.country, country: expectedCustomer.address.country,
}, },
internalCode: expectedCustomer.internalCode,
language: expectedCustomer.language, language: expectedCustomer.language,
emailDomains: expectedCustomer.emailDomains, emailDomains: expectedCustomer.emailDomains,
defaultEmailDomain: expectedCustomer.defaultEmailDomain defaultEmailDomain: expectedCustomer.defaultEmailDomain
......
import { OnDestroy } from '@angular/core';
/* /*
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2020) * Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2020)
* and the signatories of the "VITAM - Accord du Contributeur" agreement. * and the signatories of the "VITAM - Accord du Contributeur" agreement.
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
*/ */
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Subscription } from 'rxjs';
import { merge, of } from 'rxjs'; import { merge, of } from 'rxjs';
import { catchError, debounceTime, filter, map, switchMap } from 'rxjs/operators'; import { catchError, debounceTime, filter, map, switchMap } from 'rxjs/operators';
import { Customer, diff, OtpState } from 'ui-frontend-common'; import { Customer, diff, OtpState } from 'ui-frontend-common';
...@@ -51,32 +53,15 @@ const UPDATE_DEBOUNCE_TIME = 200; ...@@ -51,32 +53,15 @@ const UPDATE_DEBOUNCE_TIME = 200;
templateUrl: './information-tab.component.html', templateUrl: './information-tab.component.html',
styleUrls: ['./information-tab.component.scss'] styleUrls: ['./information-tab.component.scss']
}) })
export class InformationTabComponent implements OnInit { export class InformationTabComponent implements OnInit, OnDestroy {
public readonly form: FormGroup;
form: FormGroup;
previousValue: {
code: string,
identifier: string,
name: string,
companyName: string,
passwordRevocationDelay: number,
otp: OtpState,
address: {
street: string,
zipCode: string,
city: string,
country: string,
},
language: string,
emailDomains: string[],
defaultEmailDomain: string
};
@Input() @Input()
set customer(customer: Customer) { set customer(customer: Customer) {
this._customer = customer; this._customer = customer;
this.resetForm(this.customer); this.resetForm(this.customer);
} }
get customer(): Customer { return this._customer; } get customer(): Customer { return this._customer; }
// tslint:disable-next-line:variable-name // tslint:disable-next-line:variable-name
private _customer: Customer; private _customer: Customer;
...@@ -91,6 +76,27 @@ export class InformationTabComponent implements OnInit { ...@@ -91,6 +76,27 @@ export class InformationTabComponent implements OnInit {
} }
} }
private previousValue: {
code: string,
identifier: string,
name: string,
companyName: string,
passwordRevocationDelay: number,
otp: OtpState,
address: {
street: string,
zipCode: string,
city: string,
country: string,
},
internalCode: string,
language: string,
emailDomains: string[],
defaultEmailDomain: string
};
private sub: Subscription;
constructor( constructor(
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private customerService: CustomerService, private customerService: CustomerService,
...@@ -114,24 +120,30 @@ export class InformationTabComponent implements OnInit { ...@@ -114,24 +120,30 @@ export class InformationTabComponent implements OnInit {
city: [null, Validators.required], city: [null, Validators.required],
country: [null, Validators.required], country: [null, Validators.required],
}), }),
internalCode: [null],
language: [null, Validators.required], language: [null, Validators.required],
emailDomains: [null, Validators.required], emailDomains: [null, Validators.required],
defaultEmailDomain: [null, Validators.required] defaultEmailDomain: [null, Validators.required]
}); });
merge(this.form.statusChanges, this.form.valueChanges)
.pipe(
debounceTime(UPDATE_DEBOUNCE_TIME),
filter(() => this.form.valid),
map(() => diff(this.form.value, this.previousValue)),
filter((formData) => !isEmpty(formData)),
map((formData) => extend({ id: this.customer.id }, formData)),
switchMap((formData) => this.customerService.patch(formData).pipe(catchError(() => of(null))))
)
.subscribe((customer: Customer) => this.resetForm(customer));
} }
ngOnInit() { ngOnInit() {
this.sub = merge(this.form.statusChanges, this.form.valueChanges)
.pipe(
debounceTime(UPDATE_DEBOUNCE_TIME),
filter(() => this.form.valid),
map(() => diff(this.form.value, this.previousValue)),
filter((formData) => !isEmpty(formData)),
map((formData) => extend({ id: this.customer.id }, formData)),
switchMap((formData) => this.customerService.patch(formData).pipe(catchError(() => of(null))))
)
.subscribe((customer: Customer) => this.resetForm(customer));
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
}
} }
private resetForm(customer: Customer) { private resetForm(customer: Customer) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment