I need your help. I have a modal that I'm trying to show right after login. My effect and code inside ngOnInit
only fire once, after I've logged in. This code is not working correctly for me, because my condition for showing the modal window is true, but immediately after showing my modal, a redirect happens, regarding the conditions in the effect, and the modal window immediately disappears. Please tell me where the error is in the code? Why does my modal disappear after a redirect and how to fix it? Thank you very much
html
<modalSlideUp [isModalShow]="modalIsShown">
<form [formGroup]="form">
<input type="checkbox" formControlName="stayInTheSystem">
<h4> Don`t ask me again </h4>
<button> Yes </button>
<button> No </button>
</form>
</modalSlideUp>
typescript
_modalIsShown: boolean = false;
get modalIsShown(): boolean {
return this._modalIsShown;
}
set modalIsShown(value: boolean) {
console.log(value, 'value in setter'); // true
this._modalIsShown = true;
}
ngOnInit() {
this.effects.AuthenticationSuccess.subscribe((data) =>
let isModalShow: boolean =
(
this.tokenService.getUserSavedIsa(this.user?.id) === true ||
localStorage.getItem('userRecords') === null ||
localStorage.getItem('dontAskAgain') === 'false'
);
this.modalIsShown = isModalShow;
setTimeout(() => {
console.log(this.isTokenModalWindowOpened, 'timeout'); // true
}, 5000)
})
}
effects
AuthenticationSuccess: Observable<any> = createEffect(() => this.actions$.pipe(
ofType(idenityActions.ActionTypes.AUTHENICATION_SUCCESS),
tap((user:any) => {
const savedUrl = localStorage.getItem('intendedUrl');
if (!(user.payload as AuthenticateResponseModel).isAuthenticated) {
this.router.navigateByUrl("/non-activate", { skipLocationChange: false });
} else if (!savedUrl && user.payload.firstSetup === false) {
this.router.navigateByUrl("/");
} else if (savedUrl && user.payload.firstSetup === false) {
this.router.navigateByUrl(savedUrl);
setTimeout(() => {
localStorage.removeItem('savedUrl');
}, 3000)
} else if (savedUrl && user.payload.firstSetup === true) {
this.router.navigateByUrl('/my-profile/settings');
}
})
),{ dispatch: false });