get user's data to show in the tooltip

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

@ -28,6 +28,7 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Injector,
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 { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { distinctUntilChanged } from 'rxjs/operators';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
export const freeTrialButtonSelector = 'free-trial-button';
@ -53,25 +55,24 @@ export class FreeTrialButtonComponent implements OnInit {
public text = {
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) => {
return this.trialRequested ? this.I18n.t('js.admin.enterprise.trial.confirmation_info', {
date,
email,
}) : ''},
}) : ''
},
};
constructor(protected I18n:I18nService,
protected opModalService:OpModalService,
readonly injector:Injector,
readonly http:HttpClient,
readonly cdRef:ChangeDetectorRef,
public eeTrialService:EnterpriseTrialService,
readonly timezoneService:TimezoneService) {
}
ngOnInit() {
const eeTrialKey = (window as any).gon.ee_trial_key;
if (window.gon.ee_trial_key) {
const savedDateStr = eeTrialKey.created.split(' ')[0];
this.created = this.timezoneService.formattedDate(savedDateStr);
}
ngOnInit():void {
this.eeTrialService.userData$
.values$()
.pipe(
@ -79,9 +80,38 @@ export class FreeTrialButtonComponent implements OnInit {
)
.subscribe((userForm) => {
this.email = userForm.email;
this.cdRef.detectChanges();
});
this.initialize();
}
private initialize():void {
const eeTrialKey = (window as any).gon.ee_trial_key;
if (window.gon.ee_trial_key) {
const savedDateStr = eeTrialKey.created.split(' ')[0];
this.created = this.timezoneService.formattedDate(savedDateStr);
}
if (eeTrialKey && !this.eeTrialService.userData$.hasValue()) {
// after reload: get data from Augur using the trial key saved in gon
this.eeTrialService.trialLink = `${this.eeTrialService.baseUrlAugur}/public/v1/trials/${eeTrialKey.value}`;
this.getUserDataFromAugur();
}
}
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 {
// cancel request and open first modal window
this.eeTrialService.cancelled = true;

Loading…
Cancel
Save