1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00

[PM-5014] Download license component migration (#8443)

* Download license component migration

* download license dialog component migration

* download license dialog component migration
This commit is contained in:
vinith-kovan 2024-06-05 13:45:08 +05:30 committed by GitHub
parent 3154d21925
commit 7e86c0afd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 86 additions and 81 deletions

View File

@ -1,39 +1,35 @@
<form #form class="card" (ngSubmit)="submit()" [appApiAction]="formPromise" ngNativeValidate> <form [formGroup]="licenseForm" [bitSubmit]="submit">
<div class="card-body"> <bit-dialog>
<button type="button" class="close" appA11yTitle="{{ 'cancel' | i18n }}" (click)="cancel()"> <span bitDialogTitle>{{ "downloadLicense" | i18n }}</span>
<span aria-hidden="true">&times;</span> <ng-container bitDialogContent>
</button> <div class="tw-grid tw-grid-cols-12 tw-gap-4">
<h3 class="card-body-header">{{ "downloadLicense" | i18n }}</h3> <div class="tw-col-span-8">
<div class="row"> <bit-form-field>
<div class="form-group col-6"> <bit-label
<div class="d-flex"> >{{ "enterInstallationId" | i18n }}
<label for="installationId">{{ "enterInstallationId" | i18n }}</label> <a
<a bitLink
class="ml-auto" class="tw-ml-auto"
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
appA11yTitle="{{ 'learnMore' | i18n }}" appA11yTitle="{{ 'learnMore' | i18n }}"
href="https://bitwarden.com/help/licensing-on-premise/#organization-account-sharing" href="https://bitwarden.com/help/licensing-on-premise/#organization-account-sharing"
> >
<i class="bwi bwi-question-circle" aria-hidden="true"></i> <i class="bwi bwi-question-circle" aria-hidden="true"></i>
</a> </a>
</bit-label>
<input type="text" bitInput formControlName="installationId" />
</bit-form-field>
</div> </div>
<input
id="installationId"
class="form-control"
type="text"
name="InstallationId"
[(ngModel)]="installationId"
required
/>
</div> </div>
</div> </ng-container>
<button type="submit" class="btn btn-primary btn-submit" [disabled]="form.loading"> <ng-container bitDialogFooter>
<i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i> <button bitButton bitFormButton buttonType="primary" type="submit">
<span>{{ "submit" | i18n }}</span> {{ "submit" | i18n }}
</button> </button>
<button type="button" class="btn btn-outline-secondary" (click)="cancel()"> <button bitButton [bitAction]="cancel" bitFormButton buttonType="secondary" type="button">
{{ "cancel" | i18n }} {{ "cancel" | i18n }}
</button> </button>
</div> </ng-container>
</bit-dialog>
</form> </form>

View File

@ -1,50 +1,61 @@
import { Component, EventEmitter, Input, Output } from "@angular/core"; import { DialogConfig, DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";
import { Component, Inject } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { DialogService } from "@bitwarden/components";
export enum DownloadLicenseDialogResult {
Cancelled = "cancelled",
Downloaded = "downloaded",
}
type DownloadLicenseDialogData = {
/** current organization id */
organizationId: string;
};
@Component({ @Component({
selector: "app-download-license",
templateUrl: "download-license.component.html", templateUrl: "download-license.component.html",
}) })
export class DownloadLicenseComponent { export class DownloadLicenceDialogComponent {
@Input() organizationId: string; licenseForm = this.formBuilder.group({
@Output() onDownloaded = new EventEmitter(); installationId: ["", [Validators.required]],
@Output() onCanceled = new EventEmitter(); });
installationId: string;
formPromise: Promise<unknown>;
constructor( constructor(
@Inject(DIALOG_DATA) protected data: DownloadLicenseDialogData,
private dialogRef: DialogRef,
private fileDownloadService: FileDownloadService, private fileDownloadService: FileDownloadService,
private logService: LogService,
private organizationApiService: OrganizationApiServiceAbstraction, private organizationApiService: OrganizationApiServiceAbstraction,
protected formBuilder: FormBuilder,
) {} ) {}
async submit() { submit = async () => {
if (this.installationId == null || this.installationId === "") { this.licenseForm.markAllAsTouched();
const installationId = this.licenseForm.get("installationId").value;
if (installationId == null || installationId === "") {
return; return;
} }
const license = await this.organizationApiService.getLicense(
try { this.data.organizationId,
this.formPromise = this.organizationApiService.getLicense( installationId,
this.organizationId, );
this.installationId, const licenseString = JSON.stringify(license, null, 2);
); this.fileDownloadService.download({
const license = await this.formPromise; fileName: "bitwarden_organization_license.json",
const licenseString = JSON.stringify(license, null, 2); blobData: licenseString,
this.fileDownloadService.download({ });
fileName: "bitwarden_organization_license.json", this.dialogRef.close(DownloadLicenseDialogResult.Downloaded);
blobData: licenseString, };
}); /**
this.onDownloaded.emit(); * Strongly typed helper to open a DownloadLicenceDialogComponent
} catch (e) { * @param dialogService Instance of the dialog service that will be used to open the dialog
this.logService.error(e); * @param config Configuration for the dialog
} */
} static open(dialogService: DialogService, config: DialogConfig<DownloadLicenseDialogData>) {
return dialogService.open<DownloadLicenseDialogResult>(DownloadLicenceDialogComponent, config);
cancel() {
this.onCanceled.emit();
} }
cancel = () => {
this.dialogRef.close(DownloadLicenseDialogResult.Cancelled);
};
} }

View File

@ -8,7 +8,7 @@ import { AdjustSubscription } from "./adjust-subscription.component";
import { BillingSyncApiKeyComponent } from "./billing-sync-api-key.component"; import { BillingSyncApiKeyComponent } from "./billing-sync-api-key.component";
import { BillingSyncKeyComponent } from "./billing-sync-key.component"; import { BillingSyncKeyComponent } from "./billing-sync-key.component";
import { ChangePlanComponent } from "./change-plan.component"; import { ChangePlanComponent } from "./change-plan.component";
import { DownloadLicenseComponent } from "./download-license.component"; import { DownloadLicenceDialogComponent } from "./download-license.component";
import { OrgBillingHistoryViewComponent } from "./organization-billing-history-view.component"; import { OrgBillingHistoryViewComponent } from "./organization-billing-history-view.component";
import { OrganizationBillingRoutingModule } from "./organization-billing-routing.module"; import { OrganizationBillingRoutingModule } from "./organization-billing-routing.module";
import { OrganizationPlansComponent } from "./organization-plans.component"; import { OrganizationPlansComponent } from "./organization-plans.component";
@ -32,7 +32,7 @@ import { SubscriptionStatusComponent } from "./subscription-status.component";
BillingSyncApiKeyComponent, BillingSyncApiKeyComponent,
BillingSyncKeyComponent, BillingSyncKeyComponent,
ChangePlanComponent, ChangePlanComponent,
DownloadLicenseComponent, DownloadLicenceDialogComponent,
OrganizationSubscriptionCloudComponent, OrganizationSubscriptionCloudComponent,
OrganizationSubscriptionSelfhostComponent, OrganizationSubscriptionSelfhostComponent,
OrgBillingHistoryViewComponent, OrgBillingHistoryViewComponent,

View File

@ -246,13 +246,6 @@
{{ (hasBillingSyncToken ? "manageBillingSync" : "setUpBillingSync") | i18n }} {{ (hasBillingSyncToken ? "manageBillingSync" : "setUpBillingSync") | i18n }}
</button> </button>
</div> </div>
<div class="tw-mt-3" *ngIf="showDownloadLicense">
<app-download-license
[organizationId]="organizationId"
(onDownloaded)="closeDownloadLicense()"
(onCanceled)="closeDownloadLicense()"
></app-download-license>
</div>
<ng-container *ngIf="userOrg.canEditSubscription"> <ng-container *ngIf="userOrg.canEditSubscription">
<h2 bitTypography="h2" class="tw-mt-7">{{ "additionalOptions" | i18n }}</h2> <h2 bitTypography="h2" class="tw-mt-7">{{ "additionalOptions" | i18n }}</h2>
<p bitTypography="body1"> <p bitTypography="body1">

View File

@ -29,6 +29,7 @@ import {
} from "../shared/offboarding-survey.component"; } from "../shared/offboarding-survey.component";
import { BillingSyncApiKeyComponent } from "./billing-sync-api-key.component"; import { BillingSyncApiKeyComponent } from "./billing-sync-api-key.component";
import { DownloadLicenceDialogComponent } from "./download-license.component";
import { ManageBilling } from "./icons/manage-billing.icon"; import { ManageBilling } from "./icons/manage-billing.icon";
import { SecretsManagerSubscriptionOptions } from "./sm-adjust-subscription.component"; import { SecretsManagerSubscriptionOptions } from "./sm-adjust-subscription.component";
@ -354,8 +355,12 @@ export class OrganizationSubscriptionCloudComponent implements OnInit, OnDestroy
this.showChangePlan = false; this.showChangePlan = false;
} }
downloadLicense() { async downloadLicense() {
this.showDownloadLicense = !this.showDownloadLicense; DownloadLicenceDialogComponent.open(this.dialogService, {
data: {
organizationId: this.organizationId,
},
});
} }
async manageBillingSync() { async manageBillingSync() {