1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-01 08:03:20 +00:00
Files
browser/apps/web/src/app/vault/individual-vault/folder-add-edit.component.ts
Patrick-Pimentel-Bitwarden 0b0397c3f0 fix(enums-eslint): Enum Rule for ESLint (#14650)
* fix(enums-eslint): Enum Rule for ESLint - Added enums in the warnings for eslint.

* fix(enums-eslint): Enum Rule for ESLint - Updated to error in both places for enums.

* fix(enums-eslint): Enum Rule for ESLint - Added new eslint plugin for warning on enums.

* fix(enums-eslint): Enum Rule for ESLint - Changed based on suggestion.

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>

* refactor(browser-platform-utils): Remove Deprecation and Fix Code - Changed usages of firefox to private and moved the usages to the preferred public method and removed the deprecations.

* fix(enums-eslint): Enum Rule for ESLint - Updated to error and added disable rules for all other places.

* fix(enums-eslint): Enum Rule for ESLint - Undid other changes by accident
2025-05-13 10:07:38 -04:00

138 lines
4.6 KiB
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component, Inject } from "@angular/core";
import { FormBuilder } from "@angular/forms";
import { firstValueFrom } from "rxjs";
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.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 { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
import {
DIALOG_DATA,
DialogConfig,
DialogRef,
DialogService,
ToastService,
} from "@bitwarden/components";
import { KeyService } from "@bitwarden/key-management";
@Component({
selector: "app-folder-add-edit",
templateUrl: "folder-add-edit.component.html",
})
export class FolderAddEditComponent extends BaseFolderAddEditComponent {
protected override componentName = "app-folder-add-edit";
constructor(
folderService: FolderService,
folderApiService: FolderApiServiceAbstraction,
protected accountSerivce: AccountService,
protected keyService: KeyService,
i18nService: I18nService,
platformUtilsService: PlatformUtilsService,
logService: LogService,
dialogService: DialogService,
formBuilder: FormBuilder,
protected toastService: ToastService,
protected dialogRef: DialogRef<FolderAddEditDialogResult>,
@Inject(DIALOG_DATA) params: FolderAddEditDialogParams,
) {
super(
folderService,
folderApiService,
accountSerivce,
keyService,
i18nService,
platformUtilsService,
logService,
dialogService,
formBuilder,
toastService,
);
// FIXME: Remove when updating file. Eslint update
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
params?.folderId ? (this.folderId = params.folderId) : null;
}
deleteAndClose = async () => {
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "deleteFolder" },
content: { key: "deleteFolderConfirmation" },
type: "warning",
});
if (!confirmed) {
return;
}
try {
await this.folderApiService.delete(this.folder.id, await firstValueFrom(this.activeUserId$));
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("deletedFolder"),
});
} catch (e) {
this.logService.error(e);
}
this.dialogRef.close(FolderAddEditDialogResult.Deleted);
};
submitAndClose = async () => {
this.folder.name = this.formGroup.controls.name.value;
if (this.folder.name == null || this.folder.name === "") {
this.formGroup.controls.name.markAsTouched();
return;
}
try {
const activeAccountId = await firstValueFrom(this.activeUserId$);
const userKey = await this.keyService.getUserKeyWithLegacySupport(activeAccountId);
const folder = await this.folderService.encrypt(this.folder, userKey);
this.formPromise = this.folderApiService.save(folder, activeAccountId);
await this.formPromise;
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(this.editMode ? "editedFolder" : "addedFolder"),
});
this.onSavedFolder.emit(this.folder);
this.dialogRef.close(FolderAddEditDialogResult.Saved);
} catch (e) {
this.logService.error(e);
}
return;
};
}
export interface FolderAddEditDialogParams {
folderId: string;
}
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum FolderAddEditDialogResult {
Deleted = "deleted",
Canceled = "canceled",
Saved = "saved",
}
/**
* Strongly typed helper to open a FolderAddEdit dialog
* @param dialogService Instance of the dialog service that will be used to open the dialog
* @param config Optional configuration for the dialog
*/
export function openFolderAddEditDialog(
dialogService: DialogService,
config?: DialogConfig<FolderAddEditDialogParams>,
) {
return dialogService.open<FolderAddEditDialogResult, FolderAddEditDialogParams>(
FolderAddEditComponent,
config,
);
}