@@ -48,6 +48,7 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
48
48
49
49
static noInfoSign = '' ;
50
50
public loading : boolean ;
51
+ public showBanLoading = false ;
51
52
52
53
protected customers : User [ ] = [ ] ;
53
54
protected orders : Order [ ] = [ ] ;
@@ -59,6 +60,8 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
59
60
private dataCount : number ;
60
61
private $users ;
61
62
63
+ public _showOnlyBanned : boolean ;
64
+
62
65
constructor (
63
66
private readonly _router : Router ,
64
67
private readonly _ordersService : OrdersService ,
@@ -140,8 +143,14 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
140
143
} ) ;
141
144
modal . componentInstance . user = this . _selectedCustomers [ 0 ] ;
142
145
modal . result
143
- . then ( ( id ) => this . _usersService . unbanUser ( id ) )
144
- . catch ( console . error ) ;
146
+ . then ( async ( user ) => {
147
+ this . showBanLoading = true ;
148
+ await this . _usersService . unbanUser ( user . id ) ;
149
+ this . _loadDataSmartTable ( ) ;
150
+ this . showBanLoading = false ;
151
+ this . _notifyService . success ( `${ user . name } is unbanned!` ) ;
152
+ } )
153
+ . catch ( ( _ ) => { } ) ;
145
154
}
146
155
147
156
private showBanPopup ( ) {
@@ -153,8 +162,14 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
153
162
} ) ;
154
163
modal . componentInstance . user = this . _selectedCustomers [ 0 ] ;
155
164
modal . result
156
- . then ( ( id ) => this . _usersService . banUser ( id ) )
157
- . catch ( console . error ) ;
165
+ . then ( async ( user ) => {
166
+ this . showBanLoading = true ;
167
+ await this . _usersService . banUser ( user . id ) ;
168
+ this . _loadDataSmartTable ( ) ;
169
+ this . showBanLoading = false ;
170
+ this . _notifyService . success ( `${ user . name } is banned!` ) ;
171
+ } )
172
+ . catch ( ( _ ) => { } ) ;
158
173
}
159
174
160
175
private _loadSettingsSmartTable ( ) {
@@ -252,7 +267,7 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
252
267
users . map ( ( u ) => u . id )
253
268
) ;
254
269
255
- const usersVM = users . map ( ( user ) => {
270
+ let usersVM = users . map ( ( user ) => {
256
271
const userOrders = usersOrders . find (
257
272
( res ) => res [ 'id' ] === user . id
258
273
) ;
@@ -285,6 +300,10 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
285
300
286
301
await this . loadDataCount ( ) ;
287
302
303
+ if ( this . showOnlyBanned ) {
304
+ usersVM = usersVM . filter ( ( user ) => user . isBanned ) ;
305
+ }
306
+
288
307
const usersData = new Array ( this . dataCount ) ;
289
308
290
309
usersData . splice ( perPage * ( page - 1 ) , perPage , ...usersVM ) ;
@@ -346,6 +365,15 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
346
365
) ;
347
366
}
348
367
368
+ public set showOnlyBanned ( v : boolean ) {
369
+ this . _showOnlyBanned = v ;
370
+ this . _loadDataSmartTable ( ) ;
371
+ }
372
+
373
+ public get showOnlyBanned ( ) : boolean {
374
+ return this . _showOnlyBanned ;
375
+ }
376
+
349
377
ngOnDestroy ( ) {
350
378
this . ngDestroy$ . next ( ) ;
351
379
this . ngDestroy$ . complete ( ) ;
0 commit comments