1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-18 01:41:27 +01:00

[AC-2411] migrate account component (#8854)

* migrate account component

* account component review comment addressed

* account component review comment addressed

---------

Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
This commit is contained in:
vinith-kovan 2024-06-26 23:16:32 +05:30 committed by GitHub
parent 31e5337ecf
commit b38629b4c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 69 deletions

View File

@ -1,9 +1,8 @@
<app-header></app-header> <app-header></app-header>
<bit-container> <bit-container>
<div *ngIf="loading"> <div *ngIf="loading">
<i <i
class="bwi bwi-spinner bwi-spin text-muted" class="bwi bwi-spinner bwi-spin tw-text-muted"
title="{{ 'loading' | i18n }}" title="{{ 'loading' | i18n }}"
aria-hidden="true" aria-hidden="true"
></i> ></i>
@ -37,9 +36,9 @@
</form> </form>
<ng-container *ngIf="canUseApi"> <ng-container *ngIf="canUseApi">
<h1 bitTypography="h1" class="tw-mt-16 tw-pb-2.5">{{ "apiKey" | i18n }}</h1> <h1 bitTypography="h1" class="tw-mt-16 tw-pb-2.5">{{ "apiKey" | i18n }}</h1>
<p> <p bitTypography="body1">
{{ "apiKeyDesc" | i18n }} {{ "apiKeyDesc" | i18n }}
<a href="https://docs.bitwarden.com" target="_blank" rel="noreferrer"> <a bitLink href="https://docs.bitwarden.com" target="_blank" rel="noreferrer">
{{ "learnMore" | i18n }} {{ "learnMore" | i18n }}
</a> </a>
</p> </p>
@ -56,7 +55,7 @@
[formGroup]="collectionManagementFormGroup" [formGroup]="collectionManagementFormGroup"
> >
<h1 bitTypography="h1" class="tw-mt-16 tw-pb-2.5">{{ "collectionManagement" | i18n }}</h1> <h1 bitTypography="h1" class="tw-mt-16 tw-pb-2.5">{{ "collectionManagement" | i18n }}</h1>
<p>{{ "collectionManagementDesc" | i18n }}</p> <p bitTypography="body1">{{ "collectionManagementDesc" | i18n }}</p>
<bit-form-control *ngIf="flexibleCollectionsV1Enabled$ | async"> <bit-form-control *ngIf="flexibleCollectionsV1Enabled$ | async">
<bit-label>{{ "allowAdminAccessToAllCollectionItemsDesc" | i18n }}</bit-label> <bit-label>{{ "allowAdminAccessToAllCollectionItemsDesc" | i18n }}</bit-label>
<input type="checkbox" bitCheckbox formControlName="allowAdminAccessToAllCollectionItems" /> <input type="checkbox" bitCheckbox formControlName="allowAdminAccessToAllCollectionItems" />

View File

@ -2,51 +2,35 @@
<bit-container> <bit-container>
<div *ngIf="loading"> <div *ngIf="loading">
<i <i
class="bwi bwi-spinner bwi-spin text-muted" class="bwi bwi-spinner bwi-spin tw-text-muted"
title="{{ 'loading' | i18n }}" title="{{ 'loading' | i18n }}"
aria-hidden="true" aria-hidden="true"
></i> ></i>
<span class="sr-only">{{ "loading" | i18n }}</span> <span class="tw-sr-only">{{ "loading" | i18n }}</span>
</div> </div>
<form <form *ngIf="provider && !loading" [formGroup]="formGroup" [bitSubmit]="submit">
*ngIf="provider && !loading" <div class="tw-grid tw-grid-cols-12 tw-gap-4">
#form <div class="tw-col-span-6">
(ngSubmit)="submit()" <bit-form-field>
[appApiAction]="formPromise" <bit-label>{{ "providerName" | i18n }}</bit-label>
ngNativeValidate <input bitInput type="text" formControlName="providerName" [disabled]="selfHosted" />
> </bit-form-field>
<div class="row"> <bit-form-field>
<div class="col-6"> <bit-label>{{ "billingEmail" | i18n }}</bit-label>
<div class="form-group">
<label for="name">{{ "providerName" | i18n }}</label>
<input <input
id="name" bitInput
class="form-control"
type="text" type="text"
name="Name" formControlName="providerBillingEmail"
[(ngModel)]="provider.name"
[disabled]="selfHosted" [disabled]="selfHosted"
/> />
</div> </bit-form-field>
<div class="form-group">
<label for="billingEmail">{{ "billingEmail" | i18n }}</label>
<input
id="billingEmail"
class="form-control"
type="text"
name="BillingEmail"
[(ngModel)]="provider.billingEmail"
[disabled]="selfHosted"
/>
</div>
</div> </div>
<div class="col-6"> <div class="tw-col-span-6">
<bit-avatar [text]="provider.name" [id]="provider.id" size="large"></bit-avatar> <bit-avatar [text]="provider.name" [id]="provider.id" size="large"></bit-avatar>
</div> </div>
</div> </div>
<button type="submit" class="btn btn-primary btn-submit" [disabled]="form.loading"> <button type="submit" bitFormButton bitButton buttonType="primary">
<i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i> {{ "save" | i18n }}
<span>{{ "save" | i18n }}</span>
</button> </button>
</form> </form>

View File

@ -1,5 +1,7 @@
import { Component } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { Subject, switchMap, takeUntil } from "rxjs";
import { UserVerificationDialogComponent } from "@bitwarden/auth/angular"; import { UserVerificationDialogComponent } from "@bitwarden/auth/angular";
import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { ApiService } from "@bitwarden/common/abstractions/api.service";
@ -19,15 +21,18 @@ import { DialogService } from "@bitwarden/components";
templateUrl: "account.component.html", templateUrl: "account.component.html",
}) })
// eslint-disable-next-line rxjs-angular/prefer-takeuntil // eslint-disable-next-line rxjs-angular/prefer-takeuntil
export class AccountComponent { export class AccountComponent implements OnDestroy, OnInit {
selfHosted = false; selfHosted = false;
loading = true; loading = true;
provider: ProviderResponse; provider: ProviderResponse;
formPromise: Promise<any>;
taxFormPromise: Promise<any>; taxFormPromise: Promise<any>;
private destroy$ = new Subject<void>();
private providerId: string; private providerId: string;
protected formGroup = this.formBuilder.group({
providerName: ["" as ProviderResponse["name"]],
providerBillingEmail: ["" as ProviderResponse["billingEmail"], Validators.email],
});
protected enableDeleteProvider$ = this.configService.getFeatureFlag$( protected enableDeleteProvider$ = this.configService.getFeatureFlag$(
FeatureFlag.EnableDeleteProvider, FeatureFlag.EnableDeleteProvider,
); );
@ -42,39 +47,47 @@ export class AccountComponent {
private dialogService: DialogService, private dialogService: DialogService,
private configService: ConfigService, private configService: ConfigService,
private providerApiService: ProviderApiServiceAbstraction, private providerApiService: ProviderApiServiceAbstraction,
private formBuilder: FormBuilder,
private router: Router, private router: Router,
) {} ) {}
async ngOnInit() { async ngOnInit() {
this.selfHosted = this.platformUtilsService.isSelfHost(); this.selfHosted = this.platformUtilsService.isSelfHost();
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe this.route.parent.parent.params
this.route.parent.parent.params.subscribe(async (params) => { .pipe(
this.providerId = params.providerId; switchMap(async (params) => {
try { this.providerId = params.providerId;
this.provider = await this.providerApiService.getProvider(this.providerId); try {
} catch (e) { this.provider = await this.providerApiService.getProvider(this.providerId);
this.logService.error(`Handled exception: ${e}`); this.formGroup.patchValue({
} providerName: this.provider.name,
}); providerBillingEmail: this.provider.billingEmail,
this.loading = false; });
} catch (e) {
this.logService.error(`Handled exception: ${e}`);
} finally {
this.loading = false;
}
}),
takeUntil(this.destroy$),
)
.subscribe();
} }
ngOnDestroy() {
async submit() { this.destroy$.next();
try { this.destroy$.complete();
const request = new ProviderUpdateRequest();
request.name = this.provider.name;
request.businessName = this.provider.businessName;
request.billingEmail = this.provider.billingEmail;
this.formPromise = this.providerApiService.putProvider(this.providerId, request).then(() => {
return this.syncService.fullSync(true);
});
await this.formPromise;
this.platformUtilsService.showToast("success", null, this.i18nService.t("providerUpdated"));
} catch (e) {
this.logService.error(`Handled exception: ${e}`);
}
} }
submit = async () => {
const request = new ProviderUpdateRequest();
request.name = this.formGroup.value.providerName;
request.businessName = this.formGroup.value.providerName;
request.billingEmail = this.formGroup.value.providerBillingEmail;
await this.providerApiService.putProvider(this.providerId, request);
await this.syncService.fullSync(true);
this.provider = await this.providerApiService.getProvider(this.providerId);
this.platformUtilsService.showToast("success", null, this.i18nService.t("providerUpdated"));
};
async deleteProvider() { async deleteProvider() {
const providerClients = await this.apiService.getProviderClients(this.providerId); const providerClients = await this.apiService.getProviderClients(this.providerId);
@ -105,7 +118,6 @@ export class AccountComponent {
} catch (e) { } catch (e) {
this.logService.error(e); this.logService.error(e);
} }
await this.router.navigate(["/"]); await this.router.navigate(["/"]);
} }