get user's data to show in the tooltip

pull/10156/head
bsatarnejad 3 years ago
parent eb649e5f7c
commit 9ee95161f6
  1. 56
      frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts

@ -28,6 +28,7 @@
import { import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef,
Component, Component,
Injector, Injector,
OnInit, OnInit,
@ -38,6 +39,7 @@ import { OpModalService } from 'core-app/shared/components/modal/modal.service';
import { EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service'; import { EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service'; import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { distinctUntilChanged } from 'rxjs/operators'; import { distinctUntilChanged } from 'rxjs/operators';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
export const freeTrialButtonSelector = 'free-trial-button'; export const freeTrialButtonSelector = 'free-trial-button';
@ -53,35 +55,63 @@ export class FreeTrialButtonComponent implements OnInit {
public text = { public text = {
button_trial: this.I18n.t('js.admin.enterprise.upsale.button_start_trial'), button_trial: this.I18n.t('js.admin.enterprise.upsale.button_start_trial'),
confirmation_info: (date:string, email:string) => { return this.trialRequested ? this.I18n.t('js.admin.enterprise.trial.confirmation_info', { confirmation_info: (date:string, email:string) => {
date, return this.trialRequested ? this.I18n.t('js.admin.enterprise.trial.confirmation_info', {
email, date,
}) : ''}, email,
}) : ''
},
}; };
constructor(protected I18n:I18nService, constructor(protected I18n:I18nService,
protected opModalService:OpModalService, protected opModalService:OpModalService,
readonly injector:Injector, readonly injector:Injector,
readonly http:HttpClient,
readonly cdRef:ChangeDetectorRef,
public eeTrialService:EnterpriseTrialService, public eeTrialService:EnterpriseTrialService,
readonly timezoneService:TimezoneService) { readonly timezoneService:TimezoneService) {
} }
ngOnInit() { ngOnInit():void {
this.eeTrialService.userData$
.values$()
.pipe(
distinctUntilChanged(),
)
.subscribe((userForm) => {
this.email = userForm.email;
this.cdRef.detectChanges();
});
this.initialize();
}
private initialize():void {
const eeTrialKey = (window as any).gon.ee_trial_key; const eeTrialKey = (window as any).gon.ee_trial_key;
if (window.gon.ee_trial_key) { if (window.gon.ee_trial_key) {
const savedDateStr = eeTrialKey.created.split(' ')[0]; const savedDateStr = eeTrialKey.created.split(' ')[0];
this.created = this.timezoneService.formattedDate(savedDateStr); this.created = this.timezoneService.formattedDate(savedDateStr);
} }
this.eeTrialService.userData$ if (eeTrialKey && !this.eeTrialService.userData$.hasValue()) {
.values$() // after reload: get data from Augur using the trial key saved in gon
.pipe( this.eeTrialService.trialLink = `${this.eeTrialService.baseUrlAugur}/public/v1/trials/${eeTrialKey.value}`;
distinctUntilChanged(), this.getUserDataFromAugur();
) }
.subscribe((userForm) => {
this.email = userForm.email;
});
} }
private getUserDataFromAugur():void {
this.http
.get<any>(`${this.eeTrialService.trialLink}/details`)
.toPromise()
.then((userForm:any) => {
this.eeTrialService.userData$.putValue(userForm);
this.eeTrialService.retryConfirmation();
})
.catch((error:HttpErrorResponse) => {
// Check whether the mail has been confirmed by now
this.eeTrialService.getToken();
});
}
public openTrialModal():void { public openTrialModal():void {
// cancel request and open first modal window // cancel request and open first modal window
this.eeTrialService.cancelled = true; this.eeTrialService.cancelled = true;

Loading…
Cancel
Save