From 0544b8358af68df87dbc472221d8c0842c2b2db0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 19 May 2023 13:26:47 -0300 Subject: accounts and notifications --- .../exchange-backoffice-ui/src/handlers/FormProvider.tsx | 12 +++++++++++- packages/exchange-backoffice-ui/src/handlers/InputLine.tsx | 8 ++++++-- packages/exchange-backoffice-ui/src/handlers/InputText.tsx | 2 +- packages/exchange-backoffice-ui/src/handlers/forms.ts | 13 +++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) (limited to 'packages/exchange-backoffice-ui/src/handlers') diff --git a/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx b/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx index d8877333c..87c4c43fb 100644 --- a/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx +++ b/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx @@ -41,10 +41,12 @@ export function FormProvider({ children, initialValue, onUpdate, + onSubmit, computeFormState, }: { initialValue?: Partial; onUpdate?: (v: Partial) => void; + onSubmit: (v: T) => void; computeFormState?: (v: T) => FormState; children: ComponentChildren; }): VNode { @@ -58,7 +60,15 @@ export function FormProvider({ -
{children}
+
{ + e.preventDefault(); + //@ts-ignore + onSubmit(value.current); + }} + > + {children} +
); } diff --git a/packages/exchange-backoffice-ui/src/handlers/InputLine.tsx b/packages/exchange-backoffice-ui/src/handlers/InputLine.tsx index 255654949..32b16313d 100644 --- a/packages/exchange-backoffice-ui/src/handlers/InputLine.tsx +++ b/packages/exchange-backoffice-ui/src/handlers/InputLine.tsx @@ -23,7 +23,7 @@ interface StringConverter { } export interface UIFormProps { - name: string; + name: keyof T; label: TranslatedString; placeholder?: TranslatedString; tooltip?: TranslatedString; @@ -181,7 +181,11 @@ function defaultFromString(v: string) { return v; } -export function InputLine(props: { type: string } & UIFormProps): VNode { +type InputType = "text" | "text-area" | "password" | "email"; + +export function InputLine( + props: { type: InputType } & UIFormProps, +): VNode { const { name, placeholder, before, after, converter, type } = props; const { value, onChange, state, isDirty } = useField(name); diff --git a/packages/exchange-backoffice-ui/src/handlers/InputText.tsx b/packages/exchange-backoffice-ui/src/handlers/InputText.tsx index 107d87860..014730d92 100644 --- a/packages/exchange-backoffice-ui/src/handlers/InputText.tsx +++ b/packages/exchange-backoffice-ui/src/handlers/InputText.tsx @@ -1,6 +1,6 @@ import { VNode, h } from "preact"; import { InputLine, UIFormProps } from "./InputLine.js"; -export function InputText(props: UIFormProps): VNode { +export function InputText(props: UIFormProps): VNode { return ; } diff --git a/packages/exchange-backoffice-ui/src/handlers/forms.ts b/packages/exchange-backoffice-ui/src/handlers/forms.ts index 1d6a7daa4..a97b8561d 100644 --- a/packages/exchange-backoffice-ui/src/handlers/forms.ts +++ b/packages/exchange-backoffice-ui/src/handlers/forms.ts @@ -11,6 +11,8 @@ import { InputFile } from "./InputFile.js"; import { Caption } from "./Caption.js"; import { Group } from "./Group.js"; import { InputSelectOne } from "./InputSelectOne.js"; +import { FormProvider } from "./FormProvider.js"; +import { InputLine } from "./InputLine.js"; export type DoubleColumnForm = DoubleColumnFormSection[]; @@ -94,3 +96,14 @@ export function RenderAllFieldsByUiConfig({ }), ); } + +type FormSet = { + Provider: typeof FormProvider; + InputLine: typeof InputLine; +}; +export function createNewForm(): FormSet { + return { + Provider: FormProvider, + InputLine: InputLine, + }; +} -- cgit v1.2.3