forked from rabin-nyaundi/React-Json-Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.jsx
119 lines (116 loc) · 3.61 KB
/
test.jsx
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const renderFormField = (field) => {
const { name, type, label, options } = field;
console.log("====================================");
console.log(options);
console.log("====================================");
switch (type) {
case "text":
case "email":
case "password":
case "textarea":
return (
<div class="flex flex-col w-full mb-6" key={name}>
<label htmlFor={name}>{label}</label>
<input
class="shadow appearance-none border border-red-gray-500 rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline"
type={type}
name={name}
id={name}
/>
</div>
);
case "select":
return (
<div class="flex flex-col w-full mb-6" key={name}>
<label htmlFor={name}>{label}</label>
<select
className="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
name={name}
id={name}
>
{options?.map((option) => (
<option value={option.value} key={option.value}>
{option.label}
</option>
))}
</select>
</div>
);
case "checkbox":
return (
<div className="form-group" key={name}>
<label>{label}</label>
{options?.map((option) => (
<div className="form-check" key={option.value}>
<input
className="form-check-input"
type="checkbox"
name={name}
id={`${name}-${option.value}`}
value={option.value}
/>
<label
className="form-check-label"
htmlFor={`${name}-${option.value}`}
>
{option.label}
</label>
</div>
))}
</div>
);
case "radio":
return (
<div className="form-group" key={name}>
<label>{label}</label>
{options?.map((option) => (
<div className="form-check" key={option.value}>
<input
className="form-check-input"
type="radio"
name={name}
id={`${name}-${option.value}`}
value={option.value}
/>
<label
className="form-check-label"
htmlFor={`${name}-${option.value}`}
>
{option.label}
</label>
</div>
))}
</div>
);
case "file":
return (
<div class="flex flex-col w-full mb-6 bg-yellow-600 " key={name}>
<label
class="block text-gray-700 text-sm font-bold mb-2"
htmlFor={name}
>
Password
</label>
<input
ype={type}
name={name}
id={name}
class="shadow appearance-none border border-gray-500 rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline"
/>
<p class="text-red-500 text-xs italic">Please choose a password.</p>
</div>
);
default:
return null;
}
};
// const fetchForms = async () => {
// setLoading(true);
// let formData = await axios.get("/api/forms");
// let sc = await formData?.data?.schema;
// let uisch = await formData?.data?.uischema;
// setSchema(sc);
// setUISchema(uisch);
// setLoading(false);
// };
// fetchForms();