1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

[PM-5020] Adjust Storage component migration (#8301)

* Migrated Add Storage component

* PM-5020 Addressed review comments for Adjust Storage component

* PM-5020 Changes done in dialog css

* PM-5020 Latest review comments addressed

* PM-5020 Add storage submit action changes done

* PM-5020 Moved the paragraph to top of dialog content
This commit is contained in:
KiruthigaManivannan
2024-04-17 01:10:10 +05:30
committed by GitHub
parent cf2fefaead
commit 9ecf384176
6 changed files with 180 additions and 160 deletions

View File

@@ -170,8 +170,8 @@
</div> </div>
<ng-container *ngIf="subscription && !subscription.cancelled && !subscriptionMarkedForCancel"> <ng-container *ngIf="subscription && !subscription.cancelled && !subscriptionMarkedForCancel">
<div class="mt-3"> <div class="mt-3">
<div class="d-flex" *ngIf="!showAdjustStorage"> <div class="d-flex">
<button bitButton type="button" buttonType="secondary" (click)="adjustStorage(true)"> <button bitButton type="button" buttonType="secondary" [bitAction]="adjustStorage(true)">
{{ "addStorage" | i18n }} {{ "addStorage" | i18n }}
</button> </button>
<button <button
@@ -179,18 +179,11 @@
type="button" type="button"
buttonType="secondary" buttonType="secondary"
class="tw-ml-1" class="tw-ml-1"
(click)="adjustStorage(false)" [bitAction]="adjustStorage(false)"
> >
{{ "removeStorage" | i18n }} {{ "removeStorage" | i18n }}
</button> </button>
</div> </div>
<app-adjust-storage
[storageGbPrice]="4"
[add]="adjustStorageAdd"
(onAdjusted)="closeStorage(true)"
(onCanceled)="closeStorage(false)"
*ngIf="showAdjustStorage"
></app-adjust-storage>
</div> </div>
</ng-container> </ng-container>
</ng-container> </ng-container>

View File

@@ -12,6 +12,10 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService } from "@bitwarden/components";
import {
AdjustStorageDialogResult,
openAdjustStorageDialog,
} from "../shared/adjust-storage.component";
import { import {
OffboardingSurveyDialogResultType, OffboardingSurveyDialogResultType,
openOffboardingSurvey, openOffboardingSurvey,
@@ -24,7 +28,6 @@ export class UserSubscriptionComponent implements OnInit {
loading = false; loading = false;
firstLoaded = false; firstLoaded = false;
adjustStorageAdd = true; adjustStorageAdd = true;
showAdjustStorage = false;
showUpdateLicense = false; showUpdateLicense = false;
sub: SubscriptionResponse; sub: SubscriptionResponse;
selfHosted = false; selfHosted = false;
@@ -144,19 +147,20 @@ export class UserSubscriptionComponent implements OnInit {
} }
} }
adjustStorage(add: boolean) { adjustStorage = (add: boolean) => {
this.adjustStorageAdd = add; return async () => {
this.showAdjustStorage = true; const dialogRef = openAdjustStorageDialog(this.dialogService, {
} data: {
storageGbPrice: 4,
closeStorage(load: boolean) { add: add,
this.showAdjustStorage = false; },
if (load) { });
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. const result = await lastValueFrom(dialogRef.closed);
// eslint-disable-next-line @typescript-eslint/no-floating-promises if (result === AdjustStorageDialogResult.Adjusted) {
this.load(); await this.load();
}
} }
};
};
get subscriptionMarkedForCancel() { get subscriptionMarkedForCancel() {
return ( return (

View File

@@ -175,23 +175,24 @@
<bit-progress [barWidth]="storagePercentage" bgColor="success"></bit-progress> <bit-progress [barWidth]="storagePercentage" bgColor="success"></bit-progress>
<ng-container *ngIf="subscription && !subscription.cancelled && !subscriptionMarkedForCancel"> <ng-container *ngIf="subscription && !subscription.cancelled && !subscriptionMarkedForCancel">
<div class="tw-mt-3"> <div class="tw-mt-3">
<div class="tw-flex tw-space-x-2" *ngIf="!showAdjustStorage"> <div class="tw-flex tw-space-x-2">
<button bitButton buttonType="secondary" type="button" (click)="adjustStorage(true)"> <button
bitButton
buttonType="secondary"
type="button"
[bitAction]="adjustStorage(true)"
>
{{ "addStorage" | i18n }} {{ "addStorage" | i18n }}
</button> </button>
<button bitButton buttonType="secondary" type="button" (click)="adjustStorage(false)"> <button
bitButton
buttonType="secondary"
type="button"
[bitAction]="adjustStorage(false)"
>
{{ "removeStorage" | i18n }} {{ "removeStorage" | i18n }}
</button> </button>
</div> </div>
<app-adjust-storage
[storageGbPrice]="storageGbPrice"
[add]="adjustStorageAdd"
[organizationId]="organizationId"
[interval]="billingInterval"
(onAdjusted)="closeStorage(true)"
(onCanceled)="closeStorage(false)"
*ngIf="showAdjustStorage"
></app-adjust-storage>
</div> </div>
</ng-container> </ng-container>
<ng-container *ngIf="showAdjustSecretsManager"> <ng-container *ngIf="showAdjustSecretsManager">

View File

@@ -18,6 +18,10 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components"; import { DialogService } from "@bitwarden/components";
import {
AdjustStorageDialogResult,
openAdjustStorageDialog,
} from "../shared/adjust-storage.component";
import { import {
OffboardingSurveyDialogResultType, OffboardingSurveyDialogResultType,
openOffboardingSurvey, openOffboardingSurvey,
@@ -36,8 +40,6 @@ export class OrganizationSubscriptionCloudComponent implements OnInit, OnDestroy
userOrg: Organization; userOrg: Organization;
showChangePlan = false; showChangePlan = false;
showDownloadLicense = false; showDownloadLicense = false;
adjustStorageAdd = true;
showAdjustStorage = false;
hasBillingSyncToken: boolean; hasBillingSyncToken: boolean;
showAdjustSecretsManager = false; showAdjustSecretsManager = false;
showSecretsManagerSubscribe = false; showSecretsManagerSubscribe = false;
@@ -361,19 +363,22 @@ export class OrganizationSubscriptionCloudComponent implements OnInit, OnDestroy
this.load(); this.load();
} }
adjustStorage(add: boolean) { adjustStorage = (add: boolean) => {
this.adjustStorageAdd = add; return async () => {
this.showAdjustStorage = true; const dialogRef = openAdjustStorageDialog(this.dialogService, {
} data: {
storageGbPrice: this.storageGbPrice,
closeStorage(load: boolean) { add: add,
this.showAdjustStorage = false; organizationId: this.organizationId,
if (load) { interval: this.billingInterval,
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. },
// eslint-disable-next-line @typescript-eslint/no-floating-promises });
this.load(); const result = await lastValueFrom(dialogRef.closed);
} if (result === AdjustStorageDialogResult.Adjusted) {
await this.load();
} }
};
};
removeSponsorship = async () => { removeSponsorship = async () => {
const confirmed = await this.dialogService.openSimpleDialog({ const confirmed = await this.dialogService.openSimpleDialog({

View File

@@ -1,43 +1,35 @@
<form #form class="card" (ngSubmit)="submit()" [appApiAction]="formPromise" ngNativeValidate> <form [formGroup]="formGroup" [bitSubmit]="submit">
<div class="card-body"> <bit-dialog dialogSize="default" [title]="(add ? 'addStorage' : 'removeStorage') | i18n">
<button type="button" class="close" appA11yTitle="{{ 'cancel' | i18n }}" (click)="cancel()"> <ng-container bitDialogContent>
<span aria-hidden="true">&times;</span> <p bitTypography="body1">{{ (add ? "storageAddNote" : "storageRemoveNote") | i18n }}</p>
</button> <div class="tw-grid tw-grid-cols-12">
<h3 class="card-body-header">{{ (add ? "addStorage" : "removeStorage") | i18n }}</h3> <bit-form-field class="tw-col-span-7">
<div class="row"> <bit-label>{{ (add ? "gbStorageAdd" : "gbStorageRemove") | i18n }}</bit-label>
<div class="form-group col-6"> <input bitInput type="number" formControlName="storageAdjustment" />
<label for="storageAdjustment">{{ <bit-hint *ngIf="add">
(add ? "gbStorageAdd" : "gbStorageRemove") | i18n <strong>{{ "total" | i18n }}:</strong>
}}</label> {{ formGroup.get("storageAdjustment").value || 0 }} GB &times;
<input
id="storageAdjustment"
class="form-control"
type="number"
name="StorageGbAdjustment"
[(ngModel)]="storageAdjustment"
min="0"
max="99"
step="1"
required
/>
</div>
</div>
<div *ngIf="add" class="mb-3">
<strong>{{ "total" | i18n }}:</strong> {{ storageAdjustment || 0 }} GB &times;
{{ storageGbPrice | currency: "$" }} = {{ adjustedStorageTotal | currency: "$" }} /{{ {{ storageGbPrice | currency: "$" }} = {{ adjustedStorageTotal | currency: "$" }} /{{
interval | i18n interval | i18n
}} }}
</bit-hint>
</bit-form-field>
</div> </div>
<button type="submit" class="btn btn-primary btn-submit" [disabled]="form.loading"> </ng-container>
<i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i> <ng-container bitDialogFooter>
<span>{{ "submit" | i18n }}</span> <button type="submit" bitButton bitFormButton buttonType="primary">
{{ "submit" | i18n }}
</button> </button>
<button type="button" class="btn btn-outline-secondary" (click)="cancel()"> <button
type="button"
bitButton
bitFormButton
buttonType="secondary"
[bitDialogClose]="DialogResult.Cancelled"
>
{{ "cancel" | i18n }} {{ "cancel" | i18n }}
</button> </button>
<small class="d-block text-muted mt-3"> </ng-container>
{{ (add ? "storageAddNote" : "storageRemoveNote") | i18n }} </bit-dialog>
</small>
</div>
</form> </form>
<app-payment [showMethods]="false"></app-payment> <app-payment [showMethods]="false"></app-payment>

View File

@@ -1,4 +1,6 @@
import { Component, EventEmitter, Input, Output, ViewChild } from "@angular/core"; import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
import { Component, Inject, ViewChild } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { ApiService } from "@bitwarden/common/abstractions/api.service";
@@ -8,27 +10,45 @@ import { StorageRequest } from "@bitwarden/common/models/request/storage.request
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService } from "@bitwarden/components";
import { PaymentComponent } from "./payment.component"; import { PaymentComponent } from "./payment.component";
export interface AdjustStorageDialogData {
storageGbPrice: number;
add: boolean;
organizationId?: string;
interval?: string;
}
export enum AdjustStorageDialogResult {
Adjusted = "adjusted",
Cancelled = "cancelled",
}
@Component({ @Component({
selector: "app-adjust-storage",
templateUrl: "adjust-storage.component.html", templateUrl: "adjust-storage.component.html",
}) })
export class AdjustStorageComponent { export class AdjustStorageComponent {
@Input() storageGbPrice = 0; storageGbPrice: number;
@Input() add = true; add: boolean;
@Input() organizationId: string; organizationId: string;
@Input() interval = "year"; interval: string;
@Output() onAdjusted = new EventEmitter<number>();
@Output() onCanceled = new EventEmitter();
@ViewChild(PaymentComponent, { static: true }) paymentComponent: PaymentComponent; @ViewChild(PaymentComponent, { static: true }) paymentComponent: PaymentComponent;
storageAdjustment = 0; protected DialogResult = AdjustStorageDialogResult;
formPromise: Promise<PaymentResponse | void>; protected formGroup = new FormGroup({
storageAdjustment: new FormControl(0, [
Validators.required,
Validators.min(0),
Validators.max(99),
]),
});
constructor( constructor(
private dialogRef: DialogRef,
@Inject(DIALOG_DATA) protected data: AdjustStorageDialogData,
private apiService: ApiService, private apiService: ApiService,
private i18nService: I18nService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
@@ -36,12 +56,16 @@ export class AdjustStorageComponent {
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private logService: LogService, private logService: LogService,
private organizationApiService: OrganizationApiServiceAbstraction, private organizationApiService: OrganizationApiServiceAbstraction,
) {} ) {
this.storageGbPrice = data.storageGbPrice;
this.add = data.add;
this.organizationId = data.organizationId;
this.interval = data.interval || "year";
}
async submit() { submit = async () => {
try {
const request = new StorageRequest(); const request = new StorageRequest();
request.storageGbAdjustment = this.storageAdjustment; request.storageGbAdjustment = this.formGroup.value.storageAdjustment;
if (!this.add) { if (!this.add) {
request.storageGbAdjustment *= -1; request.storageGbAdjustment *= -1;
} }
@@ -50,12 +74,9 @@ export class AdjustStorageComponent {
const action = async () => { const action = async () => {
let response: Promise<PaymentResponse>; let response: Promise<PaymentResponse>;
if (this.organizationId == null) { if (this.organizationId == null) {
response = this.formPromise = this.apiService.postAccountStorage(request); response = this.apiService.postAccountStorage(request);
} else { } else {
response = this.formPromise = this.organizationApiService.updateStorage( response = this.organizationApiService.updateStorage(this.organizationId, request);
this.organizationId,
request,
);
} }
const result = await response; const result = await response;
if (result != null && result.paymentIntentClientSecret != null) { if (result != null && result.paymentIntentClientSecret != null) {
@@ -69,9 +90,8 @@ export class AdjustStorageComponent {
} }
} }
}; };
this.formPromise = action(); await action();
await this.formPromise; this.dialogRef.close(AdjustStorageDialogResult.Adjusted);
this.onAdjusted.emit(this.storageAdjustment);
if (paymentFailed) { if (paymentFailed) {
this.platformUtilsService.showToast( this.platformUtilsService.showToast(
"warning", "warning",
@@ -89,16 +109,21 @@ export class AdjustStorageComponent {
this.i18nService.t("adjustedStorage", request.storageGbAdjustment.toString()), this.i18nService.t("adjustedStorage", request.storageGbAdjustment.toString()),
); );
} }
} catch (e) { };
this.logService.error(e);
}
}
cancel() {
this.onCanceled.emit();
}
get adjustedStorageTotal(): number { get adjustedStorageTotal(): number {
return this.storageGbPrice * this.storageAdjustment; return this.storageGbPrice * this.formGroup.value.storageAdjustment;
} }
} }
/**
* Strongly typed helper to open an AdjustStorageDialog
* @param dialogService Instance of the dialog service that will be used to open the dialog
* @param config Configuration for the dialog
*/
export function openAdjustStorageDialog(
dialogService: DialogService,
config: DialogConfig<AdjustStorageDialogData>,
) {
return dialogService.open<AdjustStorageDialogResult>(AdjustStorageComponent, config);
}