diff options
4 files changed, 30 insertions, 13 deletions
diff --git a/packages/exchange-backoffice-ui/src/NiceForm.tsx b/packages/exchange-backoffice-ui/src/NiceForm.tsx index 69b977ee0..4fc0ea89f 100644 --- a/packages/exchange-backoffice-ui/src/NiceForm.tsx +++ b/packages/exchange-backoffice-ui/src/NiceForm.tsx @@ -13,7 +13,7 @@ export function NiceForm<T extends object>({ }: { children?: ComponentChildren; initial: Partial<T>; - onSubmit?: (v: T) => void; + onSubmit?: (v: Partial<T>) => void; form: FlexibleForm<T>; onUpdate?: (d: Partial<T>) => void; }) { diff --git a/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx b/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx index 4ac90ad57..a195c2051 100644 --- a/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx +++ b/packages/exchange-backoffice-ui/src/handlers/FormProvider.tsx @@ -58,8 +58,8 @@ export function FormProvider<T>({ }: { initialValue?: Partial<T>; onUpdate?: (v: Partial<T>) => void; - onSubmit?: (v: T) => void; - computeFormState?: (v: T) => FormState<T>; + onSubmit?: (v: Partial<T>, s: FormState<T> | undefined) => void; + computeFormState?: (v: Partial<T>) => FormState<T>; children: ComponentChildren; }): VNode { // const value = useRef(initialValue ?? {}); @@ -85,7 +85,11 @@ export function FormProvider<T>({ onSubmit={(e) => { e.preventDefault(); //@ts-ignore - if (onSubmit) onSubmit(value.current); + if (onSubmit) + onSubmit( + value.current, + !computeFormState ? undefined : computeFormState(value.current), + ); }} > {children} diff --git a/packages/exchange-backoffice-ui/src/pages/CreateAccount.tsx b/packages/exchange-backoffice-ui/src/pages/CreateAccount.tsx index 41a1d20ff..5dcb8b21d 100644 --- a/packages/exchange-backoffice-ui/src/pages/CreateAccount.tsx +++ b/packages/exchange-backoffice-ui/src/pages/CreateAccount.tsx @@ -1,5 +1,8 @@ import { TranslatedString } from "@gnu-taler/taler-util"; -import { useTranslationContext } from "@gnu-taler/web-util/browser"; +import { + notifyError, + useTranslationContext, +} from "@gnu-taler/web-util/browser"; import { VNode, h } from "preact"; import { createNewForm } from "../handlers/forms.js"; @@ -41,16 +44,26 @@ export function CreateAccount({ : undefined, }, repeat: { - // error: !v.repeat - // ? i18n.str`required` - // // : v.repeat !== v.password - // // ? i18n.str`doesn't match` - // : undefined, + error: !v.repeat + ? i18n.str`required` + : v.repeat !== v.password + ? i18n.str`doesn't match` + : undefined, }, }; }} - onSubmit={async (v) => { - onNewAccount(v.password); + onSubmit={async (v, s) => { + console.log(v, s); + const error = s?.password?.error ?? s?.repeat?.error; + console.log(error); + if (error) { + notifyError( + "Can't create account" as TranslatedString, + error as TranslatedString, + ); + } else { + onNewAccount(v.password!); + } }} > <div class="mb-4"> diff --git a/packages/exchange-backoffice-ui/src/pages/UnlockAccount.tsx b/packages/exchange-backoffice-ui/src/pages/UnlockAccount.tsx index 74cb0d056..2ebac0718 100644 --- a/packages/exchange-backoffice-ui/src/pages/UnlockAccount.tsx +++ b/packages/exchange-backoffice-ui/src/pages/UnlockAccount.tsx @@ -32,7 +32,7 @@ export function UnlockAccount({ <Form.Provider onSubmit={async (v) => { try { - await onAccountUnlocked(v.password); + await onAccountUnlocked(v.password!); notifyInfo("Account unlocked" as TranslatedString); } catch (e) { |