|
| 1 | +import Component from '@glimmer/component'; |
| 2 | +import { tracked } from '@glimmer/tracking'; |
| 3 | +import { action } from '@ember/object'; |
| 4 | +import { service } from '@ember/service'; |
| 5 | +import { waitForPromise } from '@ember/test-waiters'; |
| 6 | +import { task } from 'ember-concurrency'; |
| 7 | +import type IntlService from 'ember-intl/services/intl'; |
| 8 | + |
| 9 | +import parseError from 'irene/utils/parse-error'; |
| 10 | +import type IreneAjaxService from 'irene/services/ajax'; |
| 11 | + |
| 12 | +export default class SbomUpsellingComponent extends Component { |
| 13 | + @service declare intl: IntlService; |
| 14 | + @service declare ajax: IreneAjaxService; |
| 15 | + @service('notifications') declare notify: NotificationService; |
| 16 | + @service('browser/window') declare window: Window; |
| 17 | + |
| 18 | + @tracked hasContactedSupport = false; |
| 19 | + |
| 20 | + CONTACT_SUPPORT_ENDPOINT = 'v2/feature_request/sbom'; |
| 21 | + |
| 22 | + constructor(owner: unknown, args: object) { |
| 23 | + super(owner, args); |
| 24 | + |
| 25 | + const storedState = this.window.localStorage.getItem('sbomRequest'); |
| 26 | + |
| 27 | + this.hasContactedSupport = storedState === 'true'; |
| 28 | + } |
| 29 | + |
| 30 | + get features() { |
| 31 | + return [ |
| 32 | + this.intl.t('sbomModule.sbomFeatures.oneClickAnalysis'), |
| 33 | + this.intl.t('sbomModule.sbomFeatures.identifyDependencies'), |
| 34 | + this.intl.t('sbomModule.sbomFeatures.uncoverVulnerabilities'), |
| 35 | + this.intl.t('sbomModule.sbomFeatures.componentInsights'), |
| 36 | + ]; |
| 37 | + } |
| 38 | + |
| 39 | + @action |
| 40 | + onClickContactCTA() { |
| 41 | + this.contactSupport.perform(); |
| 42 | + } |
| 43 | + |
| 44 | + contactSupport = task(async () => { |
| 45 | + try { |
| 46 | + await waitForPromise(this.ajax.post(this.CONTACT_SUPPORT_ENDPOINT)); |
| 47 | + |
| 48 | + this.window.localStorage.setItem('sbomRequest', 'true'); |
| 49 | + |
| 50 | + this.hasContactedSupport = true; |
| 51 | + } catch (err) { |
| 52 | + this.notify.error(parseError(err, this.intl.t('pleaseTryAgain'))); |
| 53 | + } |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +declare module '@glint/environment-ember-loose/registry' { |
| 58 | + export default interface Registry { |
| 59 | + 'Sbom::Upselling': typeof SbomUpsellingComponent; |
| 60 | + } |
| 61 | +} |
0 commit comments