diff --git a/ui/ui-frontend/projects/identity/src/app/subrogation/customer-select.service.ts b/ui/ui-frontend/projects/identity/src/app/subrogation/customer-select.service.ts index 0a1bdab2e72c0125e382d6fdbc2a77146e3aaaab..111299653af15555841d1a442b7e810748f2c792 100644 --- a/ui/ui-frontend/projects/identity/src/app/subrogation/customer-select.service.ts +++ b/ui/ui-frontend/projects/identity/src/app/subrogation/customer-select.service.ts @@ -48,6 +48,8 @@ import { CustomerApiService } from '../core/api/customer-api.service'; }) export class CustomerSelectService { + private customers: Customer[]; + constructor(private customerApi: CustomerApiService) { } getAll(subrogeable: boolean): Observable<MenuOption[]> { @@ -60,6 +62,7 @@ export class CustomerSelectService { .pipe( catchError(() => of([])), map((results) => { + this.customers = results; return (results || []).map((c: { id: string, code: string, name: string }) => { const label = c.code + ' - ' + c.name; @@ -69,11 +72,7 @@ export class CustomerSelectService { ); } - getAllSubrogableCustomers(): Observable<Customer[]> { - const criterionArray: any[] = [ { key: 'subrogeable', value: true, operator: Operators.equals }]; - const query: SearchQuery = { criteria: criterionArray }; - const httpParams = new HttpParams().set('criteria', JSON.stringify(query)); - return this.customerApi.getAllByParams(httpParams); + getCustomers(): Customer[] { + return this.customers; } - } diff --git a/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.html b/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.html index 487498c66e81e3f78417f5f8439f5da6b811d560..7d3251d5616b39e17f565b7b98072e15bd761971 100644 --- a/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.html +++ b/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.html @@ -7,8 +7,8 @@ <vitamui-common-banner [searchbarPlaceholder]="'Nom de Profil de Subrogation'" (search)="onSearchSubmit($event)"> - <button class="btn primary ml-5"> - Subroger un utilisateur client + <button class="btn primary ml-5" (click)="openUserSubrogationDialog()"> + Subroger un Utilisateur Client </button> </vitamui-common-banner> diff --git a/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.ts b/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.ts index 28937cdf33da2ac6d857147bf9d4c6a3bc752548..8095394b18e174082bdc591767f015cb43538878 100644 --- a/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.ts +++ b/ui/ui-frontend/projects/identity/src/app/subrogation/subrogate-user/subrogate-user.component.ts @@ -38,7 +38,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; import { Subject } from 'rxjs'; -import { switchMap, takeLast, takeUntil } from 'rxjs/operators'; +import { switchMap, takeUntil } from 'rxjs/operators'; import { AppRootComponent, Customer, @@ -61,7 +61,6 @@ export class SubrogateUserComponent extends AppRootComponent implements OnInit, public search: string; private destroyer$ = new Subject(); - private subrogableCustomers: Customer[]; constructor( public dialog: MatDialog, @@ -104,27 +103,22 @@ export class SubrogateUserComponent extends AppRootComponent implements OnInit, this.destroyer$.complete(); } - openUserSubrogationDialog() { + public openUserSubrogationDialog(): void { this.subrogationModalService.open(this.customer.emailDomains); } - changeCustomer(customerId: string) { - this.router.navigate(['..', customerId], { relativeTo: this.route }); + public onSearchSubmit(search: string): void { + this.search = search; } - onSearchSubmit(search: string) { - this.search = search; + private changeCustomer(customerId: string): void { + this.router.navigate(['..', customerId], { relativeTo: this.route }); } - private updateCustomer(customerId: string) { - if (this.subrogableCustomers) { - this.customer = this.subrogableCustomers.find(value => value.id === customerId); - } else { - this.customerSelectService.getAllSubrogableCustomers().pipe(takeLast(1)) - .subscribe((customers: Customer[]) => { - this.subrogableCustomers = customers; - this.updateCustomer(customerId); - }); + private updateCustomer(customerId: string): void { + const customers = this.customerSelectService.getCustomers(); + if (customers) { + this.customer = customers.find(value => value.id === customerId); } }