From 98013322db6b912ac50d72353dbd8b5f7fbc0435 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 6 Oct 2023 10:38:09 -0300 Subject: backoffice ui --- .../src/components/form/InputWithAddon.tsx | 3 +- .../src/components/form/JumpToElementById.tsx | 59 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 packages/merchant-backoffice-ui/src/components/form/JumpToElementById.tsx (limited to 'packages/merchant-backoffice-ui/src/components/form') diff --git a/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx b/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx index 34feec202..d7b490a5d 100644 --- a/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx @@ -107,8 +107,9 @@ export function InputWithAddon({ {error &&

{error}

} {help} - {side} + {expand ?
{side}
: side} + ); } diff --git a/packages/merchant-backoffice-ui/src/components/form/JumpToElementById.tsx b/packages/merchant-backoffice-ui/src/components/form/JumpToElementById.tsx new file mode 100644 index 000000000..2ff23dfd3 --- /dev/null +++ b/packages/merchant-backoffice-ui/src/components/form/JumpToElementById.tsx @@ -0,0 +1,59 @@ +import { TranslatedString } from "@gnu-taler/taler-util"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; +import { h, VNode } from "preact"; +import { useState } from "preact/hooks"; + +export function JumpToElementById({ testIfExist, onSelect, palceholder, description }: { palceholder: TranslatedString, description: TranslatedString, testIfExist: (id: string) => Promise, onSelect: (id: string) => void }): VNode { + const { i18n } = useTranslationContext() + + const [error, setError] = useState( + undefined, + ); + + const [id, setId] = useState() + async function check(currentId: string | undefined): Promise { + if (!currentId) { + setError(i18n.str`missing id`); + return; + } + try { + await testIfExist(currentId); + onSelect(currentId); + setError(undefined); + } catch { + setError(i18n.str`not found`); + } + } + + return
+
+
+
+
+ setId(e.currentTarget.value)} + placeholder={palceholder} + /> + {error &&

{error}

} +
+ + + +
+
+
+
+} -- cgit v1.2.3