45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { DialogRef, DIALOG_DATA } from "@angular/cdk/dialog";
|
|
import { Component, Inject, OnInit } from "@angular/core";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
export interface AccessTokenDetails {
|
|
subTitle: string;
|
|
expirationDate?: Date;
|
|
accessToken: string;
|
|
}
|
|
|
|
@Component({
|
|
selector: "sm-access-token-dialog",
|
|
templateUrl: "./access-token-dialog.component.html",
|
|
})
|
|
export class AccessTokenDialogComponent implements OnInit {
|
|
constructor(
|
|
public dialogRef: DialogRef,
|
|
@Inject(DIALOG_DATA) public data: AccessTokenDetails,
|
|
private platformUtilsService: PlatformUtilsService,
|
|
private i18nService: I18nService
|
|
) {
|
|
this.dialogRef.disableClose = true;
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
// TODO remove null checks once strictNullChecks in TypeScript is turned on.
|
|
if (!this.data.subTitle || !this.data.accessToken) {
|
|
this.dialogRef.close();
|
|
throw new Error("The access token dialog was not called with the appropriate values.");
|
|
}
|
|
}
|
|
|
|
copyAccessToken(): void {
|
|
this.platformUtilsService.copyToClipboard(this.data.accessToken);
|
|
this.platformUtilsService.showToast(
|
|
"success",
|
|
null,
|
|
this.i18nService.t("accessTokenCreatedAndCopied")
|
|
);
|
|
this.dialogRef.close();
|
|
}
|
|
}
|