1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-03-23 15:29:29 +01:00

[SG-576] Added reference data to trial initiation (#3312)

* Added reference data to trial initiation

* refactored to use private methods

* refactored to use private methods
This commit is contained in:
Gbubemi Smith 2022-08-19 17:10:23 +01:00 committed by GitHub
parent 4c099aca46
commit d8cb543645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 2 deletions

View File

@ -1,11 +1,12 @@
<div *ngIf="accountCreateOnly" class="">
<h1 class="tw-mt-12 tw-text-center tw-text-xl" *ngIf="!layout">{{ "createAccount" | i18n }}</h1>
<h1 class="tw-mt-12 tw-text-center tw-text-xl">{{ "createAccount" | i18n }}</h1>
<div
class="tw-min-w-xl tw-m-auto tw-max-w-xl tw-rounded tw-border tw-border-solid tw-border-secondary-300 tw-bg-background tw-p-8"
>
<app-register-form
[queryParamEmail]="email"
[enforcedPolicyOptions]="enforcedPolicyOptions"
[referenceDataValue]="referenceData"
></app-register-form>
</div>
</div>
@ -53,6 +54,7 @@
<app-register-form
[isInTrialFlow]="true"
(createdAccount)="createdAccount($event)"
[referenceDataValue]="referenceData"
></app-register-form>
</app-vertical-step>
<app-vertical-step label="Organization Information" [subLabel]="orgInfoSubLabel">

View File

@ -15,7 +15,9 @@ import { ProductType } from "@bitwarden/common/enums/productType";
import { PolicyData } from "@bitwarden/common/models/data/policyData";
import { MasterPasswordPolicyOptions } from "@bitwarden/common/models/domain/masterPasswordPolicyOptions";
import { Policy } from "@bitwarden/common/models/domain/policy";
import { ReferenceEventRequest } from "@bitwarden/common/models/request/referenceEventRequest";
import { RouterService } from "./../../core/router.service";
import { VerticalStepperComponent } from "./vertical-stepper/vertical-stepper.component";
@Component({
@ -36,6 +38,7 @@ export class TrialInitiationComponent implements OnInit {
policies: Policy[];
enforcedPolicyOptions: MasterPasswordPolicyOptions;
validOrgs: string[] = ["teams", "enterprise", "families"];
referenceData: ReferenceEventRequest;
@ViewChild("stepper", { static: false }) verticalStepper: VerticalStepperComponent;
orgInfoFormGroup = this.formBuilder.group({
@ -43,6 +46,22 @@ export class TrialInitiationComponent implements OnInit {
email: [""],
});
private set referenceDataId(referenceId: string) {
if (referenceId != null) {
this.referenceData.id = referenceId;
} else {
this.referenceData.id = ("; " + document.cookie)
.split("; reference=")
.pop()
.split(";")
.shift();
}
if (this.referenceData.id === "") {
this.referenceData.id = null;
}
}
constructor(
private route: ActivatedRoute,
protected router: Router,
@ -52,15 +71,19 @@ export class TrialInitiationComponent implements OnInit {
private logService: LogService,
private policyApiService: PolicyApiServiceAbstraction,
private policyService: PolicyService,
private i18nService: I18nService
private i18nService: I18nService,
private routerService: RouterService
) {}
async ngOnInit(): Promise<void> {
this.route.queryParams.pipe(first()).subscribe((qParams) => {
this.referenceData = new ReferenceEventRequest();
if (qParams.email != null && qParams.email.indexOf("@") > -1) {
this.email = qParams.email;
}
this.referenceDataId = qParams.reference;
if (!qParams.org) {
return;
}
@ -75,6 +98,12 @@ export class TrialInitiationComponent implements OnInit {
this.org = "families";
}
this.referenceData.flow = qParams.org;
// Are they coming from an email for sponsoring a families organization
// After logging in redirect them to setup the families sponsorship
this.setupFamilySponsorship(qParams.sponsorshipToken);
this.orgLabel = this.titleCasePipe.transform(this.org);
this.accountCreateOnly = false;
@ -153,4 +182,13 @@ export class TrialInitiationComponent implements OnInit {
previousStep() {
this.verticalStepper.previous();
}
private setupFamilySponsorship(sponsorshipToken: string) {
if (sponsorshipToken != null) {
const route = this.router.createUrlTree(["setup/families-for-enterprise"], {
queryParams: { plan: sponsorshipToken },
});
this.routerService.setPreviousUrl(route.toString());
}
}
}