From 8d0473163337115963b7c387e5074cb999f42565 Mon Sep 17 00:00:00 2001 From: Daniel James Smith <2670567+djsmith85@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:28:47 +0200 Subject: [PATCH] [PM-6568][PM-8820][Tech-Debt] Migrate all tools owned toasts to use CL ToastService instead of PlatformUtilsService (#9405) * Migrate all tools owned toasts to use CL ToastService instead of PlatformUtilsService * Fix test that was missing a mock * Fix double checking file and file-content selection --------- Co-authored-by: Daniel James Smith --- .../popup/generator/generator.component.ts | 3 + .../password-generator-history.component.ts | 4 +- .../popup/send/send-add-edit.component.ts | 4 +- .../popup/send/send-groupings.component.ts | 4 +- .../tools/popup/send/send-type.component.ts | 4 +- .../src/app/tools/generator.component.spec.ts | 5 ++ .../src/app/tools/generator.component.ts | 3 + .../password-generator-history.component.ts | 4 +- .../src/app/tools/send/add-edit.component.ts | 14 ++-- .../src/app/tools/send/send.component.ts | 4 +- .../org-vault-export.component.ts | 7 +- apps/web/src/app/tools/generator.component.ts | 4 +- .../password-generator-history.component.ts | 4 +- .../src/app/tools/send/access.component.ts | 15 ++-- .../src/app/tools/send/add-edit.component.ts | 4 +- .../tools/send/send-access-file.component.ts | 22 ++++-- .../tools/send/send-access-text.component.ts | 12 ++-- apps/web/src/app/tools/send/send.component.ts | 10 ++- .../tools/vault-export/export.component.ts | 13 ++-- .../components/generator.component.ts | 15 ++-- .../password-generator-history.component.ts | 12 ++-- .../src/tools/send/add-edit.component.ts | 69 ++++++++++--------- libs/angular/src/tools/send/send.component.ts | 25 ++++--- .../src/components/import.component.ts | 40 +++++------ .../src/components/export.component.ts | 24 +++---- 25 files changed, 197 insertions(+), 128 deletions(-) diff --git a/apps/browser/src/tools/popup/generator/generator.component.ts b/apps/browser/src/tools/popup/generator/generator.component.ts index 1afe696576..cb671f7201 100644 --- a/apps/browser/src/tools/popup/generator/generator.component.ts +++ b/apps/browser/src/tools/popup/generator/generator.component.ts @@ -13,6 +13,7 @@ import { UsernameGenerationServiceAbstraction } from "@bitwarden/common/tools/ge import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { AddEditCipherInfo } from "@bitwarden/common/vault/types/add-edit-cipher-info"; +import { ToastService } from "@bitwarden/components"; @Component({ selector: "app-generator", @@ -34,6 +35,7 @@ export class GeneratorComponent extends BaseGeneratorComponent { logService: LogService, ngZone: NgZone, private location: Location, + toastService: ToastService, ) { super( passwordGenerationService, @@ -45,6 +47,7 @@ export class GeneratorComponent extends BaseGeneratorComponent { route, ngZone, window, + toastService, ); this.cipherService = cipherService; } diff --git a/apps/browser/src/tools/popup/generator/password-generator-history.component.ts b/apps/browser/src/tools/popup/generator/password-generator-history.component.ts index 8448077083..e27c42a111 100644 --- a/apps/browser/src/tools/popup/generator/password-generator-history.component.ts +++ b/apps/browser/src/tools/popup/generator/password-generator-history.component.ts @@ -5,6 +5,7 @@ import { PasswordGeneratorHistoryComponent as BasePasswordGeneratorHistoryCompon import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password"; +import { ToastService } from "@bitwarden/components"; @Component({ selector: "app-password-generator-history", @@ -16,8 +17,9 @@ export class PasswordGeneratorHistoryComponent extends BasePasswordGeneratorHist platformUtilsService: PlatformUtilsService, i18nService: I18nService, private location: Location, + toastService: ToastService, ) { - super(passwordGenerationService, platformUtilsService, i18nService, window); + super(passwordGenerationService, platformUtilsService, i18nService, window, toastService); } close() { diff --git a/apps/browser/src/tools/popup/send/send-add-edit.component.ts b/apps/browser/src/tools/popup/send/send-add-edit.component.ts index 5ff3621e35..7f17217816 100644 --- a/apps/browser/src/tools/popup/send/send-add-edit.component.ts +++ b/apps/browser/src/tools/popup/send/send-add-edit.component.ts @@ -15,7 +15,7 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils"; import { BrowserStateService } from "../../../platform/services/abstractions/browser-state.service"; @@ -53,6 +53,7 @@ export class SendAddEditComponent extends BaseAddEditComponent { private filePopoutUtilsService: FilePopoutUtilsService, billingAccountProfileStateService: BillingAccountProfileStateService, accountService: AccountService, + toastService: ToastService, ) { super( i18nService, @@ -69,6 +70,7 @@ export class SendAddEditComponent extends BaseAddEditComponent { formBuilder, billingAccountProfileStateService, accountService, + toastService, ); } diff --git a/apps/browser/src/tools/popup/send/send-groupings.component.ts b/apps/browser/src/tools/popup/send/send-groupings.component.ts index 87d03c4b76..ae76c0ef94 100644 --- a/apps/browser/src/tools/popup/send/send-groupings.component.ts +++ b/apps/browser/src/tools/popup/send/send-groupings.component.ts @@ -14,7 +14,7 @@ import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { BrowserSendComponentState } from "../../../models/browserSendComponentState"; import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils"; @@ -49,6 +49,7 @@ export class SendGroupingsComponent extends BaseSendComponent { logService: LogService, sendApiService: SendApiService, dialogService: DialogService, + toastService: ToastService, ) { super( sendService, @@ -61,6 +62,7 @@ export class SendGroupingsComponent extends BaseSendComponent { logService, sendApiService, dialogService, + toastService, ); super.onSuccessfulLoad = async () => { this.selectAll(); diff --git a/apps/browser/src/tools/popup/send/send-type.component.ts b/apps/browser/src/tools/popup/send/send-type.component.ts index aca02587de..122aa7e021 100644 --- a/apps/browser/src/tools/popup/send/send-type.component.ts +++ b/apps/browser/src/tools/popup/send/send-type.component.ts @@ -15,7 +15,7 @@ import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { BrowserComponentState } from "../../../models/browserComponentState"; import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils"; @@ -51,6 +51,7 @@ export class SendTypeComponent extends BaseSendComponent { logService: LogService, sendApiService: SendApiService, dialogService: DialogService, + toastService: ToastService, ) { super( sendService, @@ -63,6 +64,7 @@ export class SendTypeComponent extends BaseSendComponent { logService, sendApiService, dialogService, + toastService, ); super.onSuccessfulLoad = async () => { this.selectType(this.type); diff --git a/apps/desktop/src/app/tools/generator.component.spec.ts b/apps/desktop/src/app/tools/generator.component.spec.ts index dff7da9600..db8160c202 100644 --- a/apps/desktop/src/app/tools/generator.component.spec.ts +++ b/apps/desktop/src/app/tools/generator.component.spec.ts @@ -11,6 +11,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password"; import { UsernameGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/username"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; +import { ToastService } from "@bitwarden/components"; import { GeneratorComponent } from "./generator.component"; @@ -59,6 +60,10 @@ describe("GeneratorComponent", () => { provide: AccountService, useValue: mock(), }, + { + provide: ToastService, + useValue: mock(), + }, ], schemas: [NO_ERRORS_SCHEMA], }).compileComponents(); diff --git a/apps/desktop/src/app/tools/generator.component.ts b/apps/desktop/src/app/tools/generator.component.ts index a5c3d39387..0f1443314d 100644 --- a/apps/desktop/src/app/tools/generator.component.ts +++ b/apps/desktop/src/app/tools/generator.component.ts @@ -8,6 +8,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password"; import { UsernameGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/username"; +import { ToastService } from "@bitwarden/components"; @Component({ selector: "app-generator", @@ -23,6 +24,7 @@ export class GeneratorComponent extends BaseGeneratorComponent { route: ActivatedRoute, ngZone: NgZone, logService: LogService, + toastService: ToastService, ) { super( passwordGenerationService, @@ -34,6 +36,7 @@ export class GeneratorComponent extends BaseGeneratorComponent { route, ngZone, window, + toastService, ); } diff --git a/apps/desktop/src/app/tools/password-generator-history.component.ts b/apps/desktop/src/app/tools/password-generator-history.component.ts index f62662bd4f..07ebe5fb4b 100644 --- a/apps/desktop/src/app/tools/password-generator-history.component.ts +++ b/apps/desktop/src/app/tools/password-generator-history.component.ts @@ -4,6 +4,7 @@ import { PasswordGeneratorHistoryComponent as BasePasswordGeneratorHistoryCompon import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password"; +import { ToastService } from "@bitwarden/components"; @Component({ selector: "app-password-generator-history", @@ -14,7 +15,8 @@ export class PasswordGeneratorHistoryComponent extends BasePasswordGeneratorHist passwordGenerationService: PasswordGenerationServiceAbstraction, platformUtilsService: PlatformUtilsService, i18nService: I18nService, + toastService: ToastService, ) { - super(passwordGenerationService, platformUtilsService, i18nService, window); + super(passwordGenerationService, platformUtilsService, i18nService, window, toastService); } } diff --git a/apps/desktop/src/app/tools/send/add-edit.component.ts b/apps/desktop/src/app/tools/send/add-edit.component.ts index 804a390438..6f2287ea10 100644 --- a/apps/desktop/src/app/tools/send/add-edit.component.ts +++ b/apps/desktop/src/app/tools/send/add-edit.component.ts @@ -14,7 +14,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; @Component({ selector: "app-send-add-edit", @@ -36,6 +36,7 @@ export class AddEditComponent extends BaseAddEditComponent { formBuilder: FormBuilder, billingAccountProfileStateService: BillingAccountProfileStateService, accountService: AccountService, + toastService: ToastService, ) { super( i18nService, @@ -52,6 +53,7 @@ export class AddEditComponent extends BaseAddEditComponent { formBuilder, billingAccountProfileStateService, accountService, + toastService, ); } @@ -70,11 +72,11 @@ export class AddEditComponent extends BaseAddEditComponent { // 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 super.copyLinkToClipboard(link); - this.platformUtilsService.showToast( - "success", - null, - this.i18nService.t("valueCopied", this.i18nService.t("sendLink")), - ); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("valueCopied", this.i18nService.t("sendLink")), + }); } async resetAndLoad() { diff --git a/apps/desktop/src/app/tools/send/send.component.ts b/apps/desktop/src/app/tools/send/send.component.ts index 75410b2922..5fa4254186 100644 --- a/apps/desktop/src/app/tools/send/send.component.ts +++ b/apps/desktop/src/app/tools/send/send.component.ts @@ -11,7 +11,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { invokeMenu, RendererMenuItem } from "../../../utils"; import { SearchBarService } from "../../layout/search/search-bar.service"; @@ -49,6 +49,7 @@ export class SendComponent extends BaseSendComponent implements OnInit, OnDestro logService: LogService, sendApiService: SendApiService, dialogService: DialogService, + toastService: ToastService, ) { super( sendService, @@ -61,6 +62,7 @@ export class SendComponent extends BaseSendComponent implements OnInit, OnDestro logService, sendApiService, dialogService, + toastService, ); // eslint-disable-next-line rxjs-angular/prefer-takeuntil this.searchBarService.searchText$.subscribe((searchText) => { diff --git a/apps/web/src/app/admin-console/organizations/tools/vault-export/org-vault-export.component.ts b/apps/web/src/app/admin-console/organizations/tools/vault-export/org-vault-export.component.ts index e3d19f5487..0caf39ea79 100644 --- a/apps/web/src/app/admin-console/organizations/tools/vault-export/org-vault-export.component.ts +++ b/apps/web/src/app/admin-console/organizations/tools/vault-export/org-vault-export.component.ts @@ -9,8 +9,7 @@ import { EventType } from "@bitwarden/common/enums"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { VaultExportServiceAbstraction } from "@bitwarden/vault-export-core"; import { ExportComponent } from "../../../../tools/vault-export/export.component"; @@ -23,7 +22,7 @@ import { ExportComponent } from "../../../../tools/vault-export/export.component export class OrganizationVaultExportComponent extends ExportComponent { constructor( i18nService: I18nService, - platformUtilsService: PlatformUtilsService, + toastService: ToastService, exportService: VaultExportServiceAbstraction, eventCollectionService: EventCollectionService, private route: ActivatedRoute, @@ -36,7 +35,7 @@ export class OrganizationVaultExportComponent extends ExportComponent { ) { super( i18nService, - platformUtilsService, + toastService, exportService, eventCollectionService, policyService, diff --git a/apps/web/src/app/tools/generator.component.ts b/apps/web/src/app/tools/generator.component.ts index fc27e65846..0a39228f3d 100644 --- a/apps/web/src/app/tools/generator.component.ts +++ b/apps/web/src/app/tools/generator.component.ts @@ -8,7 +8,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password"; import { UsernameGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/username"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { PasswordGeneratorHistoryComponent } from "./password-generator-history.component"; @@ -27,6 +27,7 @@ export class GeneratorComponent extends BaseGeneratorComponent { route: ActivatedRoute, ngZone: NgZone, private dialogService: DialogService, + toastService: ToastService, ) { super( passwordGenerationService, @@ -38,6 +39,7 @@ export class GeneratorComponent extends BaseGeneratorComponent { route, ngZone, window, + toastService, ); if (platformUtilsService.isSelfHost()) { // Allow only valid email forwarders for self host diff --git a/apps/web/src/app/tools/password-generator-history.component.ts b/apps/web/src/app/tools/password-generator-history.component.ts index f62662bd4f..07ebe5fb4b 100644 --- a/apps/web/src/app/tools/password-generator-history.component.ts +++ b/apps/web/src/app/tools/password-generator-history.component.ts @@ -4,6 +4,7 @@ import { PasswordGeneratorHistoryComponent as BasePasswordGeneratorHistoryCompon import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password"; +import { ToastService } from "@bitwarden/components"; @Component({ selector: "app-password-generator-history", @@ -14,7 +15,8 @@ export class PasswordGeneratorHistoryComponent extends BasePasswordGeneratorHist passwordGenerationService: PasswordGenerationServiceAbstraction, platformUtilsService: PlatformUtilsService, i18nService: I18nService, + toastService: ToastService, ) { - super(passwordGenerationService, platformUtilsService, i18nService, window); + super(passwordGenerationService, platformUtilsService, i18nService, window, toastService); } } diff --git a/apps/web/src/app/tools/send/access.component.ts b/apps/web/src/app/tools/send/access.component.ts index 9915bf5204..64e46b3ff5 100644 --- a/apps/web/src/app/tools/send/access.component.ts +++ b/apps/web/src/app/tools/send/access.component.ts @@ -8,7 +8,6 @@ import { ConfigService } from "@bitwarden/common/platform/abstractions/config/co import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service"; import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; @@ -18,7 +17,7 @@ import { SendAccessResponse } from "@bitwarden/common/tools/send/models/response import { SendAccessView } from "@bitwarden/common/tools/send/models/view/send-access.view"; import { SEND_KDF_ITERATIONS } from "@bitwarden/common/tools/send/send-kdf"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; -import { NoItemsModule } from "@bitwarden/components"; +import { NoItemsModule, ToastService } from "@bitwarden/components"; import { SharedModule } from "../../shared"; @@ -67,7 +66,7 @@ export class AccessComponent implements OnInit { private route: ActivatedRoute, private cryptoService: CryptoService, private sendApiService: SendApiService, - private platformUtilsService: PlatformUtilsService, + private toastService: ToastService, private i18nService: I18nService, private configService: ConfigService, protected formBuilder: FormBuilder, @@ -142,11 +141,11 @@ export class AccessComponent implements OnInit { } else if (e.statusCode === 404) { this.unavailable = true; } else if (e.statusCode === 400) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - e.message, - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: e.message, + }); } else { this.error = true; } diff --git a/apps/web/src/app/tools/send/add-edit.component.ts b/apps/web/src/app/tools/send/add-edit.component.ts index cca416db9c..4dc3001831 100644 --- a/apps/web/src/app/tools/send/add-edit.component.ts +++ b/apps/web/src/app/tools/send/add-edit.component.ts @@ -15,7 +15,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; @Component({ selector: "app-send-add-edit", @@ -42,6 +42,7 @@ export class AddEditComponent extends BaseAddEditComponent { protected dialogRef: DialogRef, @Inject(DIALOG_DATA) params: { sendId: string }, accountService: AccountService, + toastService: ToastService, ) { super( i18nService, @@ -58,6 +59,7 @@ export class AddEditComponent extends BaseAddEditComponent { formBuilder, billingAccountProfileStateService, accountService, + toastService, ); this.sendId = params.sendId; diff --git a/apps/web/src/app/tools/send/send-access-file.component.ts b/apps/web/src/app/tools/send/send-access-file.component.ts index 9b1dc5fbc0..8bb3558a69 100644 --- a/apps/web/src/app/tools/send/send-access-file.component.ts +++ b/apps/web/src/app/tools/send/send-access-file.component.ts @@ -3,13 +3,13 @@ import { Component, Input } from "@angular/core"; import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { EncArrayBuffer } from "@bitwarden/common/platform/models/domain/enc-array-buffer"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { SendAccessRequest } from "@bitwarden/common/tools/send/models/request/send-access.request"; import { SendAccessView } from "@bitwarden/common/tools/send/models/view/send-access.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; +import { ToastService } from "@bitwarden/components"; import { SharedModule } from "../../shared"; @@ -25,7 +25,7 @@ export class SendAccessFileComponent { @Input() accessRequest: SendAccessRequest; constructor( private i18nService: I18nService, - private platformUtilsService: PlatformUtilsService, + private toastService: ToastService, private cryptoService: CryptoService, private fileDownloadService: FileDownloadService, private sendApiService: SendApiService, @@ -42,13 +42,21 @@ export class SendAccessFileComponent { ); if (Utils.isNullOrWhitespace(downloadData.url)) { - this.platformUtilsService.showToast("error", null, this.i18nService.t("missingSendFile")); + this.toastService.showToast({ + variant: "error", + title: null, + message: this.i18nService.t("missingSendFile"), + }); return; } const response = await fetch(new Request(downloadData.url, { cache: "no-store" })); if (response.status !== 200) { - this.platformUtilsService.showToast("error", null, this.i18nService.t("errorOccurred")); + this.toastService.showToast({ + variant: "error", + title: null, + message: this.i18nService.t("errorOccurred"), + }); return; } @@ -61,7 +69,11 @@ export class SendAccessFileComponent { downloadMethod: "save", }); } catch (e) { - this.platformUtilsService.showToast("error", null, this.i18nService.t("errorOccurred")); + this.toastService.showToast({ + variant: "error", + title: null, + message: this.i18nService.t("errorOccurred"), + }); } }; } diff --git a/apps/web/src/app/tools/send/send-access-text.component.ts b/apps/web/src/app/tools/send/send-access-text.component.ts index f86a24f14a..290bde50cd 100644 --- a/apps/web/src/app/tools/send/send-access-text.component.ts +++ b/apps/web/src/app/tools/send/send-access-text.component.ts @@ -4,6 +4,7 @@ import { FormBuilder } from "@angular/forms"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { SendAccessView } from "@bitwarden/common/tools/send/models/view/send-access.view"; +import { ToastService } from "@bitwarden/components"; import { SharedModule } from "../../shared"; @@ -25,6 +26,7 @@ export class SendAccessTextComponent { private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private formBuilder: FormBuilder, + private toastService: ToastService, ) {} get send(): SendAccessView { @@ -46,11 +48,11 @@ export class SendAccessTextComponent { protected copyText() { this.platformUtilsService.copyToClipboard(this.send.text.text); - this.platformUtilsService.showToast( - "success", - null, - this.i18nService.t("valueCopied", this.i18nService.t("sendTypeText")), - ); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("valueCopied", this.i18nService.t("sendTypeText")), + }); } protected toggleText() { diff --git a/apps/web/src/app/tools/send/send.component.ts b/apps/web/src/app/tools/send/send.component.ts index 755435882a..56f7734ca1 100644 --- a/apps/web/src/app/tools/send/send.component.ts +++ b/apps/web/src/app/tools/send/send.component.ts @@ -12,7 +12,13 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService, NoItemsModule, SearchModule, TableDataSource } from "@bitwarden/components"; +import { + DialogService, + NoItemsModule, + SearchModule, + TableDataSource, + ToastService, +} from "@bitwarden/components"; import { HeaderModule } from "../../layouts/header/header.module"; import { SharedModule } from "../../shared"; @@ -56,6 +62,7 @@ export class SendComponent extends BaseSendComponent { logService: LogService, sendApiService: SendApiService, dialogService: DialogService, + toastService: ToastService, ) { super( sendService, @@ -68,6 +75,7 @@ export class SendComponent extends BaseSendComponent { logService, sendApiService, dialogService, + toastService, ); } diff --git a/apps/web/src/app/tools/vault-export/export.component.ts b/apps/web/src/app/tools/vault-export/export.component.ts index df53e599ed..8b5f82167d 100644 --- a/apps/web/src/app/tools/vault-export/export.component.ts +++ b/apps/web/src/app/tools/vault-export/export.component.ts @@ -7,8 +7,7 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { VaultExportServiceAbstraction } from "@bitwarden/vault-export-core"; import { ExportComponent as BaseExportComponent } from "@bitwarden/vault-export-ui"; @@ -19,7 +18,7 @@ import { ExportComponent as BaseExportComponent } from "@bitwarden/vault-export- export class ExportComponent extends BaseExportComponent { constructor( i18nService: I18nService, - platformUtilsService: PlatformUtilsService, + toastService: ToastService, exportService: VaultExportServiceAbstraction, eventCollectionService: EventCollectionService, policyService: PolicyService, @@ -31,7 +30,7 @@ export class ExportComponent extends BaseExportComponent { ) { super( i18nService, - platformUtilsService, + toastService, exportService, eventCollectionService, policyService, @@ -45,6 +44,10 @@ export class ExportComponent extends BaseExportComponent { protected saved() { super.saved(); - this.platformUtilsService.showToast("success", null, this.i18nService.t("exportSuccess")); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("exportSuccess"), + }); } } diff --git a/libs/angular/src/tools/generator/components/generator.component.ts b/libs/angular/src/tools/generator/components/generator.component.ts index b94d9bc6f0..1f7c931df3 100644 --- a/libs/angular/src/tools/generator/components/generator.component.ts +++ b/libs/angular/src/tools/generator/components/generator.component.ts @@ -19,6 +19,7 @@ import { UsernameGeneratorOptions, } from "@bitwarden/common/tools/generator/username"; import { EmailForwarderOptions } from "@bitwarden/common/tools/models/domain/email-forwarder-options"; +import { ToastService } from "@bitwarden/components"; @Directive() export class GeneratorComponent implements OnInit, OnDestroy { @@ -67,6 +68,7 @@ export class GeneratorComponent implements OnInit, OnDestroy { protected route: ActivatedRoute, protected ngZone: NgZone, private win: Window, + protected toastService: ToastService, ) { this.typeOptions = [ { name: i18nService.t("password"), value: "password" }, @@ -317,11 +319,14 @@ export class GeneratorComponent implements OnInit, OnDestroy { password ? this.password : this.username, copyOptions, ); - this.platformUtilsService.showToast( - "info", - null, - this.i18nService.t("valueCopied", this.i18nService.t(password ? "password" : "username")), - ); + this.toastService.showToast({ + variant: "info", + title: null, + message: this.i18nService.t( + "valueCopied", + this.i18nService.t(password ? "password" : "username"), + ), + }); } select() { diff --git a/libs/angular/src/tools/generator/components/password-generator-history.component.ts b/libs/angular/src/tools/generator/components/password-generator-history.component.ts index 9ad0c0cbdb..f0438a9a5a 100644 --- a/libs/angular/src/tools/generator/components/password-generator-history.component.ts +++ b/libs/angular/src/tools/generator/components/password-generator-history.component.ts @@ -6,6 +6,7 @@ import { GeneratedPasswordHistory, PasswordGenerationServiceAbstraction, } from "@bitwarden/common/tools/generator/password"; +import { ToastService } from "@bitwarden/components"; @Directive() export class PasswordGeneratorHistoryComponent implements OnInit { @@ -16,6 +17,7 @@ export class PasswordGeneratorHistoryComponent implements OnInit { protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, private win: Window, + protected toastService: ToastService, ) {} async ngOnInit() { @@ -29,10 +31,10 @@ export class PasswordGeneratorHistoryComponent implements OnInit { copy(password: string) { const copyOptions = this.win != null ? { window: this.win } : null; this.platformUtilsService.copyToClipboard(password, copyOptions); - this.platformUtilsService.showToast( - "info", - null, - this.i18nService.t("valueCopied", this.i18nService.t("password")), - ); + this.toastService.showToast({ + variant: "info", + title: null, + message: this.i18nService.t("valueCopied", this.i18nService.t("password")), + }); } } diff --git a/libs/angular/src/tools/send/add-edit.component.ts b/libs/angular/src/tools/send/add-edit.component.ts index b4f7ec171a..a398ed1969 100644 --- a/libs/angular/src/tools/send/add-edit.component.ts +++ b/libs/angular/src/tools/send/add-edit.component.ts @@ -22,7 +22,7 @@ import { SendTextView } from "@bitwarden/common/tools/send/models/view/send-text import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; // Value = hours enum DatePreset { @@ -120,6 +120,7 @@ export class AddEditComponent implements OnInit, OnDestroy { protected formBuilder: FormBuilder, protected billingAccountProfileStateService: BillingAccountProfileStateService, protected accountService: AccountService, + protected toastService: ToastService, ) { this.typeOptions = [ { name: i18nService.t("sendTypeFile"), value: SendType.File, premium: true }, @@ -269,11 +270,11 @@ export class AddEditComponent implements OnInit, OnDestroy { this.formGroup.markAllAsTouched(); if (this.disableSend) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("sendDisabledWarning"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("sendDisabledWarning"), + }); return false; } @@ -289,11 +290,11 @@ export class AddEditComponent implements OnInit, OnDestroy { this.send.type = this.type; if (Utils.isNullOrWhitespace(this.send.name)) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("nameRequired"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("nameRequired"), + }); return false; } @@ -302,22 +303,22 @@ export class AddEditComponent implements OnInit, OnDestroy { const fileEl = document.getElementById("file") as HTMLInputElement; const files = fileEl.files; if (files == null || files.length === 0) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("selectFile"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("selectFile"), + }); return; } file = files[0]; if (files[0].size > 524288000) { // 500 MB - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("maxFileSize"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("maxFileSize"), + }); return; } } @@ -340,11 +341,11 @@ export class AddEditComponent implements OnInit, OnDestroy { await this.handleCopyLinkToClipboard(); return; } - this.platformUtilsService.showToast( - "success", - null, - this.i18nService.t(this.editMode ? "editedSend" : "createdSend"), - ); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t(this.editMode ? "editedSend" : "createdSend"), + }); }); try { await this.formPromise; @@ -377,7 +378,11 @@ export class AddEditComponent implements OnInit, OnDestroy { try { this.deletePromise = this.sendApiService.delete(this.send.id); await this.deletePromise; - this.platformUtilsService.showToast("success", null, this.i18nService.t("deletedSend")); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("deletedSend"), + }); await this.load(); this.onDeletedSend.emit(this.send); return true; @@ -470,11 +475,11 @@ export class AddEditComponent implements OnInit, OnDestroy { private async handleCopyLinkToClipboard() { const copySuccess = await this.copyLinkToClipboard(this.link); if (copySuccess ?? true) { - this.platformUtilsService.showToast( - "success", - null, - this.i18nService.t(this.editMode ? "editedSend" : "createdSend"), - ); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t(this.editMode ? "editedSend" : "createdSend"), + }); } else { await this.dialogService.openSimpleDialog({ title: "", diff --git a/libs/angular/src/tools/send/send.component.ts b/libs/angular/src/tools/send/send.component.ts index fc51e32416..f331a320cd 100644 --- a/libs/angular/src/tools/send/send.component.ts +++ b/libs/angular/src/tools/send/send.component.ts @@ -20,7 +20,7 @@ import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; -import { DialogService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; @Directive() export class SendComponent implements OnInit, OnDestroy { @@ -76,6 +76,7 @@ export class SendComponent implements OnInit, OnDestroy { private logService: LogService, protected sendApiService: SendApiService, protected dialogService: DialogService, + protected toastService: ToastService, ) {} async ngOnInit() { @@ -186,7 +187,11 @@ export class SendComponent implements OnInit, OnDestroy { this.onSuccessfulRemovePassword(); } else { // Default actions - this.platformUtilsService.showToast("success", null, this.i18nService.t("removedPassword")); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("removedPassword"), + }); await this.load(); } } catch (e) { @@ -220,7 +225,11 @@ export class SendComponent implements OnInit, OnDestroy { this.onSuccessfulDelete(); } else { // Default actions - this.platformUtilsService.showToast("success", null, this.i18nService.t("deletedSend")); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("deletedSend"), + }); await this.refresh(); } } catch (e) { @@ -234,11 +243,11 @@ export class SendComponent implements OnInit, OnDestroy { const env = await firstValueFrom(this.environmentService.environment$); const link = env.getSendUrl() + s.accessId + "/" + s.urlB64Key; this.platformUtilsService.copyToClipboard(link); - this.platformUtilsService.showToast( - "success", - null, - this.i18nService.t("valueCopied", this.i18nService.t("sendLink")), - ); + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("valueCopied", this.i18nService.t("sendLink")), + }); } searchTextChanged() { diff --git a/libs/importer/src/components/import.component.ts b/libs/importer/src/components/import.component.ts index 7ae1e5c176..8f3566831d 100644 --- a/libs/importer/src/components/import.component.ts +++ b/libs/importer/src/components/import.component.ts @@ -48,6 +48,7 @@ import { IconButtonModule, RadioButtonModule, SelectModule, + ToastService, } from "@bitwarden/components"; import { ImportOption, ImportResult, ImportType } from "../models"; @@ -191,6 +192,7 @@ export class ImportComponent implements OnInit, OnDestroy { @Inject(ImportCollectionServiceAbstraction) @Optional() protected importCollectionService: ImportCollectionServiceAbstraction, + protected toastService: ToastService, ) {} protected get importBlockedByPolicy(): boolean { @@ -336,22 +338,22 @@ export class ImportComponent implements OnInit, OnDestroy { ); if (importer === null) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("selectFormat"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("selectFormat"), + }); return; } const importContents = await this.setImportContents(); if (importContents == null || importContents === "") { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("selectFile"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("selectFile"), + }); return; } @@ -502,11 +504,11 @@ export class ImportComponent implements OnInit, OnDestroy { } if (this.importBlockedByPolicy && this.organizationId == null) { - this.platformUtilsService.showToast( - "error", - null, - this.i18nService.t("personalOwnershipPolicyInEffectImports"), - ); + this.toastService.showToast({ + variant: "error", + title: null, + message: this.i18nService.t("personalOwnershipPolicyInEffectImports"), + }); return false; } @@ -517,14 +519,6 @@ export class ImportComponent implements OnInit, OnDestroy { const fileEl = document.getElementById("import_input_file") as HTMLInputElement; const files = fileEl.files; let fileContents = this.formGroup.controls.fileContents.value; - if ((files == null || files.length === 0) && (fileContents == null || fileContents === "")) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("selectFile"), - ); - return; - } if (files != null && files.length > 0) { try { diff --git a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts index 0d0ec92eac..9f81f5e550 100644 --- a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts +++ b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts @@ -15,7 +15,6 @@ import { EventType } from "@bitwarden/common/enums"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { EncryptedExportType } from "@bitwarden/common/tools/enums/encrypted-export-type.enum"; import { @@ -28,6 +27,7 @@ import { IconButtonModule, RadioButtonModule, SelectModule, + ToastService, } from "@bitwarden/components"; import { VaultExportServiceAbstraction } from "@bitwarden/vault-export-core"; @@ -123,7 +123,7 @@ export class ExportComponent implements OnInit, OnDestroy { constructor( protected i18nService: I18nService, - protected platformUtilsService: PlatformUtilsService, + protected toastService: ToastService, protected exportService: VaultExportServiceAbstraction, protected eventCollectionService: EventCollectionService, private policyService: PolicyService, @@ -222,11 +222,11 @@ export class ExportComponent implements OnInit, OnDestroy { submit = async () => { if (this.isFileEncryptedExport && this.filePassword != this.confirmFilePassword) { - this.platformUtilsService.showToast( - "error", - this.i18nService.t("errorOccurred"), - this.i18nService.t("filePasswordAndConfirmFilePasswordDoNotMatch"), - ); + this.toastService.showToast({ + variant: "error", + title: this.i18nService.t("errorOccurred"), + message: this.i18nService.t("filePasswordAndConfirmFilePasswordDoNotMatch"), + }); return; } @@ -236,11 +236,11 @@ export class ExportComponent implements OnInit, OnDestroy { } if (this.disabledByPolicy) { - this.platformUtilsService.showToast( - "error", - null, - this.i18nService.t("personalVaultExportPolicyInEffect"), - ); + this.toastService.showToast({ + variant: "error", + title: null, + message: this.i18nService.t("personalVaultExportPolicyInEffect"), + }); return; }