1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

[PM-1504] Migrate Dialogs to DialogService (#5013)

This PR introduces a generic `DialogService` which can be used by all the clients. This allows us to decouple dialogs from the `PlatformUtilsHelper`.

The `DialogService` provides a new method, `openSimpleDialog` which is the new interface for that type of dialogs.

This gives us 3 different implementations: 
- Web: DialogService modern dialogs
- Browser: SweetAlert
- Desktop: Native electron based
This commit is contained in:
Oscar Hinton
2023-05-02 18:46:03 +02:00
committed by GitHub
parent 7c4b2c04b9
commit 4e1867682f
144 changed files with 1514 additions and 1212 deletions

View File

@@ -1,6 +1,7 @@
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { DialogServiceAbstraction, SimpleDialogType } from "@bitwarden/angular/services/dialog";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
@@ -32,7 +33,8 @@ export class UserSubscriptionComponent implements OnInit {
private i18nService: I18nService,
private router: Router,
private logService: LogService,
private fileDownloadService: FileDownloadService
private fileDownloadService: FileDownloadService,
private dialogService: DialogServiceAbstraction
) {
this.selfHosted = platformUtilsService.isSelfHost();
}
@@ -64,22 +66,23 @@ export class UserSubscriptionComponent implements OnInit {
}
if (this.usingInAppPurchase) {
this.platformUtilsService.showDialog(
this.i18nService.t("manageSubscriptionFromStore"),
this.i18nService.t("cancelSubscription"),
null,
null,
"warning"
);
this.dialogService.openSimpleDialog({
title: { key: "cancelSubscription" },
content: { key: "manageSubscriptionFromStore" },
acceptButtonText: { key: "ok" },
cancelButtonText: null,
type: SimpleDialogType.WARNING,
});
return;
}
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t("reinstateConfirmation"),
this.i18nService.t("reinstateSubscription"),
this.i18nService.t("yes"),
this.i18nService.t("cancel")
);
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "reinstateSubscription" },
content: { key: "reinstateConfirmation" },
type: SimpleDialogType.WARNING,
});
if (!confirmed) {
return;
}
@@ -100,23 +103,23 @@ export class UserSubscriptionComponent implements OnInit {
}
if (this.usingInAppPurchase) {
this.platformUtilsService.showDialog(
this.i18nService.t("manageSubscriptionFromStore"),
this.i18nService.t("cancelSubscription"),
null,
null,
"warning"
);
this.dialogService.openSimpleDialog({
title: { key: "cancelSubscription" },
content: { key: "manageSubscriptionFromStore" },
acceptButtonText: { key: "ok" },
cancelButtonText: null,
type: SimpleDialogType.WARNING,
});
return;
}
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t("cancelConfirmation"),
this.i18nService.t("cancelSubscription"),
this.i18nService.t("yes"),
this.i18nService.t("no"),
"warning"
);
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "cancelSubscription" },
content: { key: "cancelConfirmation" },
type: SimpleDialogType.WARNING,
});
if (!confirmed) {
return;
}
@@ -163,13 +166,14 @@ export class UserSubscriptionComponent implements OnInit {
adjustStorage(add: boolean) {
if (this.usingInAppPurchase) {
this.platformUtilsService.showDialog(
this.i18nService.t("cannotPerformInAppPurchase"),
this.i18nService.t(add ? "addStorage" : "removeStorage"),
null,
null,
"warning"
);
this.dialogService.openSimpleDialog({
title: { key: add ? "addStorage" : "removeStorage" },
content: { key: "cannotPerformInAppPurchase" },
acceptButtonText: { key: "ok" },
cancelButtonText: null,
type: SimpleDialogType.WARNING,
});
return;
}
this.adjustStorageAdd = add;