All files / src/app/pages/account-recurring-order account-recurring-order-page.component.ts

77.77% Statements 14/18
83.33% Branches 5/6
50% Functions 4/8
77.77% Lines 14/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 521x 1x 1x   1x   1x             1x       7x   7x   7x     7x 7x 6x     7x     7x                                      
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Observable, first } from 'rxjs';
 
import { AccountFacade } from 'ish-core/facades/account.facade';
import { RecurringOrder } from 'ish-core/models/recurring-order/recurring-order.model';
import { whenTruthy } from 'ish-core/utils/operators';
 
@Component({
  selector: 'ish-account-recurring-order-page',
  templateUrl: './account-recurring-order-page.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AccountRecurringOrderPageComponent implements OnInit {
  recurringOrder$: Observable<RecurringOrder>;
  private recurringOrder: RecurringOrder;
  taxationID: string;
  showErrorCode = false;
 
  private destroyRef = inject(DestroyRef);
 
  constructor(private accountFacade: AccountFacade) {}
 
  ngOnInit() {
    this.recurringOrder$ = this.accountFacade.selectedRecurringOrder$;
    this.recurringOrder$.pipe(whenTruthy(), first(), takeUntilDestroyed(this.destroyRef)).subscribe(recurringOrder => {
      this.recurringOrder = recurringOrder;
    });
 
    this.accountFacade.customer$
      .pipe(whenTruthy(), first(), takeUntilDestroyed(this.destroyRef))
      .subscribe(customer => {
        this.taxationID = this.taxationID || customer?.taxationID;
      });
  }
 
  switchActiveStatus(switchStatus: { active: boolean }) {
    this.accountFacade.setActiveRecurringOrder(this.recurringOrder.id, switchStatus.active);
  }
 
  // callback function for ishServerHtml link
  get activateRecurringOrder() {
    return () => {
      this.accountFacade.setActiveRecurringOrder(this.recurringOrder.id, true);
    };
  }
 
  toggleShowErrorCode() {
    this.showErrorCode = !this.showErrorCode;
  }
}