Teso Business 2.0 angular source code https://bacwaredev.barhendev.com/teso
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

import { Component, OnInit } from '@angular/core';
3 years ago
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';
3 years ago
import { CouponsModel } from 'app/models/couponsModel';
import { throwIfEmpty } from 'rxjs/operators';
3 years ago
import { AdminNewCouponsComponent } from './AdminNewCoupons/admin-new-coupons.component';
3 years ago
import { CouponsService } from './coupons.service';
3 years ago
import { NewCouponsComponent } from './NewCoupons/new-coupons.component';
3 years ago
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 {
3 years ago
activecouponsData: MatTableDataSource<any> = new MatTableDataSource();
inactivecouponsData: MatTableDataSource<any> = new MatTableDataSource();
3 years ago
allcoupons: CouponsModel[] = [];
3 years ago
constructor(private router: Router, private _tesoMediaWatcherService: tesoMediaWatcherService,
3 years ago
public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService,
private _couponsService: CouponsService, private _authService: AuthService) {
}
ngOnInit(): void {
3 years ago
3 years ago
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");
});
}
3 years ago
generateCoupons() {
const tokenInfo = this.getDecodedAccessToken(this._authService.relevantToken);
if (tokenInfo.businessID != "1TESBU00000000") {
const dialogRef = this.dialog.open(AdminNewCouponsComponent, {
3 years ago
disableClose: true,
hasBackdrop: true,
});
} else {
3 years ago
const dialogRef = this.dialog.open(NewCouponsComponent, {
3 years ago
disableClose: true,
hasBackdrop: true,
});
3 years ago
}
}
getDecodedAccessToken(token: string): any {
try {
return jwt_decode(token);
} catch (Error) {
return null;
3 years ago
}
}
}