summaryrefslogtreecommitdiff
path: root/packages/exchange-backoffice-ui/src/handlers/InputArray.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/exchange-backoffice-ui/src/handlers/InputArray.tsx')
-rw-r--r--packages/exchange-backoffice-ui/src/handlers/InputArray.tsx22
1 files changed, 13 insertions, 9 deletions
diff --git a/packages/exchange-backoffice-ui/src/handlers/InputArray.tsx b/packages/exchange-backoffice-ui/src/handlers/InputArray.tsx
index c09806e58..00379bed6 100644
--- a/packages/exchange-backoffice-ui/src/handlers/InputArray.tsx
+++ b/packages/exchange-backoffice-ui/src/handlers/InputArray.tsx
@@ -71,17 +71,15 @@ function Option({
);
}
-export function InputArray(
+export function InputArray<T extends object, K extends keyof T>(
props: {
fields: UIFormField[];
labelField: string;
- } & UIFormProps<Array<{}>>,
+ } & UIFormProps<T, K>,
): VNode {
const { fields, labelField, name, label, required, tooltip } = props;
- const { value, onChange, state } = useField<{ [s: string]: Array<any> }>(
- name,
- );
- const list = value ?? [];
+ const { value, onChange, state } = useField<T, K>(name);
+ const list = (value ?? []) as Array<Record<string, string | undefined>>;
const [selectedIndex, setSelected] = useState<number | undefined>(undefined);
const selected =
selectedIndex === undefined ? undefined : list[selectedIndex];
@@ -98,7 +96,7 @@ export function InputArray(
{list.map((v, idx) => {
return (
<Option
- label={v[labelField]}
+ label={v[labelField] as TranslatedString}
isSelected={selectedIndex === idx}
isLast={idx === list.length - 1}
disabled={selectedIndex !== undefined && selectedIndex !== idx}
@@ -141,10 +139,16 @@ export function InputArray(
//@ts-ignore
return state.elements[selectedIndex];
}}
+ onSubmit={(v) => {
+ const newValue = [...list];
+ newValue.splice(selectedIndex, 1, v);
+ onChange(newValue as T[K]);
+ setSelected(undefined);
+ }}
onUpdate={(v) => {
const newValue = [...list];
newValue.splice(selectedIndex, 1, v);
- onChange(newValue);
+ onChange(newValue as T[K]);
}}
>
<div class="px-4 py-6">
@@ -163,7 +167,7 @@ export function InputArray(
onClick={() => {
const newValue = [...list];
newValue.splice(selectedIndex, 1);
- onChange(newValue);
+ onChange(newValue as T[K]);
setSelected(undefined);
}}
class="block rounded-md bg-red-600 px-3 py-2 text-center text-sm text-white shadow-sm hover:bg-red-500 "