-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormBuilder.tsx
38 lines (35 loc) · 1.03 KB
/
FormBuilder.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import { Form } from '../../../../shared/components/Form';
import { FormField } from './FormField';
import { IFormBuilderProps } from './FormBuilder.types';
const defaultAction = 'https://httpbin.org/post';
const defaultMethod = 'post';
export const FormBuilder = React.memo((props: IFormBuilderProps): React.ReactElement => {
const { schema, className } = props;
const { title, items, actions } = schema;
const buttons = actions?.map((action) => ({
type: action.type,
children: action.text,
}));
return (
<Form
testId="FormBuilder"
action={defaultAction}
method={defaultMethod}
title={title}
actions={buttons}
className={className}
>
{items.length > 0 && (
items.map((item, index) => (
<FormField
// we have no control over the uniqueness of any input property
// eslint-disable-next-line react/no-array-index-key
key={index}
schema={item}
/>
))
)}
</Form>
);
});