import { Injectable } from '@angular/core'; import { BannerState } from '@core/states/banner.state'; import { ImpersonationBannerService } from '@features/impersonation/impersonation-banner.service'; import { BannerInfo, PasswordService } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { AttachYCState, BaseYCService } from '@yourcause/common/state'; import moment from 'moment'; @AttachYCState(BannerState) @Injectable({ providedIn: 'root' }) export class BannerService extends BaseYCService { constructor ( private i18n: I18nService, private impersonationBannerService: ImpersonationBannerService, private passwordService: PasswordService ) { super(); } get banners () { return this.get('banners'); } getIE11Banner (): BannerInfo { if (/Trident\/|MSIE/.test(navigator.userAgent)) { return { visible: true, message: this.i18n.translate( 'common:textIE11BannerText', { date: moment('6/30/2022').format('ll') }, 'Internet Explorer 11 will no longer be supported after __date__. Refer to our Help Center for a list of supported web browsers.' ), buttonText: this.i18n.translate( 'common:textLearnMore', {}, 'Learn more' ), onButtonClick: () => { location.href = 'https://grantsconnect.zendesk.com/hc/en-us/articles/4851009459085'; } }; } return null; } setManagerPortalBanners (passwordExpirationDate: string) { const banners: BannerInfo[] = []; const impersonationBanner = this.impersonationBannerService.getImpersonationBanner(); const passwordBanner = this.passwordService.getPasswordBannerInfo( passwordExpirationDate, '/management/my-account' ); const ie11Banner = this.getIE11Banner(); if (impersonationBanner) { banners.push(impersonationBanner); } if (passwordBanner) { banners.push(passwordBanner); } if (ie11Banner) { banners.push(ie11Banner); } this.setBanners(banners); } setApplicantPortalBanners (passwordExpirationDate: string) { const banners: BannerInfo[] = []; const passwordBanner = this.passwordService.getPasswordBannerInfo( passwordExpirationDate, '/apply/my-account' ); const ie11Banner = this.getIE11Banner(); if (passwordBanner) { banners.push(passwordBanner); } if (ie11Banner) { banners.push(ie11Banner); } this.setBanners(banners); } setLoginBanners () { const banners: BannerInfo[] = []; const ie11Banner = this.getIE11Banner(); if (ie11Banner) { banners.push(ie11Banner); } this.setBanners(banners); } setBanners (banners: BannerInfo[]) { this.set('banners', banners); } clearBannerInfo () { this.setBanners([]); } }