import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { TournamentTicketsService } from 'src/app/shared/services/tournament.tickets.service'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; import { TournamentService } from 'src/app/shared/services/tournament.service'; import { UtilityService } from 'src/app/shared/services/utility.service'; import { ScrollToService } from '@nicky-lenaers/ngx-scroll-to'; import { TicketCheckoutComponent } from './ticket-checkout/ticket-checkout.component'; import { TourneeFeeCheckoutComponent } from './tournee-fee-checkout/tournee-fee-checkout.component'; @Component({ selector: 'app-checkout', templateUrl: './checkout.component.html', styleUrls: ['./checkout.component.css'], providers: [ TournamentTicketsService, TournamentService ] }) export class CheckoutComponent implements OnInit { @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; @ViewChild('TicketCheckout') TicketCheckout:TicketCheckoutComponent; @ViewChild('TourneFeeCheckout') TourneFeeCheckout:TourneeFeeCheckoutComponent; isWorking: boolean = false; Url: string = '/'; constructor(public utility: UtilityService, private _route: ActivatedRoute, private _router: Router, private _scrollToService: ScrollToService) { } ngOnInit() { this._route.parent.params.subscribe(params => { if (params['url']) { this.Url = this.Url + params['url'] + '/'; } this.load() .then(() => { this._scrollToService.scrollTo(UtilityService.scroll_to_head); this.isWorking = false; }) .catch((err) => { this.isWorking = false; console.log(err); if (!err) { this._router.navigate(['/404']); } else { this.FeedbackPanel.triggerError(err); } }); }); } load() { return new Promise((resolve, reject) => { this._route.queryParams.subscribe(params => { this.isWorking = true; if (params['st'] == 't') { this.TicketCheckout.load(params, this.Url) .then(resolve) .catch(reject); } else if (params['st'] == 'tf') { this.TourneFeeCheckout.load(params, this.Url) .then(resolve) .catch(reject); } else { return reject(new Error("Invalid request")) } }); }) } }