graycoreio/daffodil

View on GitHub
libs/customer/routing/src/guards/clear-errors.guard.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Injectable } from '@angular/core';
import { UrlTree } from '@angular/router';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';

import { DaffCustomerClearErrors } from '@daffodil/customer/state';

/**
 * A guard that will clear customer state errors before allowing route deactivation.
 */
@Injectable({ providedIn: 'root' })
export class DaffCustomerClearErrorsGuard  {
  constructor(private store: Store<any>) {}

  canDeactivate(): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
    this.store.dispatch(new DaffCustomerClearErrors());
    return true;
  }
}