Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rework trial modal for onPush

Oliver Güntherd441c6f6dea8
diff --git a/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts b/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts
index 01e5a47abaf..886a871fb10 100644
--- a/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts
+++ b/frontend/src/app/features/enterprise/enterprise-active-trial/ee-active-trial.component.ts
@@ -42,6 +42,7 @@ import {
import { EEActiveTrialBase } from 'core-app/features/enterprise/enterprise-active-trial/ee-active-trial.base';
import { GonService } from 'core-app/core/gon/gon.service';
import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';
+import { IEnterpriseData } from 'core-app/features/enterprise/enterprise-trial.model';
@Component({
selector: 'enterprise-active-trial',
@@ -74,14 +75,13 @@ export class EEActiveTrialComponent extends EEActiveTrialBase implements OnInit
ngOnInit() {
if (!this.subscriber) {
- this.eeTrialService.userData$
- .values$()
+ void this.eeTrialService.userData$
.pipe(
distinctUntilChanged(),
this.untilDestroyed(),
)
- .subscribe((userForm) => {
- this.formatUserData(userForm);
+ .subscribe((data:IEnterpriseData) => {
+ this.formatUserData(data);
this.cdRef.detectChanges();
});
@@ -90,22 +90,24 @@ export class EEActiveTrialComponent extends EEActiveTrialBase implements OnInit
}
private initialize():void {
- const eeTrialKey = this.Gon.get('ee_trial_key') as any;
+ const eeTrialKey = this.Gon.get('ee_trial_key') as { value:string }|undefined;
+ const { data } = this.eeTrialService.current;
- if (eeTrialKey && !this.eeTrialService.userData$.hasValue()) {
+ if (eeTrialKey && !data) {
// 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();
+ const trialLink = `${this.eeTrialService.baseUrlAugur}/public/v1/trials/${eeTrialKey.value}`;
+ this.eeTrialService.store.update({ trialLink });
+ this.getUserDataFromAugur(trialLink);
}
}
// use the trial key saved in the db
// to get the user data from Augur
- private getUserDataFromAugur() {
+ private getUserDataFromAugur(trialLink:string) {
this
.http
- .get<any>(
- `${this.eeTrialService.trialLink}/details`,
+ .get(
+ `${trialLink}/details`,
{
headers: {
[EXTERNAL_REQUEST_HEADER]: 'true',
@@ -113,17 +115,17 @@ export class EEActiveTrialComponent extends EEActiveTrialBase implements OnInit
},
)
.toPromise()
- .then((userForm:any) => {
- this.eeTrialService.userData$.putValue(userForm);
+ .then((data:IEnterpriseData) => {
+ this.eeTrialService.store.update({ data });
this.eeTrialService.retryConfirmation();
})
- .catch((error:HttpErrorResponse) => {
+ .catch(() => {
// Check whether the mail has been confirmed by now
this.eeTrialService.getToken();
});
}
- private formatUserData(userForm:any) {
+ private formatUserData(userForm:IEnterpriseData) {
this.subscriber = `${userForm.first_name} ${userForm.last_name}`;
this.email = userForm.email;
this.company = userForm.company;
diff --git a/frontend/src/app/features/enterprise/enterprise-base.component.ts b/frontend/src/app/features/enterprise/enterprise-base.component.ts
index 58fac8e02c5..66c4e99c164 100644
--- a/frontend/src/app/features/enterprise/enterprise-base.component.ts
+++ b/frontend/src/app/features/enterprise/enterprise-base.component.ts
@@ -60,8 +60,7 @@ export class EnterpriseBaseComponent {
public openTrialModal() {
// cancel request and open first modal window
- this.eeTrialService.cancelled = true;
- this.eeTrialService.modalOpen = true;
+ this.eeTrialService.store.update({ cancelled: true, modalOpen: true });
this.opModalService.show(EnterpriseTrialModalComponent, this.injector);
}
diff --git a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
index bd7d62f2e2a..c93ba1976df 100644
--- a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
+++ b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
@@ -32,24 +32,32 @@
</div>
</div>
</div>
- <div class="form--field -wide-label -required">
+ <div
+ *ngIf="{ emailError: (eeTrialService.emailError$ | async) } as field"
+ class="form--field -wide-label -required">
<label class="form--label" for="trial-email">{{ text.label_email }}</label>
<div class="form--field-container">
<div class="form--text-field-container"
- [ngClass]="{ '-required-highlighting' : eeTrialService.emailError }">
+ [ngClass]="{ '-required-highlighting' : field.emailError }">
<input type="email"
class="form--text-field"
id="trial-email"
formControlName="email" (blur)="checkMailField()">
</div>
</div>
- <div *ngIf="eeTrialService.emailError" class="form--field-instructions op-ee-trial-email-error">{{ eeTrialService.errorMsg }}</div>
+ <div
+ *ngIf="field.emailError"
+ [textContent]="field.emailError"
+ class="form--field-instructions op-ee-trial-email-error"
+ ></div>
</div>
- <div class="form--field -wide-label -required">
+ <div
+ *ngIf="{ domainError: (eeTrialService.domainTaken$ | async) } as field"
+ class="form--field -wide-label -required">
<label class="form--label" for="trial-domain-name">{{ text.label_domain }}</label>
<div class="form--field-container">
<div class="form--text-field-container"
- [ngClass]="{ '-required-highlighting' : eeTrialService.domainTaken }">
+ [ngClass]="{ '-required-highlighting' : field.domainError }">
<input type="text"
id="trial-domain-name"
class="form--text-field"
@@ -59,7 +67,7 @@
</div>
<div class="form--field-instructions">
<p *ngIf="requestHost !== configuredHost" [textContent]="text.domain_mismatch"></p>
- <p *ngIf="eeTrialService.domainTaken" [textContent]="eeTrialService.errorMsg"></p>
+ <p *ngIf="field.domainError" [textContent]="field.domainError"></p>
</div>
</div>
<div class="form--field -required">
diff --git a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts
index cc2436079f1..3acea6b5ab8 100644
--- a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts
+++ b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.ts
@@ -26,13 +26,21 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { Component, ElementRef } from '@angular/core';
-import { FormBuilder, Validators } from '@angular/forms';
+import {
+ ChangeDetectionStrategy,
+ Component,
+ ElementRef,
+} from '@angular/core';
+import {
+ FormBuilder,
+ Validators,
+} from '@angular/forms';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { EnterpriseTrialData, EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service';
+import { EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { localizeLink } from 'core-app/shared/helpers/i18n/localized-link';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
+import { IEnterpriseData } from 'core-app/features/enterprise/enterprise-trial.model';
const newsletterURL = 'https://www.openproject.org/newsletter/';
@@ -40,13 +48,15 @@ const newsletterURL = 'https://www.openproject.org/newsletter/';
selector: 'enterprise-trial-form',
templateUrl: './ee-trial-form.component.html',
styleUrls: ['./ee-trial-form.component.sass'],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EETrialFormComponent {
// Retain used values
- userData:Partial<EnterpriseTrialData> = this.eeTrialService.userData$.getValueOr({});
+ userData:Partial<IEnterpriseData> = this.eeTrialService.current.data || {};
// The current request host
requestHost = window.location.host;
+
// The configured host name
configuredHost = this.configurationService.hostName;
@@ -84,23 +94,24 @@ export class EETrialFormComponent {
terms_of_service: this.I18n.t('js.admin.enterprise.trial.form.terms_of_service'),
};
- constructor(readonly elementRef:ElementRef,
+ constructor(
+ readonly elementRef:ElementRef,
readonly I18n:I18nService,
- private formBuilder:FormBuilder,
+ readonly formBuilder:FormBuilder,
readonly currentUserService:CurrentUserService,
readonly configurationService:ConfigurationService,
- public eeTrialService:EnterpriseTrialService) {
-
+ readonly eeTrialService:EnterpriseTrialService,
+ ) {
}
// checks if mail is valid after input field was edited by the user
// displays message for user
- public checkMailField() {
- if (this.trialForm.value.email !== '' && this.trialForm.controls.email.errors) {
- this.eeTrialService.emailInvalid = true;
+ public checkMailField():void {
+ const data = this.trialForm.value as IEnterpriseData;
+ if (data.email !== '' && this.trialForm.controls.email.errors) {
+ this.eeTrialService.store.update({ emailInvalid: true });
} else {
- this.eeTrialService.emailInvalid = false;
- this.eeTrialService.error = undefined;
+ this.eeTrialService.store.update({ emailInvalid: false, error: undefined });
}
}
}
diff --git a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.html b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.html
index 70dca218e15..bbda2c50a54 100644
--- a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.html
+++ b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.html
@@ -1,19 +1,19 @@
<div class="spot-modal op-enterprise-modal">
- <div class="spot-modal--header">{{headerText()}}</div>
+ <div class="spot-modal--header" [textContent]="headerText$ | async"></div>
<div class="spot-divider"></div>
- <div [ngSwitch]="openWindow()" class="spot-modal--body spot-container">
+ <div [ngSwitch]="showState$ | async" class="spot-modal--body spot-container">
<!-- first modal window -->
- <div *ngSwitchCase="1">
+ <div *ngSwitchCase="'trial-form'">
<enterprise-trial-form></enterprise-trial-form>
</div>
<!-- second modal window -->
- <div *ngSwitchCase="2">
+ <div *ngSwitchCase="'trial-waiting'">
<enterprise-trial-waiting></enterprise-trial-waiting>
</div>
<!-- third modal window -->
- <div *ngSwitchCase="3">
+ <div *ngSwitchCase="'overview'">
<div class="onboarding--video-block">
<div class="onboarding--video-text">
<span>{{ text.quick_overview }}</span>
@@ -30,9 +30,12 @@
</div>
</div>
- <div class="spot-action-bar">
+ <div
+ class="spot-action-bar"
+ *ngIf="{ status: eeTrialService.status$ | async, cancelled: eeTrialService.cancelled$ | async, confirmed: eeTrialService.confirmed$ | async } as context"
+ >
<div class="spot-action-bar--right">
- <div *ngIf="!eeTrialService.status || eeTrialService.cancelled; else mailSubmitted"
+ <div *ngIf="!context.status || context.cancelled; else mailSubmitted"
class="spot-action-bar--right">
<button
class="button button_no-margin spot-action-bar--action"
@@ -48,7 +51,7 @@
[disabled]="!trialForm || trialForm.invalid"
[textContent]="text.button_submit"
[attr.title]="text.button_submit"
- [hidden]="eeTrialService.mailSubmitted && !eeTrialService.cancelled"
+ [hidden]="context.status === 'mailSubmitted' && !context.cancelled"
></button>
</div>
<ng-template #mailSubmitted>
@@ -59,11 +62,11 @@
(click)="startEnterpriseTrial()"
[textContent]="text.button_continue"
[attr.title]="text.button_continue"
- [disabled]="!eeTrialService.confirmed"
- [hidden]="eeTrialService.trialStarted"
+ [disabled]="!context.confirmed"
+ [hidden]="context.status === 'startTrial'"
></button>
<button
- *ngIf="eeTrialService.trialStarted"
+ *ngIf="context.status === 'startTrial'"
class="button button_no-margin -highlight spot-action-bar--action"
data-qa-selector="confirmation-modal--confirmed"
(click)="closeModal($event)"
diff --git a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.ts b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.ts
index f0efb295819..201f487b2b7 100644
--- a/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.ts
+++ b/frontend/src/app/features/enterprise/enterprise-modal/enterprise-trial.modal.ts
@@ -27,16 +27,31 @@
//++
import {
- AfterViewInit, ChangeDetectorRef, Component, ElementRef, Inject, Input, ViewChild,
+ AfterViewInit,
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ ElementRef,
+ Inject,
+ Input,
+ ViewChild,
} from '@angular/core';
-import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
-import { FormControl, FormGroup } from '@angular/forms';
+import {
+ DomSanitizer,
+ SafeResourceUrl,
+} from '@angular/platform-browser';
+import {
+ FormControl,
+ FormGroup,
+} from '@angular/forms';
import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { EETrialFormComponent } from 'core-app/features/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component';
import { EnterpriseTrialService } from 'core-app/features/enterprise/enterprise-trial.service';
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
export const eeOnboardingVideoURL = 'https://www.youtube.com/embed/zLMSydhFSkw?autoplay=1';
@@ -44,6 +59,7 @@ export const eeOnboardingVideoURL = 'https://www.youtube.com/embed/zLMSydhFSkw?a
selector: 'enterprise-trial-modal',
templateUrl: './enterprise-trial.modal.html',
styleUrls: ['./enterprise-trial.modal.sass'],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
export class EnterpriseTrialModalComponent extends OpModalComponent implements AfterViewInit {
@ViewChild(EETrialFormComponent, { static: false }) formComponent:EETrialFormComponent;
@@ -52,9 +68,6 @@ export class EnterpriseTrialModalComponent extends OpModalComponent implements A
public trialForm:FormGroup;
- // modal configuration
- public showClose = true;
-
public trustedEEVideoURL:SafeResourceUrl;
public text = {
@@ -68,6 +81,39 @@ export class EnterpriseTrialModalComponent extends OpModalComponent implements A
quick_overview: this.I18n.t('js.admin.enterprise.trial.quick_overview'),
};
+ headerText$:Observable<string> = this
+ .eeTrialService
+ .observe$
+ .pipe(
+ map(({ status }) => {
+ if (status === 'mailSubmitted') {
+ return this.text.heading_confirmation;
+ }
+
+ if (status === 'startTrial') {
+ return this.text.heading_next_steps;
+ }
+
+ return this.text.heading_test_ee;
+ }),
+ );
+
+ showState$ = this
+ .eeTrialService
+ .observe$
+ .pipe(
+ map(({ status, cancelled }) => {
+ if (!status || cancelled) {
+ return 'trial-form';
+ }
+ if (status === 'mailSubmitted' && !cancelled) {
+ return 'trial-waiting';
+ }
+
+ return 'overview';
+ }),
+ );
+
constructor(readonly elementRef:ElementRef,
@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
readonly cdRef:ChangeDetectorRef,
@@ -78,55 +124,39 @@ export class EnterpriseTrialModalComponent extends OpModalComponent implements A
this.trustedEEVideoURL = this.trustedURL(eeOnboardingVideoURL);
}
- ngAfterViewInit() {
+ ngAfterViewInit():void {
this.trialForm = this.formComponent.trialForm;
}
// checks if form is valid and submits it
- public onSubmit() {
+ public onSubmit():void {
if (this.trialForm.valid) {
this.trialForm.addControl('_type', new FormControl('enterprise-trial'));
- this.eeTrialService.sendForm(this.trialForm);
+ void this.eeTrialService.sendForm(this.trialForm);
}
}
- public startEnterpriseTrial() {
+ public startEnterpriseTrial():void {
// open onboarding modal screen
this.eeTrialService.setStartTrialStatus();
}
- public headerText() {
- if (this.eeTrialService.mailSubmitted) {
- return this.text.heading_confirmation;
- } if (this.eeTrialService.trialStarted) {
- return this.text.heading_next_steps;
- }
- return this.text.heading_test_ee;
- }
-
- public closeModal(event:any) {
+ public closeModal(event:Event):void {
this.closeMe(event);
+
+ const { status, confirmed } = this.eeTrialService.current;
// refresh page to show enterprise trial
- if (this.eeTrialService.trialStarted || this.eeTrialService.confirmed) {
+ if (status === 'startTrial' || confirmed) {
window.location.reload();
- }
- else if (this.eeTrialService.mailSubmitted) {
+ } else if (status === 'mailSubmitted') {
window.location.reload();
return;
}
- this.eeTrialService.modalOpen = false;
- }
- public trustedURL(url:string) {
- return this.domSanitizer.bypassSecurityTrustResourceUrl(url);
+ this.eeTrialService.store.update({ modalOpen: false });
}
- public openWindow():number {
- if (!this.eeTrialService.status || this.eeTrialService.cancelled) {
- return 1;
- } if (this.eeTrialService.mailSubmitted && !this.eeTrialService.cancelled) {
- return 2;
- }
- return 3;
+ public trustedURL(url:string):SafeResourceUrl {
+ return this.domSanitizer.bypassSecurityTrustResourceUrl(url);
}
}
diff --git a/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html b/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
index 54efa8a0a96..c0f8b0c5d66 100644
--- a/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
+++ b/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
@@ -1,26 +1,31 @@
-<div class="op-ee-trial-waiting">
+<div
+ class="op-ee-trial-waiting"
+ *ngIf="{ confirmed: (eeTrialService.confirmed$ | async), cancelled: (eeTrialService.cancelled$ | async) } as context"
+>
<enterprise-active-trial></enterprise-active-trial>
<p>{{ text.confirmation_info(created, email) }}</p>
<p>
<span>{{ text.status_label }} </span>
- <span *ngIf="!eeTrialService.confirmed; else confirmedStatus" class="op-ee-trial-waiting-status--waiting"
- data-qa-selector="op-ee-trial-waiting-status--waiting">
+ <span *ngIf="!context.confirmed; else confirmedStatus" class="op-ee-trial-waiting-status--waiting"
+ data-qa-selector="op-ee-trial-waiting-status--waiting">
{{ text.status_waiting }}
<!-- <a id="op-ee-trial-waiting-resend-link"
data-qa-selector='op-ee-trial-waiting-resend-link' (click)="resendMail()">{{ text.resend }}</a> -->
<button
- class="spot-link op-ee-trial-waiting-resend-link"
- data-qa-selector='op-ee-trial-waiting-resend-link'
- (click)="resendMail()">
+ class="spot-link op-ee-trial-waiting-resend-link"
+ data-qa-selector='op-ee-trial-waiting-resend-link'
+ (click)="resendMail()">
{{ text.resend }}</button>
- <p *ngIf="eeTrialService.cancelled">{{ text.session_timeout }}</p>
</span>
+ <span *ngIf="context.cancelled">{{ text.session_timeout }}</span>
<ng-template #confirmedStatus>
- <span class="op-ee-trial-waiting-status--confirmed icon-yes"
- data-qa-selector="op-ee-trial-waiting-status--confirmed"> {{ text.status_confirmed }}</span>
+ <span
+ class="op-ee-trial-waiting-status--confirmed icon-yes"
+ data-qa-selector="op-ee-trial-waiting-status--confirmed"> {{ text.status_confirmed }}
+ </span>
</ng-template>
</p>
</div>
diff --git a/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts b/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
index eaf493b84e5..0b30f187cf5 100644
--- a/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
+++ b/frontend/src/app/features/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
@@ -38,6 +38,7 @@ import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { distinctUntilChanged } from 'rxjs/operators';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';
+import { IEnterpriseData } from 'core-app/features/enterprise/enterprise-trial.model';
@Component({
selector: 'enterprise-trial-waiting',
@@ -71,28 +72,34 @@ export class EETrialWaitingComponent implements OnInit {
readonly timezoneService:TimezoneService) {
}
- ngOnInit() {
- const eeTrialKey = (window as any).gon.ee_trial_key;
+ ngOnInit():void {
+ const eeTrialKey = window.gon.ee_trial_key as { created:string }|undefined;
if (eeTrialKey) {
const savedDateStr = eeTrialKey.created.split(' ')[0];
this.created = this.timezoneService.formattedDate(savedDateStr);
}
- this.eeTrialService.userData$
- .values$()
+ this.eeTrialService
+ .userData$
.pipe(
distinctUntilChanged(),
)
- .subscribe((userForm) => {
- this.email = userForm.email;
+ .subscribe((data:IEnterpriseData) => {
+ this.email = data.email;
});
}
// resend mail if resend link has been clicked
- public resendMail() {
- this.eeTrialService.cancelled = false;
+ public resendMail():void {
+ const { resendLink } = this.eeTrialService.store.getValue();
+
+ if (!resendLink) {
+ return;
+ }
+
+ this.eeTrialService.store.update({ cancelled: false });
this.http.post(
- this.eeTrialService.resendLink,
+ resendLink,
{},
{
headers: {
@@ -106,7 +113,8 @@ export class EETrialWaitingComponent implements OnInit {
this.eeTrialService.retryConfirmation();
})
.catch(() => {
- if (this.eeTrialService.trialLink) {
+ const { trialLink } = this.eeTrialService.store.getValue();
+ if (trialLink) {
// Check whether the mail has been confirmed by now
this.eeTrialService.getToken();
} else {
diff --git a/frontend/src/app/features/enterprise/enterprise-trial.model.ts b/frontend/src/app/features/enterprise/enterprise-trial.model.ts
new file mode 100644
index 00000000000..9a189cabdab
--- /dev/null
+++ b/frontend/src/app/features/enterprise/enterprise-trial.model.ts
@@ -0,0 +1,43 @@
+import { HttpErrorResponse } from '@angular/common/http';
+import {
+ IHalOptionalTitledLink,
+ IHalResourceLinks,
+} from 'core-app/core/state/hal-resource';
+
+export interface IEnterpriseData {
+ id?:string;
+ company:string;
+ first_name:string;
+ last_name:string;
+ email:string;
+ domain:string;
+ general_consent?:boolean;
+ newsletter_consent?:boolean;
+}
+
+export interface IEnterpriseTrial {
+ trialLink?:string;
+ resendLink?:string;
+ modalOpen:boolean;
+ confirmed:boolean;
+ cancelled:boolean;
+ status?:'mailSubmitted'|'startTrial';
+ error?:HttpErrorResponse;
+ emailInvalid:boolean;
+
+ data?:IEnterpriseData;
+}
+
+export interface EnterpriseTrialHalResource {
+ _links:IHalResourceLinks;
+}
+
+export interface EnterpriseTrialErrorHalResource {
+ identifier:string;
+ message?:string;
+ description?:string;
+ _links:{
+ self:IHalOptionalTitledLink;
+ resend:IHalOptionalTitledLink;
+ };
+}
diff --git a/frontend/src/app/features/enterprise/enterprise-trial.service.ts b/frontend/src/app/features/enterprise/enterprise-trial.service.ts
index b75f5dd9d7e..b5b34fde038 100644
--- a/frontend/src/app/features/enterprise/enterprise-trial.service.ts
+++ b/frontend/src/app/features/enterprise/enterprise-trial.service.ts
@@ -7,44 +7,77 @@ import {
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { FormGroup } from '@angular/forms';
-import { input } from 'reactivestates';
import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';
-
-export interface EnterpriseTrialData {
- id?:string;
- company:string;
- first_name:string;
- last_name:string;
- email:string;
- domain:string;
- general_consent?:boolean;
- newsletter_consent?:boolean;
-}
+import { EnterpriseTrialStore } from 'core-app/features/enterprise/enterprise-trial.store';
+import { GonType } from 'core-app/core/gon/gon.service';
+import {
+ EnterpriseTrialErrorHalResource,
+ EnterpriseTrialHalResource,
+ IEnterpriseData,
+ IEnterpriseTrial,
+} from 'core-app/features/enterprise/enterprise-trial.model';
+import { Query } from '@datorama/akita';
+import {
+ filter,
+ map,
+ shareReplay,
+} from 'rxjs/operators';
@Injectable()
export class EnterpriseTrialService {
- // user data needs to be sync in ee-active-trial.component.ts
- userData$ = input<EnterpriseTrialData>();
+ readonly store = new EnterpriseTrialStore();
- public readonly baseUrlAugur:string;
+ private query = new Query(this.store);
- public readonly tokenVersion:string;
+ confirmed$ = this.query.select('confirmed');
- public trialLink:string;
+ cancelled$ = this.query.select('cancelled');
- public resendLink:string;
+ status$ = this.query.select('status');
- public modalOpen = false;
+ observe$ = this.query.select();
- public confirmed:boolean;
+ userData$ = this.query
+ .select('data')
+ .pipe(
+ filter((data) => data !== undefined),
+ );
- public cancelled = false;
+ emailError$ = this
+ .query
+ .select()
+ .pipe(
+ map(({ error, emailInvalid }) => {
+ if (emailInvalid) {
+ return this.text.invalid_email;
+ }
- public status:'mailSubmitted'|'startTrial'|undefined;
+ const errorResponse = error?.error as { identifier?:string };
+ if (error && errorResponse.identifier === 'user_already_created_trial') {
+ return this.text.taken_email;
+ }
+ return null;
+ }),
+ shareReplay(1),
+ );
+
+ domainTaken$ = this
+ .query
+ .select()
+ .pipe(
+ map(({ error }) => {
+ const errorResponse = error?.error as { identifier?:string };
+ if (error && errorResponse.identifier === 'domain_taken') {
+ return this.text.taken_domain;
+ }
+ return null;
+ }),
+ shareReplay(1),
+ );
- public error:HttpErrorResponse|undefined;
+ public readonly baseUrlAugur:string;
- public emailInvalid = false;
+ public readonly tokenVersion:string;
public text = {
invalid_email: this.I18n.t('js.admin.enterprise.trial.form.invalid_email'),
@@ -56,20 +89,20 @@ export class EnterpriseTrialService {
protected http:HttpClient,
readonly pathHelper:PathHelperService,
protected toastService:ToastService) {
- const { gon } = window as any;
+ const gon = window.gon as (GonType&{ augur_url:string, token_version:string, ee_trial_key?:string });
this.baseUrlAugur = gon.augur_url;
this.tokenVersion = gon.token_version;
- if ((window as any).gon.ee_trial_key) {
+ if (gon.ee_trial_key) {
this.setMailSubmittedStatus();
}
}
// send POST request with form object
// receive an enterprise trial link to access a token
- public sendForm(form:FormGroup) {
- const request = { ...form.value, token_version: this.tokenVersion };
- this.http
+ public sendForm(form:FormGroup):Promise<unknown> {
+ const request:unknown = { ...form.value, token_version: this.tokenVersion };
+ return this.http
.post(
`${this.baseUrlAugur}/public/v1/trials`,
request,
@@ -80,30 +113,35 @@ export class EnterpriseTrialService {
},
)
.toPromise()
- .then((enterpriseTrial:any) => {
- this.userData$.putValue(form.value);
- this.cancelled = false;
+ .then((enterpriseTrial:EnterpriseTrialHalResource) => {
+ const trialLink = enterpriseTrial._links.self.href;
+ const data = form.value as IEnterpriseData;
- this.trialLink = enterpriseTrial._links.self.href;
- this.saveTrialKey(this.trialLink);
+ this.store.update({
+ trialLink,
+ data,
+ cancelled: false,
+ });
+ void this.saveTrialKey(trialLink);
this.retryConfirmation();
})
.catch((error:HttpErrorResponse) => {
// mail is invalid or user already created a trial
if (error.status === 422 || error.status === 400) {
- this.error = error;
+ this.store.update({ error });
} else {
- this.toastService.addWarning(error.error.description || I18n.t('js.error.internal'));
+ const description = (error.error as { description?:string }).description;
+ this.toastService.addWarning(description || I18n.t('js.error.internal'));
}
});
}
// get a token from the trial link if user confirmed mail
- public getToken() {
+ public getToken():void {
// 2) GET /public/v1/trials/:id
- this.http.get<any>(
- this.trialLink,
+ this.http.get(
+ this.store.getValue().trialLink as string,
{
headers: {
[EXTERNAL_REQUEST_HEADER]: 'true',
@@ -111,9 +149,9 @@ export class EnterpriseTrialService {
},
)
.toPromise()
- .then(async (res:any) => {
+ .then(async (res:{ token_retrieved?:boolean, token:string }) => {
// show confirmed status and enable continue btn
- this.confirmed = true;
+ this.store.update({ confirmed: true });
// returns token if mail was confirmed
// -> if token is new (token_retrieved: false) save token in backend
@@ -122,19 +160,24 @@ export class EnterpriseTrialService {
}
})
.catch((error:HttpErrorResponse) => {
+ const errorResponse = error.error as EnterpriseTrialErrorHalResource;
// returns error 422 while waiting of confirmation
- if (error.status === 422 && error.error.identifier === 'waiting_for_email_verification') {
+ if (error.status === 422 && errorResponse.identifier === 'waiting_for_email_verification') {
// get resend button link
- this.resendLink = error.error._links.resend.href;
+ const resendLink = errorResponse._links.resend.href;
+ this.store.update({ resendLink });
+
+ const { status, cancelled } = this.store.getValue();
+
// save a key for the requested trial
- if (!this.status || this.cancelled) { // only do it once
- this.saveTrialKey(this.resendLink);
+ if (!status || cancelled) { // only do it once
+ void this.saveTrialKey(resendLink);
}
// open next modal window -> status waiting
this.setMailSubmittedStatus();
- this.confirmed = false;
- } else if (_.get(error, 'error._type') === 'Error') {
- this.toastService.addError(error.error.message);
+ this.store.update({ confirmed: false });
+ } else if (errorResponse?.message) {
+ this.toastService.addError(errorResponse.message);
} else {
this.toastService.addError(error.error || I18n.t('js.error.internal'));
}
@@ -144,7 +187,7 @@ export class EnterpriseTrialService {
// save a part of the resend link in db
// which allows to remember if a user has already requested a trial token
// and to ask for the corresponding user data saved in Augur
- private saveTrialKey(resendlink:string) {
+ private saveTrialKey(resendlink:string):Promise<unknown> {
// extract token from resend link
const trialKey = resendlink.split('/')[6];
return this.http.post(
@@ -153,8 +196,9 @@ export class EnterpriseTrialService {
{ withCredentials: true },
)
.toPromise()
- .catch((e:any) => {
- this.toastService.addError(e.error.message || e.message || e);
+ .catch((e:HttpErrorResponse) => {
+ const errorResponse = e.error as EnterpriseTrialErrorHalResource;
+ this.toastService.addError(errorResponse.message || e.message || e);
});
}
@@ -167,8 +211,9 @@ export class EnterpriseTrialService {
)
.toPromise()
.then(() => {
+ const { modalOpen } = this.store.getValue();
// load page if mail was confirmed and modal window is not open
- if (!this.modalOpen) {
+ if (!modalOpen) {
setTimeout(() => { // display confirmed status before reloading
window.location.reload();
}, 500);
@@ -177,23 +222,29 @@ export class EnterpriseTrialService {
.catch((error:HttpErrorResponse) => {
// Delete the trial key as the token could not be saved and thus something is wrong with the token.
// Without this deletion, we run into an endless loop of an confirmed mail, but no saved token.
- this.http
+ void this.http
.delete(
`${this.pathHelper.api.v3.apiV3Base}/admin/enterprise/delete_trial_key`,
{ withCredentials: true },
)
.toPromise();
- this.toastService.addError(error.error.description || I18n.t('js.error.internal'));
+ const errorResponse = error.error as EnterpriseTrialErrorHalResource;
+ this.toastService.addError(errorResponse.description || I18n.t('js.error.internal'));
});
}
// retry request while waiting for mail confirmation
- public retryConfirmation(delay = 5000, retries = 60) {
- if (this.cancelled || this.confirmed) {
+ public retryConfirmation(delay = 5000, retries = 60):void {
+ const { cancelled, confirmed } = this.store.getValue();
+
+ if (cancelled || confirmed) {
+ // no need to retry
+ return;
+ }
- } else if (retries === 0) {
- this.cancelled = true;
+ if (retries === 0) {
+ this.store.update({ cancelled: true });
} else {
this.getToken();
setTimeout(() => {
@@ -202,50 +253,15 @@ export class EnterpriseTrialService {
}
}
- public setStartTrialStatus() {
- this.status = 'startTrial';
+ public setStartTrialStatus():void {
+ this.store.update({ status: 'startTrial' });
}
- public setMailSubmittedStatus() {
- this.status = 'mailSubmitted';
+ public setMailSubmittedStatus():void {
+ this.store.update({ status: 'mailSubmitted' });
}
- public get trialStarted():boolean {
- return this.status === 'startTrial';
- }
-
- public get mailSubmitted():boolean {
- return this.status === 'mailSubmitted';
- }
-
- public get domainTaken():boolean {
- return this.error ? this.error.error.identifier === 'domain_taken' : false;
- }
-
- public get emailTaken():boolean {
- return this.error ? this.error.error.identifier === 'user_already_created_trial' : false;
- }
-
- public get emailError():boolean {
- if (this.emailInvalid) {
- return true;
- }
- if (this.error) {
- return this.emailTaken;
- }
- return false;
- }
-
- public get errorMsg() {
- let error = '';
- if (this.emailInvalid) {
- error = this.text.invalid_email;
- } else if (this.domainTaken) {
- error = this.text.taken_domain;
- } else if (this.emailTaken) {
- error = this.text.taken_email;
- }
-
- return error;
+ public get current():IEnterpriseTrial {
+ return this.store.getValue();
}
}
diff --git a/frontend/src/app/features/enterprise/enterprise-trial.store.ts b/frontend/src/app/features/enterprise/enterprise-trial.store.ts
new file mode 100644
index 00000000000..755f441b690
--- /dev/null
+++ b/frontend/src/app/features/enterprise/enterprise-trial.store.ts
@@ -0,0 +1,21 @@
+import {
+ Store,
+ StoreConfig,
+} from '@datorama/akita';
+import { IEnterpriseTrial } from 'core-app/features/enterprise/enterprise-trial.model';
+
+export function createInitialState():IEnterpriseTrial {
+ return {
+ modalOpen: false,
+ confirmed: false,
+ cancelled: false,
+ emailInvalid: false,
+ };
+}
+
+@StoreConfig({ name: 'enterprise-trial' })
+export class EnterpriseTrialStore extends Store<IEnterpriseTrial> {
+ constructor() {
+ super(createInitialState());
+ }
+}
diff --git a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html
index 768710b4d60..49a011e3405 100644
--- a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html
+++ b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.html
@@ -1,4 +1,6 @@
-<div [attr.data-tooltip]="trialRequested ? text.confirmation_info(created, email) : ''" [ngClass]="{'tooltip--top': trialRequested}">
+<div
+ [attr.data-tooltip]="trialRequested ? text.confirmation_info(created, email) : ''"
+ [ngClass]="{'tooltip--top': trialRequested}">
<button
type="button"
[disabled]="trialRequested"
diff --git a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts
index ed11bf5e527..57ccb3a331a 100644
--- a/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts
+++ b/frontend/src/app/features/enterprise/free-trial-button/free-trial-button.component.ts
@@ -41,6 +41,7 @@ import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { distinctUntilChanged } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { GonService } from 'core-app/core/gon/gon.service';
+import { IEnterpriseData } from 'core-app/features/enterprise/enterprise-trial.model';
export const freeTrialButtonSelector = 'free-trial-button';
@@ -48,15 +49,6 @@ export interface EETrialKey {
created:string;
value:string;
}
-
-export interface TrialDetails {
- first_name:string;
- last_name:string;
- email:string;
- company:string;
- domain:string;
-}
-
@Component({
selector: freeTrialButtonSelector,
templateUrl: './free-trial-button.component.html',
@@ -86,12 +78,12 @@ export class FreeTrialButtonComponent implements OnInit {
}
ngOnInit():void {
- this.eeTrialService.userData$
- .values$()
+ this.eeTrialService
+ .userData$
.pipe(
distinctUntilChanged(),
)
- .subscribe((userForm) => {
+ .subscribe((userForm:IEnterpriseData) => {
this.email = userForm.email;
this.cdRef.detectChanges();
});
@@ -105,20 +97,22 @@ export class FreeTrialButtonComponent implements OnInit {
const savedDateStr = eeTrialKey.created.split(' ')[0];
this.created = this.timezoneService.formattedDate(savedDateStr);
- if (!this.eeTrialService.userData$.hasValue()) {
+ const { data } = this.eeTrialService.store.getValue();
+ if (data) {
// 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();
+ const trialLink = `${this.eeTrialService.baseUrlAugur}/public/v1/trials/${eeTrialKey.value}`;
+ this.eeTrialService.store.update({ trialLink });
+ this.getUserDataFromAugur(trialLink);
}
}
}
- private getUserDataFromAugur():void {
+ private getUserDataFromAugur(trialLink:string):void {
this.http
- .get<TrialDetails>(`${this.eeTrialService.trialLink}/details`)
+ .get<IEnterpriseData>(`${trialLink}/details`)
.toPromise()
- .then((userForm:TrialDetails) => {
- this.eeTrialService.userData$.putValue(userForm);
+ .then((data:IEnterpriseData) => {
+ this.eeTrialService.store.update({ data });
this.eeTrialService.retryConfirmation();
})
.catch(() => {
@@ -129,13 +123,12 @@ export class FreeTrialButtonComponent implements OnInit {
public openTrialModal():void {
// cancel request and open first modal window
- this.eeTrialService.cancelled = true;
- this.eeTrialService.modalOpen = true;
+ this.eeTrialService.store.update({ cancelled: true, modalOpen: true });
this.opModalService.show(EnterpriseTrialModalComponent, this.injector);
}
public get trialRequested():boolean {
- const eeTrialKey = this.Gon.get('ee_trial_key') as EETrialKey;
- return (eeTrialKey && eeTrialKey !== undefined);
+ const eeTrialKey = this.Gon.get('ee_trial_key') as EETrialKey|undefined;
+ return !!eeTrialKey;
}
}