1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[PM-9869] Create SendFormContainer (#10147)

* Move SendV2component into send-v2 subFolder

* Create SendFormContainer and related services

* Add initial SendFormComponent which uses the SendFormContainer

* Remove AdditionalOptionsSectionComponent which will be added with a future PR

* Add libs/tools/send to root tsconfig

* Register libs/tools/send/send-ui with root jest.config.js

* Register libs/tools/send/send-ui with root tailwind.config.js

* Fix service injection on DefaultSendFormService

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith
2024-07-19 21:17:52 +02:00
committed by GitHub
parent beeb0354fd
commit 1320d96cb4
20 changed files with 630 additions and 1 deletions

View File

@@ -0,0 +1,93 @@
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { Send } from "@bitwarden/common/tools/send/models/domain/send";
import { SendId } from "@bitwarden/common/types/guid";
/**
* The mode of the add/edit form.
* - `add` - The form is creating a new send.
* - `edit` - The form is editing an existing send.
* - `partial-edit` - The form is editing an existing send, but only the favorite/folder fields
*/
export type SendFormMode = "add" | "edit" | "partial-edit";
/**
* Base configuration object for the send form. Includes all common fields.
*/
type BaseSendFormConfig = {
/**
* The mode of the form.
*/
mode: SendFormMode;
/**
* The type of send to create/edit.
*/
sendType: SendType;
/**
* Flag to indicate if the user is allowed to create sends. If false, configuration must
* supply a list of organizations that the user can create sends in.
*/
areSendsAllowed: boolean;
/**
* The original send that is being edited or cloned. This can be undefined when creating a new send.
*/
originalSend?: Send;
};
/**
* Configuration object for the send form when editing an existing send.
*/
type ExistingSendConfig = BaseSendFormConfig & {
mode: "edit" | "partial-edit";
originalSend: Send;
};
/**
* Configuration object for the send form when creating a completely new send.
*/
type CreateNewSendConfig = BaseSendFormConfig & {
mode: "add";
};
type CombinedAddEditConfig = ExistingSendConfig | CreateNewSendConfig;
/**
* Configuration object for the send form when personal ownership is allowed.
*/
type SendsAllowed = CombinedAddEditConfig & {
areSendsAllowed: true;
};
/**
* Configuration object for the send form when Sends are not allowed by an organization.
* Organizations must be provided.
*/
type SendsNotAllowed = CombinedAddEditConfig & {
areSendsAllowed: false;
};
/**
* Configuration object for the send form.
* Determines the behavior of the form and the controls that are displayed/enabled.
*/
export type SendFormConfig = SendsAllowed | SendsNotAllowed;
/**
* Service responsible for building the configuration object for the send form.
*/
export abstract class SendFormConfigService {
/**
* Builds the configuration for the send form using the specified mode, sendId, and sendType.
* The other configuration fields will be fetched from their respective services.
* @param mode
* @param sendId
* @param sendType
*/
abstract buildConfig(
mode: SendFormMode,
sendId?: SendId,
sendType?: SendType,
): Promise<SendFormConfig>;
}

View File

@@ -0,0 +1,26 @@
import { Send } from "@bitwarden/common/tools/send/models/domain/send";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendFormConfig } from "./send-form-config.service";
/**
* Service to save the send using the correct endpoint(s) and encapsulating the logic for decrypting the send.
*
* This service should only be used internally by the SendFormComponent.
*/
export abstract class SendFormService {
/**
* Helper to decrypt a send and avoid the need to call the send service directly.
* (useful for mocking tests/storybook).
*/
abstract decryptSend(send: Send): Promise<SendView>;
/**
* Saves the new or modified send with the server.
*/
abstract saveSend(
send: SendView,
file: File | ArrayBuffer,
config: SendFormConfig,
): Promise<SendView>;
}