1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 17:53:39 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/access/access-tokens.component.ts
Will Martin 8ac8cc0274 [SM-383] add create access token button (#4547)
* rebase to master; add create access token button

* add static method to access-tokens component
2023-01-31 11:29:38 -05:00

52 lines
1.6 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
import { DialogService } from "@bitwarden/components";
import { AccessTokenView } from "../models/view/access-token.view";
import { AccessService } from "./access.service";
import { AccessTokenCreateDialogComponent } from "./dialogs/access-token-create-dialog.component";
@Component({
selector: "sm-access-tokens",
templateUrl: "./access-tokens.component.html",
})
export class AccessTokenComponent implements OnInit {
accessTokens$: Observable<AccessTokenView[]>;
private serviceAccountId: string;
private organizationId: string;
constructor(
private route: ActivatedRoute,
private accessService: AccessService,
private dialogService: DialogService
) {}
ngOnInit() {
this.accessTokens$ = this.accessService.accessToken$.pipe(
startWith(null),
combineLatestWith(this.route.params),
switchMap(async ([_, params]) => {
this.organizationId = params.organizationId;
this.serviceAccountId = params.serviceAccountId;
return await this.getAccessTokens();
})
);
}
private async getAccessTokens(): Promise<AccessTokenView[]> {
return await this.accessService.getAccessTokens(this.organizationId, this.serviceAccountId);
}
protected openNewAccessTokenDialog() {
AccessTokenCreateDialogComponent.openNewAccessTokenDialog(
this.dialogService,
this.serviceAccountId,
this.organizationId
);
}
}