import { Component, OnInit } from '@angular/core'; import { PolicyService } from '@core/services/policy.service'; import { SpinnerService } from '@core/services/spinner.service'; import { ApplicantsPageRow, AppliedApplicant } from '@core/typings/applicant.typing'; import { APConfigService } from '@features/ap-config/ap-config.service'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { SystemTagsService } from '@features/system-tags/system-tags.service'; import { SystemTags } from '@features/system-tags/typings/system-tags.typing'; import { Address, DebounceFactory, PaginationOptions, TableDataFactory, TopLevelFilter } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { ModalFactory } from '@yourcause/common/modals'; import { from as observableFrom, map } from 'rxjs'; import { EditVendorIdModalComponent } from '../edit-vendor-id-modal/edit-vendor-id-modal.component'; import { ApplicationManagerResources } from '../resources/application-manager.resources'; @Component({ selector: 'gc-applicants-page', templateUrl: './applicants-page.component.html', styleUrls: ['./applicants-page.component.scss'] }) export class ApplicantsPageComponent implements OnInit { searchPlaceholder = this.i18n.translate( this.isNomination ? 'GLOBAL:textSearchByNominatorNameOrEmail' : 'GLOBAL:textSearchByApplicantNameOrEmail', {}, `Search by ${ this.isNomination ? 'nominator' : 'applicant' } name or email` ); topLevelFilters = [ new TopLevelFilter( 'text', 'fullName', '', this.searchPlaceholder, undefined, this.searchPlaceholder, [{ column: 'fullName', filterType: 'cn' }, { column: 'email', filterType: 'cn' }] ) ]; tagOptions = this.systemTagsService .getTagsForBucket(SystemTags.Buckets.Applicant, true) .map(tag => { return { label: tag.name, value: tag.id }; }); tableDataFactory: TableDataFactory; hasMaskedPermission = false; showVendorId = this.clientSettingsService.clientSettings.apEnabled && this.policyService.system.canManageClientSettings(); constructor ( private systemTagsService: SystemTagsService, private applicationManagerResources: ApplicationManagerResources, private i18n: I18nService, private policyService: PolicyService, private modalFactory: ModalFactory, private spinnerService: SpinnerService, private apConfigService: APConfigService, private clientSettingsService: ClientSettingsService ) { } get isNomination () { return location.pathname.includes('nomination'); } ngOnInit () { this.hasMaskedPermission = this.policyService.grantApplication .canSeeMaskedApplicants(); this.setTableDataFactory(); } setTableDataFactory () { this.tableDataFactory = DebounceFactory.createSimple( (options: PaginationOptions) => { options = this.systemTagsService.formatPaginationOptions(options); return observableFrom( this.applicationManagerResources.getApplicants(options, this.isNomination) ).pipe(map(result => ({ success: true, data: result }))); } ); } addressObj (row: ApplicantsPageRow): Address { return { address1: row.address, address2: row.address2, city: row.city, postalCode: row.postalCode, countryCode: row.country, stateProvRegCode: row.state }; } async editVendorIdModal (row: AppliedApplicant) { const response = await this.modalFactory.open( EditVendorIdModalComponent, { existingVendorId: row.vendorId } ); if (response) { this.spinnerService.startSpinner(); await this.apConfigService.updateVendorId( row.id, response.vendorId, true ); this.tableDataFactory.reset.emit(); this.spinnerService.stopSpinner(); } } }