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.
@@ -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 'react';
16
+ import React, { useState } from "react"
17
17
 
18
18
  import moment from 'moment';
19
19
 
20
- import Button from '../../../../../lib/elements/basic/button/button';
20
+ import Button from "../../../../../lib/elements/basic/button/button";
21
21
 
22
- import { Form, Input, Radio, InputNumber, DatePicker, TimePicker, Checkbox, Select, Row, Col, Tabs } from 'antd';
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 '../../../../utils';
32
+ import { DateUtils } from "../../../../utils";
33
33
 
34
- import { FieldCustomizer, TabCustomizer, ReferenceSelect } from './../../../../';
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
- import './form-creator.scss';
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
- /**If we want to change the existing information first we need the current information ie, selectedInformation*/
56
- selectedInformation,
57
- model,
58
- formContent = {},
59
- onSubmit,
60
- fields = [],
61
- callback,
62
- layout,
63
- // Below are arguments for use in form display
64
- onFieldUpdate,
65
- // onListUpdate,
66
- onFieldRemove,
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
- const [form] = Form.useForm();
69
-
70
- let layoutValue;
71
-
72
- if (layout) {
73
- layoutValue = layout;
74
- } else {
75
- layoutValue = {
76
- labelCol: { span: 12 },
77
- wrapperCol: { span: 12 },
78
- };
79
- }
80
-
81
- // Variable used for loading state
82
- const [loading, setLoading] = useState(false);
83
-
84
- // Variable stores the form body values
85
- const [content, setContent] = useState(() => {
86
- // Body for the files
87
- let body = formContent || { [model.name]: {} };
88
-
89
- fields.forEach((entry) => {
90
- if (entry.transform) {
91
- body[entry.field] = entry.transform(body[entry.field]);
92
- }
93
-
94
- // If its a date
95
- if (['date'].indexOf(entry.type) !== -1 && formContent[entry.field]) {
96
- body[entry.field] = DateUtils.getMomentObject(formContent[entry.field]);
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
- return body;
101
- });
102
-
103
- /**
104
- * Function handles trigger of onupload
105
- *
106
- * @param {*} element
107
- * @param {*} attachments
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
- // const onDragEnd = (result) => {
135
-
136
- // onListUpdate(result.source, result.destination);
137
- // }
138
-
139
- // const getListStyle = (isDraggingOver) => ({
140
- // // background: isDraggingOver ? 'lightblue' : '',
141
- // boxShadow: isDraggingOver ? '0px 0px 5px 5px #eeeeee' : '',
142
-
143
- // // padding: grid,
144
- // // width: 250
145
- // });
146
-
147
- /**
148
- * Function triggered for any onChange of input
149
- *
150
- * @param {*} formFields
151
- */
152
- const onFieldsChange = (formFields) => {
153
- formFields.forEach((field) => {
154
- if (field.name[0].includes('date')) {
155
- // values[field.field] = new Timestamp(moment(field.value).valueOf());
156
- // content[field.name[0]] = moment(field.value).format('DD/MM/YYYY');
157
- } else {
158
- // content[field.name[0]] = field.value;
159
- }
160
- });
161
- // setContent({ ...content })
162
- };
163
-
164
- /**
165
- * Values Change
166
- *
167
- * @param {*} field
168
- * @param {*} values
169
- */
170
- const onValuesChange = async (field, values) => {
171
- // Find the input that is changed
172
- let key = Object.keys(field)[0];
173
-
174
- // Configuration
175
- let fieldConfiguration = fields.filter((config) => config.field === key)[0];
176
-
177
- // We have to check if there is an onChange script for the field
178
- if (fieldConfiguration.on_change) {
179
- // Before Submit of form , execute the script
180
- values = await prepareAndExecuteScript(values, null, fieldConfiguration.on_change);
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
- return (
185
- <section className="form-creator">
186
- <div>
187
- {/* <DragDropContext onDragEnd={onDragEnd}>
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
- <Form
198
- form={form}
199
- // layout="inline"
200
- {...layoutValue}
201
- className="new-record"
202
- name="new-record"
203
- onFinish={(values) => {
204
- setLoading(true);
205
-
206
- // Do a screening to check if date fields are
207
- fields.forEach((field) => {
208
- if (field.field && field.field.includes('date')) {
209
- // values[field.field] = new Timestamp(new Date());
210
-
211
- values[field.field] = moment(values[field.field]).valueOf();
212
- } else {
213
- }
214
-
215
- if (field.type === 'time') {
216
- // values[field.field] = new Timestamp(new Date());
217
-
218
- values[field.field] = moment(values[field.field]).format('HH:mm A');
219
- } else {
220
- }
221
- });
222
-
223
- onSubmit(values).then(() => {
224
- setLoading(false);
225
- });
226
- }}
227
- onFieldsChange={onFieldsChange}
228
- onValuesChange={onValuesChange}
229
- layout={layoutValue}
230
- // validateMessages={validateMessages}
231
- initialValues={{
232
- ...content,
233
- remarks: '',
234
- }}
235
- >
236
- {/* Mapper maps each fields to build the form */}
237
- <FieldMapper
238
- fields={fields}
239
- onChange={onChange}
240
- selectedInformation={selectedInformation}
241
- onUpload={onUpload}
242
- onFieldUpdate={onFieldUpdate}
243
- onFieldRemove={onFieldRemove}
244
- formContent={formContent}
245
- />
246
-
247
- {/* Mapper Ends */}
248
-
249
- <Button loading={loading} type="primary" htmlType="submit" className="submit-button">
250
- SUBMIT
251
- </Button>
252
- </Form>
253
- </div>
254
- {/* </div>)}
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
- </section>
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({ fields = [], onChange, selectedInformation, onUpload, onFieldUpdate, onFieldRemove, formContent }) {
271
- return (
272
- <>
273
- {fields.map((field, index) => {
274
- // For Tabs
275
- if (field.type === 'Tabs') {
276
- return (
277
- <Tabs defaultActiveKey="0">
278
- {field.tabs.map((tab, tabIndex) => {
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
- {/* Mapper maps each fields to build the form */}
293
- <FieldMapper
294
- fields={tab.fields}
295
- onChange={onChange}
296
- onUpload={onUpload}
297
- onFieldUpdate={onFieldUpdate}
298
- onFieldRemove={onFieldRemove}
299
- />
300
- </TabPane>
301
- );
302
- })}
303
- </Tabs>
304
- );
305
- } else {
306
- if (field.condition) {
307
- return field.condition(content) ? (
308
- <UserInput
309
- onChange={onChange}
310
- index={index}
311
- key={index}
312
- onUpload={onUpload}
313
- field={field}
314
- onFieldUpdate={onFieldUpdate}
315
- onFieldRemove={onFieldRemove}
316
- formContent={formContent}
317
- />
318
- ) : null;
319
- } else {
320
- return (
321
- <UserInput
322
- onChange={onChange}
323
- key={index}
324
- selectedInformation={selectedInformation}
325
- index={index}
326
- field={field}
327
- onUpload={onUpload}
328
- onFieldUpdate={onFieldUpdate}
329
- onFieldRemove={onFieldRemove}
330
- formContent={formContent}
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, formContent }) {
346
- let props = {};
347
-
348
- // The extra text
349
- if (field.extra) {
350
- props.extra = field.extra;
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
- switch (field.type) {
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
- <Row>
392
- <Checkbox key={key} value={opt}>
393
- {opt}
394
- </Checkbox>
395
- </Row>
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
- </Col>
399
- </Checkbox.Group>
400
- );
401
-
402
- // case 'checkbox':
403
- // return <Checkbox.Group options={field.options}/>
404
- case 'textarea':
405
- return <TextArea rows={4} required={field.required} />;
406
-
407
- case 'boolean':
408
- return (
409
- <Select style={{ width: 120 }} required={field.required}>
410
- {[true, false].map((option, key) => (
411
- <Option key={key} value={option}>
412
- {option ? 'Yes' : 'No'}
413
- </Option>
414
- ))}
415
- </Select>
416
- );
417
-
418
- case 'select':
419
- // Handle static select options
420
- if (Array.isArray(field.options)) {
421
- let defaultValue = field.default ? field.default : '';
422
-
423
- /**If there is selected Information ie, for change info if there is selected guest information
424
- * then we will match and set a default value from the guest details
425
- */
426
- if (selectedInformation) {
427
- // Get the field value dynamically from selectedInformation[0] using field.field
428
- const fieldValue = selectedInformation[0] && selectedInformation[0][field.caption];
429
-
430
- // Find the default value based on field value and matching DisplayMember or description
431
- const defaultOption = field.options.find((option) => option.displayMember?.toLowerCase() === fieldValue?.toLowerCase());
432
-
433
- // If a matching option is found, set the default value; otherwise, do not set a default value (i.e., null or undefined)
434
- defaultValue = defaultOption ? defaultOption.valueMember : null;
435
- }
436
- /**In case of default selection we need to call the onchange manually */
437
- if (defaultValue) {
438
- onChange(field, defaultValue);
439
- }
440
-
441
- return (
442
- <Select defaultValue={defaultValue} required={field.required} style={{ width: 120 }} onChange={(value) => onChange(field, value)}>
443
- {field.options.map((option, key) => (
444
- <Option key={key} value={option.valueMember}>
445
- {option.displayMember}
446
- </Option>
447
- ))}
448
- </Select>
449
- );
450
- }
451
- // case 'checkbox':
452
- // return <Checkbox.Group options={field.options} />
453
- case 'reference-select':
454
- // If a default value is provided in the field configuration
455
- if (field.default) {
456
- onChange(field, field.default);
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
- // const getItemStyle = (draggableStyle, isDragging) => ({
516
- // // some basic styles to make the items look a bit nicer
517
- // userSelect: 'none',
518
- // // padding: grid,
519
- // // margin: `0 0 ${grid}px 0`,
520
- // // position: `absolute`,
521
- // // right: '40px',
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
- // // change background colour if dragging
524
- // // background: isDragging ? 'lightgreen' : 'whitesmoke',
572
+ // // change background colour if dragging
573
+ // // background: isDragging ? 'lightgreen' : 'whitesmoke',
525
574
 
526
- // boxShadow: isDragging ? '0px 0px 5px 5px #eeeeee' : '',
575
+ // boxShadow: isDragging ? '0px 0px 5px 5px #eeeeee' : '',
527
576
 
528
- // // styles we need to apply on draggables
529
- // ...draggableStyle
530
- // });
577
+ // // styles we need to apply on draggables
578
+ // ...draggableStyle
579
+ // });
531
580
 
532
- return (
533
- <>
534
- {/* <Draggable
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
- {isVisible === true ? (
553
- <div className="form-item-element">
554
- {/* <Button
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
- {/* Customizes the form */}
570
- <FieldCustomizer field={field} onFieldUpdate={onFieldUpdate} index={index} onFieldRemove={onFieldRemove} />
571
- {/* Customizes the form Ends */}
572
-
573
- <Form.Item
574
- {...props}
575
- name={field.field}
576
- label={field.caption}
577
- rules={[{ required: field.required, message: field.placeholder || 'Please enter ' + field.caption }]}
578
- >
579
- {inputElement(field, onChange)}
580
- {/* <InputElement field={field} /> */}
581
- </Form.Item>
582
- </div>
583
- ) : null}
584
- {/* </div>
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
  }