import { Component, Input, OnInit } from '@angular/core'; import { LocationService } from '@core/services/location.service'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { } from '@yourcause/common'; import { NotifierService } from '@yourcause/common/notifier'; import { I18nService } from '@yourcause/common/i18n'; import { LogService } from '@yourcause/common/logging'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-copy-link', templateUrl: './copy-link.component.html', styleUrls: ['./copy-link.component.scss'] }) export class CopyLinkComponent extends YCModalComponent implements OnInit { @Input() route: string; @Input() internalLinkDescription = this.i18n.translate( 'PROGRAM:textInternalProgramLinkDesc', {}, 'Provide this link to users who will be signing in via SSO, such as employees of your company.' ); @Input() externalLinkDescription = this.i18n.translate( 'PROGRAM:textExternalProgramLinkDescription', {}, 'Provide this link to users who will be applying externally, such as nonprofits.' ); internalLink: string; externalLink: string; constructor ( private locationService: LocationService, private notifierService: NotifierService, private logger: LogService, private i18n: I18nService, private clientSettingsService: ClientSettingsService ) { super(); } ngOnInit () { if (this.route) { this.internalLink = ''; this.externalLink = ''; if (!this.route.startsWith('/')) { this.route = `/${this.route}`; } const { internalPortalBase, externalPortalBase } = this.locationService.generateUrlBase( this.clientSettingsService.clientBranding.loginBehavior ); if (internalPortalBase) { this.internalLink = `${internalPortalBase}${this.route}`; } if (externalPortalBase) { this.externalLink = `${externalPortalBase}${this.route}`; } } } copyLink (link: string) { try { const textArea = document.createElement('textarea'); textArea.setAttribute('style', 'width:1px;border:0;opacity:0;'); document.body.appendChild(textArea); textArea.value = link; textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); this.notifierService.success(this.i18n.translate( 'common:textSuccessfullyCopiedToClipboard', {}, 'Successfully copied to clipboard.' )); } catch (err) { this.logger.error(err); this.notifierService.error(this.i18n.translate( 'common:textErrorCopiedToClipboard', {}, 'Error in copying to clipboard.' )); } } }