1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00
Files
browser/apps/web/src/app/billing/organizations/download-license.component.ts
vinith-kovan 7e86c0afd4 [PM-5014] Download license component migration (#8443)
* Download license component migration

* download license dialog component migration

* download license dialog component migration
2024-06-05 13:45:08 +05:30

62 lines
2.3 KiB
TypeScript

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 { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
import { DialogService } from "@bitwarden/components";
export enum DownloadLicenseDialogResult {
Cancelled = "cancelled",
Downloaded = "downloaded",
}
type DownloadLicenseDialogData = {
/** current organization id */
organizationId: string;
};
@Component({
templateUrl: "download-license.component.html",
})
export class DownloadLicenceDialogComponent {
licenseForm = this.formBuilder.group({
installationId: ["", [Validators.required]],
});
constructor(
@Inject(DIALOG_DATA) protected data: DownloadLicenseDialogData,
private dialogRef: DialogRef,
private fileDownloadService: FileDownloadService,
private organizationApiService: OrganizationApiServiceAbstraction,
protected formBuilder: FormBuilder,
) {}
submit = async () => {
this.licenseForm.markAllAsTouched();
const installationId = this.licenseForm.get("installationId").value;
if (installationId == null || installationId === "") {
return;
}
const license = await this.organizationApiService.getLicense(
this.data.organizationId,
installationId,
);
const licenseString = JSON.stringify(license, null, 2);
this.fileDownloadService.download({
fileName: "bitwarden_organization_license.json",
blobData: licenseString,
});
this.dialogRef.close(DownloadLicenseDialogResult.Downloaded);
};
/**
* Strongly typed helper to open a DownloadLicenceDialogComponent
* @param dialogService Instance of the dialog service that will be used to open the dialog
* @param config Configuration for the dialog
*/
static open(dialogService: DialogService, config: DialogConfig<DownloadLicenseDialogData>) {
return dialogService.open<DownloadLicenseDialogResult>(DownloadLicenceDialogComponent, config);
}
cancel = () => {
this.dialogRef.close(DownloadLicenseDialogResult.Cancelled);
};
}