import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Action } from '@ngrx/store'; import { Effect, Actions, ofType } from '@ngrx/effects'; import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; import * as subActions from '@app/actions/subscription.actions'; import { SUB } from '../profile/common'; import { AC } from '@app/shared/global'; @Injectable() export class RoutingEffects { constructor( private router: Router, private actions$: Actions ) { } @Effect({ dispatch: false }) gotoMyservices$: Observable = this.actions$.pipe( ofType(subActions.GOTO_MY_SERVICES), tap(() => this.router.navigate([SUB.PROFILE, SUB.MY_SERVICES]).then(() => window.location.reload())) ); @Effect({ dispatch: false }) gotoServices$: Observable = this.actions$.pipe( ofType(subActions.GOTO_SERVICES), tap(() => this.router.navigate([SUB.PROFILE, SUB.SERVICES])) ); @Effect({ dispatch: false }) gotPaymentHistory$: Observable = this.actions$.pipe( ofType(subActions.GOTO_PAYMENT_HISTORY), tap(() => this.router.navigate([SUB.PROFILE, SUB.PM_HISTORY])) ); @Effect({ dispatch: false }) gotPaymentDetail$: Observable = this.actions$.pipe( ofType(subActions.GOTO_PAYMENT_DETAIL), tap((action: subActions.GotoPaymentDetail) => this.router.navigate([SUB.PROFILE, SUB.PM_DETAIL, action.payload.paymentId])) ); @Effect({ dispatch: false }) gotoUnpaidSub$: Observable = this.actions$.pipe( ofType(subActions.SHOW_UNPAID_SUBSCRIPTION), tap(() => this.router.navigate([SUB.PROFILE, SUB.UNPAID_SUB])) ); @Effect({ dispatch: false }) gotoBillingAddr$: Observable = this.actions$.pipe( ofType(subActions.START_BILLING_INFO_SUCCESS, subActions.GOTO_BILLING_ADDRESS), tap(() => this.router.navigate([SUB.PROFILE, SUB.BILL_ADR])) ); @Effect({ dispatch: false }) gotoCheckout$: Observable = this.actions$.pipe( ofType(subActions.UPDATE_BILLING_ADDRESS_SUCCESS, subActions.GOTO_CHECK_OUT, subActions.START_CHECKOUT_SUCCESS), tap(() => this.router.navigate([SUB.PROFILE, SUB.CHKOUT])) ); @Effect({ dispatch: false }) gotoCheckoutReview$: Observable = this.actions$.pipe( ofType(subActions.CHECK_OUT, subActions.RESOLVE_PAYMENT, subActions.GOTO_CHECK_OUT_REVIEW), tap(() => this.router.navigate([SUB.PROFILE, SUB.CHKOUT_REV])) ); @Effect({ dispatch: false }) gotoCheckoutConfirm$: Observable = this.actions$.pipe( ofType(subActions.GOTO_CHECK_OUT_CONFIRM, subActions.PAY_UNPAID_SUBSCRIPTION_SUCCESS, subActions.CONFIRM_ACTION_SUCCESS, subActions.CONFIRM_PAYMENT_SUCCESS, subActions.CHECK_OUT_TRIAL_SUCCESS), tap(() => this.router.navigate([SUB.PROFILE, SUB.CHKOUT_CONF])) ); @Effect({ dispatch: false }) gotoHome$: Observable = this.actions$.pipe( ofType(subActions.GOTO_HOME), tap(() => this.router.navigate(['/', SUB.HOME])) ); @Effect({ dispatch: false }) gotoUsageDetail$: Observable = this.actions$.pipe( ofType(subActions.GOTO_USAGE_DETAIL), tap(() => this.router.navigate([SUB.PROFILE, SUB.USAGE_DETAIL])) ); @Effect({ dispatch: false }) gotoAircraftList$: Observable = this.actions$.pipe( ofType(subActions.GOTO_AIRCRAFT_LIST), tap(() => this.router.navigate(['entities', AC])) ); }