File

projects/storefrontlib/cms-components/myaccount/my-coupons/coupon-claim/coupon-claim.component.ts

Implements

OnInit OnDestroy

Metadata

selector cx-coupon-claim

Index

Properties
Methods

Constructor

constructor(couponService: CustomerCouponService, routingService: RoutingService, messageService: GlobalMessageService)
Parameters :
Name Type Optional
couponService CustomerCouponService No
routingService RoutingService No
messageService GlobalMessageService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

subscription
Type : Subscription
import { Component, OnInit, OnDestroy } from '@angular/core';
import {
  RoutingService,
  CustomerCouponService,
  GlobalMessageService,
  GlobalMessageType,
} from '@spartacus/core';
import { Subscription } from 'rxjs';

@Component({
  template: '',
  selector: 'cx-coupon-claim',
})
export class CouponClaimComponent implements OnInit, OnDestroy {
  subscription: Subscription;

  constructor(
    protected couponService: CustomerCouponService,
    protected routingService: RoutingService,
    protected messageService: GlobalMessageService
  ) {}

  ngOnInit(): void {
    this.routingService
      .getRouterState()
      .subscribe((k) => {
        const couponCode = k.state.params.couponCode;
        if (couponCode) {
          this.couponService.claimCustomerCoupon(couponCode);
          this.subscription = this.couponService
            .getClaimCustomerCouponResultSuccess()
            .subscribe((success) => {
              if (success) {
                this.messageService.add(
                  { key: 'myCoupons.claimCustomerCoupon' },
                  GlobalMessageType.MSG_TYPE_CONFIRMATION
                );
              }
              this.routingService.go({ cxRoute: 'coupons' });
            });
        } else {
          this.routingService.go({ cxRoute: 'notFound' });
        }
      })
      .unsubscribe();
  }

  ngOnDestroy(): void {
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""