import { Component } from '@angular/core'; import { FeatureFlagsService } from '@core/services/feature-flags.service'; import { FeatureFlag } from '@core/typings/feature-flag.typing'; import { I18nService } from '@yourcause/common/i18n'; import { LogService } from '@yourcause/common/logging'; import { ModalFactory } from '@yourcause/common/modals'; import { NotifierService } from '@yourcause/common/notifier'; import { UpdateFeatureFlagStatusComponent } from '../update-feature-flag-status/update-feature-flag-status.component'; @Component({ selector: 'gc-feature-flags-page', templateUrl: './feature-flags-page.component.html', styleUrls: ['./feature-flags-page.component.scss'] }) export class FeatureFlagsPageComponent { featureFlags$ = this.featureFlagsService.changesTo$('featureFlags'); constructor ( private notifier: NotifierService, private i18n: I18nService, private featureFlagsService: FeatureFlagsService, private modalFactory: ModalFactory, private logger: LogService ) { } async updateAccess ( feature: FeatureFlag ) { const newStatus = await this.modalFactory.open(UpdateFeatureFlagStatusComponent, { featureName: feature.name, currentStatus: feature.status }); if (newStatus) { try { await this.featureFlagsService.updateFlag(feature.feature, newStatus); this.notifier.success( this.i18n.translate( 'common:textSuccessUpdateFlag', {}, 'Successfully updated the feature flag' ) ); } catch (e) { this.logger.error(e); this.notifier.error( this.i18n.translate( 'common:textErrorUpdatingFlag', {}, 'There was an error updating the feature flag' ) ); } } } }