|
|
@@ -1,5 +1,8 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { FormControl } from '@angular/forms';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
+import { debounceTime, takeUntil } from 'rxjs/operators';
|
|
|
+import { SortOrder } from 'shared/generated-shop-types';
|
|
|
|
|
|
import { BaseListComponent } from '../../../common/base-list.component';
|
|
|
import { GetCustomerList } from '../../../common/generated-types';
|
|
|
@@ -10,12 +13,38 @@ import { DataService } from '../../../data/providers/data.service';
|
|
|
templateUrl: './customer-list.component.html',
|
|
|
styleUrls: ['./customer-list.component.scss'],
|
|
|
})
|
|
|
-export class CustomerListComponent extends BaseListComponent<GetCustomerList.Query, GetCustomerList.Items> {
|
|
|
+export class CustomerListComponent extends BaseListComponent<GetCustomerList.Query, GetCustomerList.Items>
|
|
|
+ implements OnInit {
|
|
|
+ searchTerm = new FormControl('');
|
|
|
constructor(private dataService: DataService, router: Router, route: ActivatedRoute) {
|
|
|
super(router, route);
|
|
|
super.setQueryFn(
|
|
|
(...args: any[]) => this.dataService.customer.getCustomerList(...args),
|
|
|
data => data.customers,
|
|
|
+ (skip, take) => ({
|
|
|
+ options: {
|
|
|
+ skip,
|
|
|
+ take,
|
|
|
+ filter: {
|
|
|
+ emailAddress: {
|
|
|
+ contains: this.searchTerm.value,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ sort: {
|
|
|
+ createdAt: SortOrder.DESC,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ super.ngOnInit();
|
|
|
+ this.searchTerm.valueChanges
|
|
|
+ .pipe(
|
|
|
+ debounceTime(250),
|
|
|
+ takeUntil(this.destroy$),
|
|
|
+ )
|
|
|
+ .subscribe(() => this.refresh());
|
|
|
+ }
|
|
|
}
|