1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00
Files
browser/libs/tools/send/send-ui/src/send-form/send-form-container.ts
Jordan Aasen c4d66a1383 [PM-11904] - send options form (#11142)
* send options form

* remove commented code

* fix margin. update i18 key

* remove unecessary input

* remove unnecessary typing. DRY up messages
2024-09-19 20:53:25 +02:00

48 lines
2.0 KiB
TypeScript

import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { SendFormConfig } from "./abstractions/send-form-config.service";
import { SendOptionsComponent } from "./components/options/send-options.component";
import { SendDetailsComponent } from "./components/send-details/send-details.component";
import { SendFileDetailsComponent } from "./components/send-details/send-file-details.component";
import { SendTextDetailsComponent } from "./components/send-details/send-text-details.component";
/**
* The complete form for a send. Includes all the sub-forms from their respective section components.
* TODO: Add additional form sections as they are implemented.
*/
export type SendForm = {
sendDetailsForm?: SendDetailsComponent["sendDetailsForm"];
sendTextDetailsForm?: SendTextDetailsComponent["sendTextDetailsForm"];
sendFileDetailsForm?: SendFileDetailsComponent["sendFileDetailsForm"];
sendOptionsForm?: SendOptionsComponent["sendOptionsForm"];
};
/**
* A container for the {@link SendForm} that allows for registration of child form groups and patching of the send
* to be updated/created. Child form components inject this container in order to register themselves with the parent form
* and access configuration options.
*
* This is an alternative to passing the form groups down through the component tree via @Inputs() and form updates via
* @Outputs(). It allows child forms to define their own structure and validation rules, while still being able to
* update the parent send.
*/
export abstract class SendFormContainer {
/**
* The configuration for the send form.
*/
readonly config: SendFormConfig;
/**
* The original send that is being edited/cloned. Used to pre-populate the form and compare changes.
*/
readonly originalSendView: SendView | null;
abstract registerChildForm<K extends keyof SendForm>(
name: K,
group: Exclude<SendForm[K], undefined>,
): void;
abstract onFileSelected(file: File): void;
abstract patchSend(updateFn: (current: SendView) => SendView): void;
}