ui-soxo-bootstrap-core 2.6.1-dev.26 → 2.6.1-dev.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/lib/models/forms/components/form-creator/form-creator.js +525 -468
- package/core/lib/models/forms/components/form-creator/form-creator.scss +29 -26
- package/core/lib/modules/generic/generic-list/ExportReactCSV.js +28 -2
- package/core/lib/utils/generic/generic.utils.js +2 -1
- package/core/modules/reporting/components/reporting-dashboard/adavance-search/advance-search.js +70 -43
- package/core/modules/reporting/components/reporting-dashboard/adavance-search/advance-search.scss +2 -2
- package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.js +134 -250
- package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.scss +36 -0
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
*
|
|
3
3
|
* @author Ashique Mohammed
|
|
4
4
|
* @description Generic Form create accepts an array of fields to update any resource
|
|
5
5
|
* @version
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
// let forms = [{
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
// tabs: [{}]
|
|
14
14
|
// }]
|
|
15
15
|
|
|
16
|
-
import React, { useState } from
|
|
16
|
+
import React, { useState } from "react"
|
|
17
17
|
|
|
18
18
|
import moment from 'moment';
|
|
19
19
|
|
|
20
|
-
import Button from
|
|
20
|
+
import Button from "../../../../../lib/elements/basic/button/button";
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import { Form, Input, Radio, InputNumber, DatePicker, TimePicker, Checkbox, Select, Row, Col, Tabs } from 'antd';
|
|
23
23
|
|
|
24
24
|
// import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
|
|
25
25
|
|
|
@@ -29,12 +29,14 @@ import Camera from './../../../../components/camera/camera';
|
|
|
29
29
|
|
|
30
30
|
// import { ColumnHeightOutlined } from '@ant-design/icons';
|
|
31
31
|
|
|
32
|
-
import { DateUtils } from
|
|
32
|
+
import { DateUtils } from "../../../../utils";
|
|
33
33
|
|
|
34
|
-
import { FieldCustomizer, TabCustomizer
|
|
34
|
+
import { FieldCustomizer, TabCustomizer } from "./../../../../";
|
|
35
35
|
|
|
36
36
|
import { prepareAndExecuteScript } from './../../../../utils/script.utils';
|
|
37
37
|
|
|
38
|
+
import AdvancedSearchSelect from "../../../../../modules/reporting/components/reporting-dashboard/adavance-search/advance-search";
|
|
39
|
+
|
|
38
40
|
const { TextArea } = Input;
|
|
39
41
|
|
|
40
42
|
const { Option } = Select;
|
|
@@ -43,148 +45,168 @@ const { TabPane } = Tabs;
|
|
|
43
45
|
|
|
44
46
|
// const grid = 4;
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
|
|
49
|
+
import './form-creator.scss'
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
* Component accepts fields to render the necessary components and returns the values on submission
|
|
50
|
-
*
|
|
51
|
-
* @param {*} param0
|
|
52
|
-
* @returns
|
|
53
|
+
*
|
|
54
|
+
* @param {*} param0
|
|
55
|
+
* @returns
|
|
53
56
|
*/
|
|
54
57
|
function FormCreator({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
/**If we want to change the existing information first we need the current information ie, selectedInformation*/
|
|
59
|
+
selectedInformation,
|
|
60
|
+
model,
|
|
61
|
+
formContent = {},
|
|
62
|
+
onSubmit,
|
|
63
|
+
fields = [],
|
|
64
|
+
reportId,
|
|
65
|
+
callback,
|
|
66
|
+
layout,
|
|
67
|
+
onFormValuesChange,
|
|
68
|
+
// Below are arguments for use in form display
|
|
69
|
+
onFieldUpdate,
|
|
70
|
+
// onListUpdate,
|
|
71
|
+
onFieldRemove,
|
|
67
72
|
}) {
|
|
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
|
-
|
|
73
|
+
const [form] = Form.useForm();
|
|
74
|
+
|
|
75
|
+
let layoutValue;
|
|
76
|
+
if (layout) {
|
|
77
|
+
layoutValue = layout
|
|
78
|
+
} else {
|
|
79
|
+
layoutValue = {
|
|
80
|
+
labelCol: { span: 12 },
|
|
81
|
+
wrapperCol: { span: 12 },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Variable used for loading state
|
|
86
|
+
const [loading, setLoading] = useState(false);
|
|
87
|
+
|
|
88
|
+
// Variable stores the form body values
|
|
89
|
+
const [content, setContent] = useState(() => {
|
|
90
|
+
|
|
91
|
+
// Body for the files
|
|
92
|
+
let body = formContent || { [model.name]: {} };
|
|
93
|
+
|
|
94
|
+
fields.forEach((entry) => {
|
|
95
|
+
|
|
96
|
+
if (entry.transform) {
|
|
97
|
+
|
|
98
|
+
body[entry.field] = entry.transform(body[entry.field]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// If its a date
|
|
102
|
+
if (['date'].indexOf(entry.type) !== -1 && formContent[entry.field]) {
|
|
103
|
+
|
|
104
|
+
body[entry.field] = DateUtils.getMomentObject(formContent[entry.field]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
return body;
|
|
110
|
+
|
|
98
111
|
});
|
|
99
112
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/
|
|
109
|
-
function onUpload(element, attachments) {
|
|
110
|
-
form.setFieldsValue({ [element.field]: attachments });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Custom Listener for onchange of input
|
|
115
|
-
*
|
|
116
|
-
* @param {*} element
|
|
117
|
-
* @param {*} attachments
|
|
118
|
-
*/
|
|
119
|
-
function onChange(element, value) {
|
|
120
|
-
// Though we initially gave less respect to this method
|
|
121
|
-
// This is the game changer - 29/01/23
|
|
122
|
-
|
|
123
|
-
// Being able to listen to script , Bind onChange listeners to each input
|
|
124
|
-
// can avoid the need for building custom forms again
|
|
125
|
-
|
|
126
|
-
// console.log(element);
|
|
127
|
-
|
|
128
|
-
/** */
|
|
129
|
-
if (element.field) {
|
|
130
|
-
form.setFieldsValue({ [element.field]: value });
|
|
113
|
+
/**
|
|
114
|
+
* Function handles trigger of onupload
|
|
115
|
+
*
|
|
116
|
+
* @param {*} element
|
|
117
|
+
* @param {*} attachments
|
|
118
|
+
*/
|
|
119
|
+
function onUpload(element, attachments) {
|
|
120
|
+
form.setFieldsValue({ [element.field]: attachments });
|
|
131
121
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Custom Listener for onchange of input
|
|
125
|
+
*
|
|
126
|
+
* @param {*} element
|
|
127
|
+
* @param {*} attachments
|
|
128
|
+
*/
|
|
129
|
+
function onChange(element, value) {
|
|
130
|
+
|
|
131
|
+
// Though we initially gave less respect to this method
|
|
132
|
+
// This is the game changer - 29/01/23
|
|
133
|
+
|
|
134
|
+
// Being able to listen to script , Bind onChange listeners to each input
|
|
135
|
+
// can avoid the need for building custom forms again
|
|
136
|
+
|
|
137
|
+
// console.log(element);
|
|
138
|
+
|
|
139
|
+
/** */
|
|
140
|
+
if (element.field) {
|
|
141
|
+
|
|
142
|
+
form.setFieldsValue({ [element.field]: value });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// const onDragEnd = (result) => {
|
|
147
|
+
|
|
148
|
+
// onListUpdate(result.source, result.destination);
|
|
149
|
+
// }
|
|
150
|
+
|
|
151
|
+
// const getListStyle = (isDraggingOver) => ({
|
|
152
|
+
// // background: isDraggingOver ? 'lightblue' : '',
|
|
153
|
+
// boxShadow: isDraggingOver ? '0px 0px 5px 5px #eeeeee' : '',
|
|
154
|
+
|
|
155
|
+
// // padding: grid,
|
|
156
|
+
// // width: 250
|
|
157
|
+
// });
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Function triggered for any onChange of input
|
|
161
|
+
*
|
|
162
|
+
* @param {*} formFields
|
|
163
|
+
*/
|
|
164
|
+
const onFieldsChange = (formFields) => {
|
|
165
|
+
|
|
166
|
+
formFields.forEach((field) => {
|
|
167
|
+
if (field.name[0].includes('date')) {
|
|
168
|
+
|
|
169
|
+
// values[field.field] = new Timestamp(moment(field.value).valueOf());
|
|
170
|
+
|
|
171
|
+
// content[field.name[0]] = moment(field.value).format('DD/MM/YYYY');
|
|
172
|
+
} else {
|
|
173
|
+
// content[field.name[0]] = field.value;
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
// setContent({ ...content })
|
|
181
177
|
}
|
|
182
|
-
};
|
|
183
178
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Values Change
|
|
181
|
+
*
|
|
182
|
+
* @param {*} field
|
|
183
|
+
* @param {*} values
|
|
184
|
+
*/
|
|
185
|
+
const onValuesChange = async (field, values) => {
|
|
186
|
+
|
|
187
|
+
// Find the input that is changed
|
|
188
|
+
let key = Object.keys(field)[0];
|
|
189
|
+
|
|
190
|
+
// Configuration
|
|
191
|
+
let fieldConfiguration = fields.filter((config) => config.field === key)[0];
|
|
192
|
+
|
|
193
|
+
// We have to check if there is an onChange script for the field
|
|
194
|
+
if (fieldConfiguration.on_change) {
|
|
195
|
+
|
|
196
|
+
// Before Submit of form , execute the script
|
|
197
|
+
values = await prepareAndExecuteScript(values, null, fieldConfiguration.on_change);
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (onFormValuesChange) {
|
|
202
|
+
onFormValuesChange(values);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<section className="form-creator">
|
|
208
|
+
|
|
209
|
+
{/* <DragDropContext onDragEnd={onDragEnd}>
|
|
188
210
|
<Droppable droppableId="droppable">
|
|
189
211
|
|
|
190
212
|
{(provided, snapshot) => (
|
|
@@ -194,344 +216,372 @@ function FormCreator({
|
|
|
194
216
|
{...provided.droppableProps}
|
|
195
217
|
> */}
|
|
196
218
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
219
|
+
<Form
|
|
220
|
+
|
|
221
|
+
form={form}
|
|
222
|
+
// layout="inline"
|
|
223
|
+
{...layoutValue}
|
|
224
|
+
className="new-record"
|
|
225
|
+
name="new-record"
|
|
226
|
+
onFinish={(values) => {
|
|
227
|
+
|
|
228
|
+
setLoading(true);
|
|
229
|
+
|
|
230
|
+
// Do a screening to check if date fields are
|
|
231
|
+
fields.forEach((field) => {
|
|
232
|
+
|
|
233
|
+
if (field.field && field.field.includes('date')) {
|
|
234
|
+
|
|
235
|
+
// values[field.field] = new Timestamp(new Date());
|
|
236
|
+
|
|
237
|
+
values[field.field] = moment(values[field.field]).valueOf();
|
|
238
|
+
|
|
239
|
+
} else {
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (field.type === ('time')) {
|
|
244
|
+
|
|
245
|
+
// values[field.field] = new Timestamp(new Date());
|
|
246
|
+
|
|
247
|
+
values[field.field] = moment(values[field.field]).format('HH:mm A');
|
|
248
|
+
|
|
249
|
+
} else {
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
onSubmit(values).then(() => {
|
|
255
|
+
|
|
256
|
+
setLoading(false);
|
|
257
|
+
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
}}
|
|
261
|
+
// layout="inline"
|
|
262
|
+
|
|
263
|
+
onFieldsChange={onFieldsChange}
|
|
264
|
+
|
|
265
|
+
onValuesChange={onValuesChange}
|
|
266
|
+
layout={layoutValue}
|
|
267
|
+
// validateMessages={validateMessages}
|
|
268
|
+
initialValues={{
|
|
269
|
+
...content,
|
|
270
|
+
remarks: ''
|
|
271
|
+
}}
|
|
272
|
+
>
|
|
273
|
+
|
|
274
|
+
{/* Mapper maps each fields to build the form */}
|
|
275
|
+
<FieldMapper
|
|
276
|
+
fields={fields}
|
|
277
|
+
reportId={reportId}
|
|
278
|
+
onChange={onChange}
|
|
279
|
+
selectedInformation={selectedInformation}
|
|
280
|
+
onUpload={onUpload}
|
|
281
|
+
onFieldUpdate={onFieldUpdate}
|
|
282
|
+
onFieldRemove={onFieldRemove}
|
|
283
|
+
/>
|
|
284
|
+
|
|
285
|
+
{/* Mapper Ends */}
|
|
286
|
+
|
|
287
|
+
<Button loading={loading} type="primary" htmlType="submit" className="submit-button">
|
|
288
|
+
SUBMIT
|
|
289
|
+
</Button>
|
|
290
|
+
</Form>
|
|
291
|
+
|
|
292
|
+
{/* </div>)}
|
|
255
293
|
|
|
256
294
|
</Droppable>
|
|
257
295
|
</DragDropContext> */}
|
|
258
|
-
|
|
259
|
-
|
|
296
|
+
|
|
297
|
+
</section>
|
|
298
|
+
);
|
|
260
299
|
}
|
|
261
300
|
|
|
262
301
|
export default FormCreator;
|
|
263
302
|
|
|
303
|
+
|
|
264
304
|
/**
|
|
265
305
|
* Field Mapper accepts fields to build the form
|
|
266
|
-
*
|
|
267
|
-
* @param {*} param0
|
|
268
|
-
* @returns
|
|
306
|
+
*
|
|
307
|
+
* @param {*} param0
|
|
308
|
+
* @returns
|
|
269
309
|
*/
|
|
270
|
-
function FieldMapper({
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return (
|
|
280
|
-
<TabPane tab={`${tab.caption}`} key={tabIndex}>
|
|
281
|
-
{/* Customizes the Tab */}
|
|
282
|
-
<TabCustomizer
|
|
283
|
-
tab={tab}
|
|
284
|
-
field={field}
|
|
285
|
-
onFieldUpdate={onFieldUpdate}
|
|
286
|
-
fieldIndex={tabIndex}
|
|
287
|
-
index={index}
|
|
288
|
-
onFieldRemove={onFieldRemove}
|
|
289
|
-
/>
|
|
290
|
-
{/* Customizes the Tab Ends */}
|
|
310
|
+
function FieldMapper({
|
|
311
|
+
fields = [],
|
|
312
|
+
reportId,
|
|
313
|
+
onChange,
|
|
314
|
+
selectedInformation,
|
|
315
|
+
onUpload,
|
|
316
|
+
onFieldUpdate,
|
|
317
|
+
onFieldRemove
|
|
318
|
+
}) {
|
|
291
319
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
320
|
+
return (<>
|
|
321
|
+
|
|
322
|
+
{
|
|
323
|
+
fields.map((field, index) => {
|
|
324
|
+
|
|
325
|
+
// For Tabs
|
|
326
|
+
if (field.type === 'Tabs') {
|
|
327
|
+
|
|
328
|
+
return (<Tabs defaultActiveKey="0">
|
|
329
|
+
|
|
330
|
+
{
|
|
331
|
+
field.tabs.map((tab, tabIndex) => {
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<TabPane tab={`${tab.caption}`} key={tabIndex} >
|
|
335
|
+
|
|
336
|
+
{/* Customizes the Tab */}
|
|
337
|
+
<TabCustomizer
|
|
338
|
+
|
|
339
|
+
tab={tab}
|
|
340
|
+
field={field}
|
|
341
|
+
|
|
342
|
+
onFieldUpdate={onFieldUpdate}
|
|
343
|
+
fieldIndex={tabIndex}
|
|
344
|
+
index={index}
|
|
345
|
+
onFieldRemove={onFieldRemove} />
|
|
346
|
+
{/* Customizes the Tab Ends */}
|
|
347
|
+
|
|
348
|
+
{/* Mapper maps each fields to build the form */}
|
|
349
|
+
<FieldMapper
|
|
350
|
+
fields={tab.fields}
|
|
351
|
+
reportId={reportId}
|
|
352
|
+
onChange={onChange}
|
|
353
|
+
onUpload={onUpload}
|
|
354
|
+
onFieldUpdate={onFieldUpdate}
|
|
355
|
+
onFieldRemove={onFieldRemove}
|
|
356
|
+
/>
|
|
357
|
+
|
|
358
|
+
</TabPane>
|
|
359
|
+
)
|
|
360
|
+
})
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
</Tabs>)
|
|
364
|
+
|
|
365
|
+
} else {
|
|
366
|
+
|
|
367
|
+
if (field.condition) {
|
|
368
|
+
|
|
369
|
+
return field.condition(content)
|
|
370
|
+
?
|
|
371
|
+
<UserInput
|
|
372
|
+
onChange={onChange}
|
|
373
|
+
reportId={reportId}
|
|
374
|
+
index={index}
|
|
375
|
+
key={index}
|
|
376
|
+
onUpload={onUpload}
|
|
377
|
+
field={field}
|
|
378
|
+
onFieldUpdate={onFieldUpdate}
|
|
379
|
+
onFieldRemove={onFieldRemove}
|
|
380
|
+
/>
|
|
381
|
+
:
|
|
382
|
+
null
|
|
383
|
+
|
|
384
|
+
} else {
|
|
385
|
+
return <UserInput
|
|
386
|
+
onChange={onChange}
|
|
387
|
+
reportId={reportId}
|
|
388
|
+
key={index}
|
|
389
|
+
selectedInformation={selectedInformation}
|
|
390
|
+
index={index}
|
|
391
|
+
field={field}
|
|
392
|
+
onUpload={onUpload}
|
|
393
|
+
onFieldUpdate={onFieldUpdate}
|
|
394
|
+
|
|
395
|
+
onFieldRemove={onFieldRemove}
|
|
396
|
+
|
|
397
|
+
/>;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
})
|
|
334
401
|
}
|
|
335
|
-
|
|
336
|
-
</>
|
|
337
|
-
|
|
402
|
+
|
|
403
|
+
</>)
|
|
404
|
+
|
|
338
405
|
}
|
|
339
406
|
|
|
407
|
+
|
|
408
|
+
|
|
340
409
|
/**
|
|
341
410
|
* Component accepts user input according to type
|
|
342
|
-
*
|
|
343
|
-
* @param {*} param0
|
|
411
|
+
*
|
|
412
|
+
* @param {*} param0
|
|
344
413
|
*/
|
|
345
|
-
function UserInput({ field, onUpload, selectedInformation, onChange, onFieldUpdate, onFieldRemove, index,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const isVisible = field.visible !== undefined ? field.visible : true;
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* According to the type render each element
|
|
357
|
-
*
|
|
358
|
-
* @param {*} field
|
|
359
|
-
*/
|
|
360
|
-
const inputElement = (field, onChange) => {
|
|
361
|
-
if (field.visible) {
|
|
362
|
-
if (field.visible === false) return null;
|
|
414
|
+
function UserInput({ field, onUpload, selectedInformation, onChange, onFieldUpdate, onFieldRemove, index, reportId }) {
|
|
415
|
+
|
|
416
|
+
let props = {};
|
|
417
|
+
|
|
418
|
+
// The extra text
|
|
419
|
+
if (field.extra) {
|
|
420
|
+
props.extra = field.extra;
|
|
363
421
|
}
|
|
364
422
|
|
|
365
|
-
|
|
366
|
-
case 'number':
|
|
367
|
-
return <InputNumber required={field.required} />;
|
|
368
|
-
|
|
369
|
-
case 'input':
|
|
370
|
-
return <Input required={field.required} />;
|
|
371
|
-
|
|
372
|
-
case 'radio':
|
|
373
|
-
return (
|
|
374
|
-
<Radio.Group>
|
|
375
|
-
{field.options.map((option, key) => (
|
|
376
|
-
<Radio key={key} value={option}>
|
|
377
|
-
{option ? 'Yes' : 'No'}
|
|
378
|
-
</Radio>
|
|
379
|
-
))}
|
|
380
|
-
</Radio.Group>
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
case 'checkbox':
|
|
384
|
-
return (
|
|
385
|
-
<Checkbox.Group style={{ width: '100%' }}>
|
|
386
|
-
<Col>
|
|
387
|
-
{field.options.map((option, key) => {
|
|
388
|
-
let opt = typeof option === 'string' ? option : option.value;
|
|
423
|
+
const isVisible = field.visible !== undefined ? field.visible : true;
|
|
389
424
|
|
|
425
|
+
/**
|
|
426
|
+
* According to the type render each element
|
|
427
|
+
*
|
|
428
|
+
* @param {*} field
|
|
429
|
+
*/
|
|
430
|
+
const inputElement = (field, onChange) => {
|
|
431
|
+
|
|
432
|
+
if (field.visible) {
|
|
433
|
+
|
|
434
|
+
if (field.visible === false) return null;
|
|
435
|
+
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
switch (field.type) {
|
|
439
|
+
|
|
440
|
+
case 'search':
|
|
441
|
+
return <AdvancedSearchSelect {...field} reportId={reportId} style={{ width: '100%' }} />
|
|
442
|
+
|
|
443
|
+
case 'number':
|
|
444
|
+
return <InputNumber required={field.required} />
|
|
445
|
+
|
|
446
|
+
case 'input':
|
|
447
|
+
return <Input required={field.required} />
|
|
448
|
+
|
|
449
|
+
case 'radio':
|
|
390
450
|
return (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
451
|
+
<Radio.Group>
|
|
452
|
+
|
|
453
|
+
{field.options.map((option, key) => <Radio key={key} value={option}>{option ? 'Yes' : 'No'}</Radio>)}
|
|
454
|
+
|
|
455
|
+
</Radio.Group>
|
|
456
|
+
|
|
396
457
|
);
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
458
|
+
|
|
459
|
+
case 'checkbox':
|
|
460
|
+
return <Checkbox.Group style={{ width: '100%' }}>
|
|
461
|
+
<Col>
|
|
462
|
+
{
|
|
463
|
+
field.options.map((option, key) => {
|
|
464
|
+
|
|
465
|
+
let opt = typeof option === 'string' ? option : option.value;
|
|
466
|
+
|
|
467
|
+
return <Row><Checkbox key={key} value={opt}>{opt}</Checkbox></Row>
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
</Col>
|
|
471
|
+
</Checkbox.Group>
|
|
472
|
+
|
|
473
|
+
// case 'checkbox':
|
|
474
|
+
// return <Checkbox.Group options={field.options}/>
|
|
475
|
+
case 'textarea':
|
|
476
|
+
return <TextArea rows={4} required={field.required} />
|
|
477
|
+
|
|
478
|
+
case 'boolean':
|
|
479
|
+
return <Select style={{ width: '120' }} required={field.required}>
|
|
480
|
+
{[true, false].map((option, key) => <Option key={key} value={option}>{option ? 'Yes' : 'No'}</Option>)}
|
|
481
|
+
</Select>
|
|
482
|
+
|
|
483
|
+
case 'select':
|
|
484
|
+
// Handle static select options
|
|
485
|
+
if (Array.isArray(field.options)) {
|
|
486
|
+
|
|
487
|
+
let defaultValue = field.default ? field.default : '';
|
|
488
|
+
|
|
489
|
+
/**If there is selected Information ie, for change info if there is selected guest information
|
|
490
|
+
* then we will match and set a default value from the guest details
|
|
491
|
+
*/
|
|
492
|
+
if (selectedInformation) {
|
|
493
|
+
// Get the field value dynamically from selectedInformation[0] using field.field
|
|
494
|
+
const fieldValue = selectedInformation[0] && selectedInformation[0][field.caption];
|
|
495
|
+
|
|
496
|
+
// Find the default value based on field value and matching DisplayMember or description
|
|
497
|
+
const defaultOption = field.options.find(
|
|
498
|
+
(option) =>
|
|
499
|
+
option.displayMember?.toLowerCase() === fieldValue?.toLowerCase()
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
// If a matching option is found, set the default value; otherwise, do not set a default value (i.e., null or undefined)
|
|
503
|
+
defaultValue = defaultOption ? defaultOption.valueMember : null;
|
|
504
|
+
|
|
505
|
+
}
|
|
506
|
+
/**In case of default selection we need to call the onchange manually */
|
|
507
|
+
if (defaultValue) {
|
|
508
|
+
|
|
509
|
+
onChange(field, defaultValue);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return (
|
|
513
|
+
<Select defaultValue={defaultValue}
|
|
514
|
+
required={field.required}
|
|
515
|
+
style={{ width: '120' }}
|
|
516
|
+
onChange={(value) => onChange(field, value)}
|
|
517
|
+
>
|
|
518
|
+
{field.options.map((option, key) => (
|
|
519
|
+
<Option key={key} value={option.valueMember}>
|
|
520
|
+
{option.displayMember}
|
|
521
|
+
</Option>
|
|
522
|
+
))}
|
|
523
|
+
</Select>
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
// case 'checkbox':
|
|
527
|
+
// return <Checkbox.Group options={field.options} />
|
|
528
|
+
|
|
529
|
+
case 'datetime':
|
|
530
|
+
return <DatePicker format={"DD/MM/YYYY"} onChange={(record) => {
|
|
531
|
+
|
|
532
|
+
onChange(field, record.format('DD/MM/YYYY'))
|
|
533
|
+
|
|
534
|
+
}} />
|
|
535
|
+
|
|
536
|
+
case 'date':
|
|
537
|
+
return <DatePicker format={"DD/MM/YYYY"} />
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
case 'time':
|
|
541
|
+
return <TimePicker format={"HH:mm A"} />
|
|
542
|
+
|
|
543
|
+
// onChange={(record) => {
|
|
544
|
+
|
|
545
|
+
// console.log(record);
|
|
546
|
+
|
|
547
|
+
// onChange(field, record.format('HH:mm A'))
|
|
548
|
+
|
|
549
|
+
// }}
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
case 'upload':
|
|
553
|
+
return <FileUpload multiple={field.multiple} maxSize={field.maxSize || 3} callback={(attachment) => onUpload(field, attachment)} onProgress={() => { }} />
|
|
554
|
+
|
|
555
|
+
case 'camera':
|
|
556
|
+
return <Camera />
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
default:
|
|
560
|
+
return <Input />
|
|
457
561
|
}
|
|
458
|
-
// Render the ReferenceSelect component
|
|
459
|
-
|
|
460
|
-
return (
|
|
461
|
-
<ReferenceSelect
|
|
462
|
-
style={{ width: 120 }}
|
|
463
|
-
field={field.code}
|
|
464
|
-
model={formContent[field.modelName]}
|
|
465
|
-
{...field}
|
|
466
|
-
onChange={(value) => onChange(field, value)}
|
|
467
|
-
defaultValue={field.default}
|
|
468
|
-
allowClear={true}
|
|
469
|
-
// defaultValue={'1'}
|
|
470
|
-
/>
|
|
471
|
-
);
|
|
472
|
-
|
|
473
|
-
case 'datetime':
|
|
474
|
-
return (
|
|
475
|
-
<DatePicker
|
|
476
|
-
format={'DD/MM/YYYY'}
|
|
477
|
-
onChange={(record) => {
|
|
478
|
-
onChange(field, record.format('DD/MM/YYYY'));
|
|
479
|
-
}}
|
|
480
|
-
/>
|
|
481
|
-
);
|
|
482
|
-
|
|
483
|
-
case 'date':
|
|
484
|
-
return <DatePicker format={'DD/MM/YYYY'} />;
|
|
485
|
-
|
|
486
|
-
case 'time':
|
|
487
|
-
return <TimePicker format={'HH:mm A'} />;
|
|
488
|
-
|
|
489
|
-
// onChange={(record) => {
|
|
490
|
-
|
|
491
|
-
// console.log(record);
|
|
492
|
-
|
|
493
|
-
// onChange(field, record.format('HH:mm A'))
|
|
494
|
-
|
|
495
|
-
// }}
|
|
496
|
-
|
|
497
|
-
case 'upload':
|
|
498
|
-
return (
|
|
499
|
-
<FileUpload
|
|
500
|
-
multiple={field.multiple}
|
|
501
|
-
maxSize={field.maxSize || 3}
|
|
502
|
-
callback={(attachment) => onUpload(field, attachment)}
|
|
503
|
-
onProgress={() => {}}
|
|
504
|
-
/>
|
|
505
|
-
);
|
|
506
|
-
|
|
507
|
-
case 'camera':
|
|
508
|
-
return <Camera />;
|
|
509
|
-
|
|
510
|
-
default:
|
|
511
|
-
return <Input />;
|
|
512
562
|
}
|
|
513
|
-
};
|
|
514
563
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
564
|
+
// const getItemStyle = (draggableStyle, isDragging) => ({
|
|
565
|
+
// // some basic styles to make the items look a bit nicer
|
|
566
|
+
// userSelect: 'none',
|
|
567
|
+
// // padding: grid,
|
|
568
|
+
// // margin: `0 0 ${grid}px 0`,
|
|
569
|
+
// // position: `absolute`,
|
|
570
|
+
// // right: '40px',
|
|
522
571
|
|
|
523
|
-
|
|
524
|
-
|
|
572
|
+
// // change background colour if dragging
|
|
573
|
+
// // background: isDragging ? 'lightgreen' : 'whitesmoke',
|
|
525
574
|
|
|
526
|
-
|
|
575
|
+
// boxShadow: isDragging ? '0px 0px 5px 5px #eeeeee' : '',
|
|
527
576
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
577
|
+
// // styles we need to apply on draggables
|
|
578
|
+
// ...draggableStyle
|
|
579
|
+
// });
|
|
531
580
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
581
|
+
|
|
582
|
+
return (
|
|
583
|
+
<>
|
|
584
|
+
{/* <Draggable
|
|
535
585
|
key={`${field.caption}-${index}`}
|
|
536
586
|
draggableId={`${field.caption}-${index}`}
|
|
537
587
|
index={index}
|
|
@@ -549,9 +599,10 @@ function UserInput({ field, onUpload, selectedInformation, onChange, onFieldUpda
|
|
|
549
599
|
)}
|
|
550
600
|
|
|
551
601
|
> */}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
602
|
+
{isVisible === true ? (
|
|
603
|
+
<div className="form-item-element">
|
|
604
|
+
|
|
605
|
+
{/* <Button
|
|
555
606
|
size="small"
|
|
556
607
|
ref={provided.innerRef}
|
|
557
608
|
{...provided.dragHandleProps}
|
|
@@ -566,25 +617,31 @@ function UserInput({ field, onUpload, selectedInformation, onChange, onFieldUpda
|
|
|
566
617
|
|
|
567
618
|
</Button> */}
|
|
568
619
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
620
|
+
|
|
621
|
+
{/* Customizes the form */}
|
|
622
|
+
<FieldCustomizer field={field} onFieldUpdate={onFieldUpdate} index={index} onFieldRemove={onFieldRemove} />
|
|
623
|
+
{/* Customizes the form Ends */}
|
|
624
|
+
|
|
625
|
+
<Form.Item
|
|
626
|
+
{...props}
|
|
627
|
+
name={field.field}
|
|
628
|
+
label={field.caption}
|
|
629
|
+
rules={[{ required: field.required, message: field.placeholder || 'Please enter ' + field.caption }]}
|
|
630
|
+
style={{ marginBottom: '12px' }}
|
|
631
|
+
>
|
|
632
|
+
|
|
633
|
+
{inputElement(field, onChange)}
|
|
634
|
+
{/* <InputElement field={field} /> */}
|
|
635
|
+
|
|
636
|
+
</Form.Item>
|
|
637
|
+
|
|
638
|
+
</div>
|
|
639
|
+
) : null}
|
|
640
|
+
{/* </div>
|
|
585
641
|
</div>
|
|
586
642
|
)}
|
|
587
643
|
</Draggable> */}
|
|
588
|
-
|
|
589
|
-
|
|
644
|
+
|
|
645
|
+
</>
|
|
646
|
+
)
|
|
590
647
|
}
|