import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { RelationTypesActions } from '@onepoint-yap/dashboard'; import { mergeMap } from 'rxjs/operators'; import { AdminActions } from './admin.actions'; import { AdminService } from './admin.service'; @Injectable() export class AdminEffects { routeTo$ = createEffect(() => this.actions$.pipe( ofType(AdminActions.routeTo), mergeMap((action) => { this.router.navigate([action.path], { queryParams: action.params }); return action.path === this.router.url ? [] : [AdminActions.resetActions()]; }) ) ); deleteRelationTypeSuccess$ = createEffect(() => this.actions$.pipe( ofType(RelationTypesActions.deleteRelationTypeSuccess), mergeMap((action) => { return [ RelationTypesActions.load(), AdminActions.selectComponentType({ componentType: null }), AdminActions.mainActions({ actions: [ { action: RelationTypesActions.openModal(), label: 'add', icon: 'add_column', moduleAccess: 'admin', pageAccess: 'relation_types', actionAccess: 'write' } ] }) ]; }) ) ); closePanel$ = createEffect(() => this.actions$.pipe( ofType(AdminActions.highlightMenu), mergeMap((action) => { return [AdminActions.togglePanel({ panelOpen: false })]; }) ) ); constructor(private actions$: Actions, private service: AdminService, private router: Router) {} }