import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { DueDiligenceModalComponent } from '@core/components/due-diligence-modal/due-diligence-modal.component'; import { VettingRequirementsModalComponent } from '@core/components/vetting-requirements-modal/vetting-requirements-modal.component'; import { PolicyService } from '@core/services/policy.service'; import { VettingRequestStatusId } from '@core/typings/application.typing'; import { NonprofitDetail, NonprofitProfileData, NonprofitProfileSummary } from '@core/typings/organization.typing'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { UserService } from '@features/users/user.service'; import { AddressFormatterService, Tab } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { ModalFactory } from '@yourcause/common/modals'; import { NonprofitService } from '../nonprofit.service'; @Component({ selector: 'gc-nonprofit-profile-wrapper', templateUrl: './nonprofit-profile-wrapper.component.html', styleUrls: ['./nonprofit-profile-wrapper.component.scss'] }) export class NonprofitProfileWrapperComponent implements OnInit { guid: string; tabs: Tab[]; canAccessCommunications = false; canSeeAppManager = false; nonprofit: NonprofitProfileData; VettingRequestStatusId = VettingRequestStatusId; nonprofitAddress: string; nonprofitDetail: NonprofitDetail; nonprofitMap = this.nonprofitService.get('nonprofitMap'); npoSummary: NonprofitProfileSummary; dueDiligenceText = this.i18n.translate( 'nonprofit:lblDueDiligence', {}, 'Due diligence' ); clientDefaultTz = this.clientSettingsService.clientSettings.defaultTimezone; constructor ( private activatedRoute: ActivatedRoute, private nonprofitService: NonprofitService, private policyService: PolicyService, private addressFormatter: AddressFormatterService, private userService: UserService, private modalFactory: ModalFactory, private i18n: I18nService, private clientSettingsService: ClientSettingsService ) { } ngOnInit () { this.guid = this.activatedRoute.snapshot.params.guid; this.nonprofit = this.nonprofitMap[this.guid]; this.nonprofitDetail = this.nonprofit ? this.nonprofit.nonprofitDetail : ({} as NonprofitDetail); this.npoSummary = this.nonprofit.summary; this.nonprofitAddress = this.addressFormatter.format( this.nonprofitDetail.remittanceInfo?.address || this.nonprofitDetail.address, true ); this.canSeeAppManager = this.policyService.grantApplication.canAccessApplicationManager(); const hasNominations = this.userService.user.clientHasNominations && this.userService.user.isInNominationWorkFlow; this.canAccessCommunications = this.policyService.system.canManageOrganizationCRM(); if (this.canSeeAppManager) { this.tabs = [{ link: './profile', labelKey: 'GLOBAL:textProfile', label: 'Profile', icon: 'book' }, { link: './applications', labelKey: 'common:hdrApplications', label: 'Applications', icon: 'clipboard' }, hasNominations ? { link: './nominations', labelKey: 'common:hdrNominations', label: 'Nominations', icon: 'medal' } : null, { link: './applicants', labelKey: 'common:lblApplicants', label: 'Applicants', icon: 'user' }, { link: './awards', labelKey: 'common:hdrAwards', label: 'Awards', icon: 'gift' }, this.canAccessCommunications ? { link: './communications', labelKey: 'GLOBAL:textCommunications', label: 'Communications', icon: 'comments' } : null].filter((tab) => !!tab); } } async openVettingInfoModal () { const modalClose = await this.modalFactory.open( VettingRequirementsModalComponent, {} ); if (modalClose) { await this.openDueDiligenceModal(); } } async openDueDiligenceModal () { const openVetting = await this.modalFactory.open( DueDiligenceModalComponent, { nonprofit: this.nonprofit } ); if (openVetting) { await this.openVettingInfoModal(); } } }