|  |  |  | import { Component, OnInit } from '@angular/core'; | 
					
						
							|  |  |  | import { MatDialog } from '@angular/material/dialog'; | 
					
						
							|  |  |  | import { MatTableDataSource } from '@angular/material/table'; | 
					
						
							|  |  |  | import { Router } from '@angular/router'; | 
					
						
							|  |  |  | import { ConfirmBoxEvokeService } from '@costlydeveloper/ngx-awesome-popup'; | 
					
						
							|  |  |  | import { tesoMediaWatcherService } from '@teso/services/media-watcher'; | 
					
						
							|  |  |  | import { CouponsModel } from 'app/models/couponsModel'; | 
					
						
							|  |  |  | import { throwIfEmpty } from 'rxjs/operators'; | 
					
						
							|  |  |  | import { AdminNewCouponsComponent } from './AdminNewCoupons/admin-new-coupons.component'; | 
					
						
							|  |  |  | import { CouponsService } from './coupons.service'; | 
					
						
							|  |  |  | import { NewCouponsComponent } from './NewCoupons/new-coupons.component'; | 
					
						
							|  |  |  | import jwt_decode from 'jwt-decode'; | 
					
						
							|  |  |  | import { AuthService } from 'app/core/auth/auth.service'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'app-coupons', | 
					
						
							|  |  |  |   templateUrl: './coupons.component.html', | 
					
						
							|  |  |  |   styleUrls: ['./coupons.component.scss'] | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class CouponsComponent implements OnInit { | 
					
						
							|  |  |  |   activecouponsData: MatTableDataSource<any> = new MatTableDataSource(); | 
					
						
							|  |  |  |   inactivecouponsData: MatTableDataSource<any> = new MatTableDataSource(); | 
					
						
							|  |  |  |   allcoupons: CouponsModel[] = []; | 
					
						
							|  |  |  |   constructor(private router: Router, private _tesoMediaWatcherService: tesoMediaWatcherService, | 
					
						
							|  |  |  |     public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService, | 
					
						
							|  |  |  |     private _couponsService: CouponsService, private _authService: AuthService) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ngOnInit(): void { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this._couponsService.getData().subscribe((response) => { | 
					
						
							|  |  |  |       this.allcoupons = response; | 
					
						
							|  |  |  |       this.activecouponsData.data = this.allcoupons.filter(t => t.status.toLowerCase() == "active"); | 
					
						
							|  |  |  |       this.inactivecouponsData.data = this.allcoupons.filter(t => t.status.toLowerCase() != "active"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   generateCoupons() { | 
					
						
							|  |  |  |     const tokenInfo = this.getDecodedAccessToken(this._authService.relevantToken); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (tokenInfo.businessID != "1TESBU00000000") { | 
					
						
							|  |  |  |       const dialogRef = this.dialog.open(AdminNewCouponsComponent, { | 
					
						
							|  |  |  |         disableClose: true, | 
					
						
							|  |  |  |         hasBackdrop: true, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       const dialogRef = this.dialog.open(NewCouponsComponent, { | 
					
						
							|  |  |  |         disableClose: true, | 
					
						
							|  |  |  |         hasBackdrop: true, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getDecodedAccessToken(token: string): any { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       return jwt_decode(token); | 
					
						
							|  |  |  |     } catch (Error) { | 
					
						
							|  |  |  |       return null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |