@visns-studio/visns-components 4.7.1 → 4.7.3

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.
Files changed (96) hide show
  1. package/package.json +13 -9
  2. package/src/components/cms/DataGrid.jsx +1461 -0
  3. package/src/components/cms/DropZone.jsx +349 -0
  4. package/src/components/cms/Field.jsx +802 -0
  5. package/src/components/cms/Form.jsx +476 -0
  6. package/src/components/cms/generic/CmsDetail.jsx +36 -0
  7. package/src/components/cms/generic/CmsIndex.jsx +73 -0
  8. package/src/components/cms/generic/CmsSort.jsx +125 -0
  9. package/src/components/cms/sorting/Item.jsx +115 -0
  10. package/src/components/cms/sorting/List.jsx +30 -0
  11. package/src/components/crm/AsyncSelect.jsx +125 -0
  12. package/src/components/crm/Autocomplete.jsx +174 -0
  13. package/src/components/crm/Breadcrumb.jsx +52 -0
  14. package/src/components/crm/Call.jsx +220 -0
  15. package/src/components/crm/DataGrid.jsx +2701 -0
  16. package/src/components/crm/Download.jsx +101 -0
  17. package/src/components/crm/Fetch.jsx +119 -0
  18. package/src/components/crm/Field.jsx +1557 -0
  19. package/src/components/crm/Form.jsx +1409 -0
  20. package/src/components/crm/Loader.jsx +29 -0
  21. package/src/components/crm/MultiSelect.jsx +78 -0
  22. package/src/components/crm/Navigation.jsx +619 -0
  23. package/src/components/crm/Notification.jsx +197 -0
  24. package/src/components/crm/QrCode.jsx +83 -0
  25. package/src/components/crm/Select.jsx +58 -0
  26. package/src/components/crm/SelectList.jsx +21 -0
  27. package/src/components/crm/TableFilter.jsx +198 -0
  28. package/src/components/crm/auth/Login.jsx +223 -0
  29. package/src/components/crm/auth/Profile.jsx +280 -0
  30. package/src/components/crm/auth/Reset.jsx +111 -0
  31. package/src/components/crm/auth/Verify.jsx +174 -0
  32. package/src/components/crm/auth/styles/Login.module.scss +243 -0
  33. package/src/components/crm/auth/styles/Profile.module.scss +222 -0
  34. package/src/components/crm/auth/styles/Reset.module.scss +216 -0
  35. package/src/components/crm/auth/styles/Verify.module.scss +216 -0
  36. package/src/components/crm/generic/AuditLog.jsx +108 -0
  37. package/src/components/crm/generic/AuditLogs.jsx +115 -0
  38. package/src/components/crm/generic/GenericAuth.jsx +166 -0
  39. package/src/components/crm/generic/GenericDashboard.jsx +42 -0
  40. package/src/components/crm/generic/GenericDetail.jsx +1499 -0
  41. package/src/components/crm/generic/GenericDynamic.jsx +915 -0
  42. package/src/components/crm/generic/GenericFormBuilder.jsx +1765 -0
  43. package/src/components/crm/generic/GenericIndex.jsx +376 -0
  44. package/src/components/crm/generic/GenericMain.jsx +129 -0
  45. package/src/components/crm/generic/GenericSort.jsx +188 -0
  46. package/src/components/crm/generic/NotificationList.jsx +64 -0
  47. package/src/components/crm/generic/styles/AuditLog.module.scss +147 -0
  48. package/src/components/crm/generic/styles/AuditLogs.module.scss +92 -0
  49. package/src/components/crm/generic/styles/GenericDetail.module.scss +634 -0
  50. package/src/components/crm/generic/styles/GenericDynamic.module.scss +932 -0
  51. package/src/components/crm/generic/styles/GenericFormBuilder.module.scss +944 -0
  52. package/src/components/crm/generic/styles/GenericIndex.module.scss +247 -0
  53. package/src/components/crm/generic/styles/GenericMain.module.scss +91 -0
  54. package/src/components/crm/generic/styles/GenericSort.module.scss +123 -0
  55. package/src/components/crm/generic/styles/NotificationList.module.scss +67 -0
  56. package/src/components/crm/sorting/Item.jsx +117 -0
  57. package/src/components/crm/sorting/List.jsx +32 -0
  58. package/src/components/crm/sorting/styles/Item.module.scss +68 -0
  59. package/src/components/crm/sorting/styles/List.module.scss +68 -0
  60. package/src/components/crm/styles/AsyncSelect.module.scss +8 -0
  61. package/src/components/crm/styles/Autocomplete.module.scss +44 -0
  62. package/src/components/crm/styles/DataGrid.module.scss +210 -0
  63. package/src/components/crm/styles/Field.module.scss +311 -0
  64. package/src/components/crm/styles/Form.module.scss +499 -0
  65. package/src/components/crm/styles/Loader.module.scss +94 -0
  66. package/src/components/crm/styles/MultiSelect.module.scss +8 -0
  67. package/src/components/crm/styles/Navigation.module.scss +978 -0
  68. package/src/components/crm/styles/Notification.module.scss +147 -0
  69. package/src/components/crm/styles/QrCode.module.scss +87 -0
  70. package/src/components/crm/styles/TableFilter.module.scss +52 -0
  71. package/src/components/styles/global.css +73 -0
  72. package/src/index.js +86 -0
  73. package/dist/104e5636d8ddb791614c.woff2 +0 -0
  74. package/dist/11fe6a83d647de5daf95.woff +0 -0
  75. package/dist/141e2a8c7836495afe2a.woff +0 -0
  76. package/dist/2ba5877f7079830b5383.woff +0 -0
  77. package/dist/2d6836f45b2037be41f3.woff +0 -0
  78. package/dist/399.0a0f3e0d21be1057d599.css +0 -8
  79. package/dist/399.b8f57fa3f8c0c10119e4.js +0 -1
  80. package/dist/47d566c3b1293dfd9d77.woff +0 -0
  81. package/dist/6282a13cbba671a71913.woff2 +0 -0
  82. package/dist/78266f551031aa9db127.woff +0 -0
  83. package/dist/7b7da89f1e3fdcbfe36c.woff2 +0 -0
  84. package/dist/7e78e8338af7efeda712.woff2 +0 -0
  85. package/dist/7fa387951673abf164b1.woff2 +0 -0
  86. package/dist/819d59862c2d0640aad8.woff +0 -0
  87. package/dist/b615e1a6c838ea059a56.woff +0 -0
  88. package/dist/b9b1aa739c660c4ce67c.woff2 +0 -0
  89. package/dist/c5f3640b11df9414facb.woff +0 -0
  90. package/dist/da26d162ff5af71d6590.woff2 +0 -0
  91. package/dist/dd5b2912dbf896310865.woff2 +0 -0
  92. package/dist/f282b331272463c1aa6c.woff2 +0 -0
  93. package/dist/main.83b033670d64419bb497.css +0 -1
  94. package/dist/main.b1723d17cd2d3513ab62.js +0 -1
  95. package/dist/report.html +0 -39
  96. package/dist/runtime.33c276593b23f8035b8d.js +0 -1
@@ -0,0 +1,1557 @@
1
+ import '../styles/global.css';
2
+
3
+ import React, { useEffect, useRef, useState } from 'react';
4
+ import DatePicker from 'react-datepicker';
5
+ import _ from 'lodash';
6
+ import Toggle from 'react-toggle';
7
+ import moment from 'moment';
8
+ import parse from 'html-react-parser';
9
+ import Popup from 'reactjs-popup';
10
+ import { BlockPicker } from 'react-color';
11
+ import { CopyToClipboard } from 'react-copy-to-clipboard';
12
+ import { NumericFormat, PatternFormat } from 'react-number-format';
13
+ import { Editor } from '@tinymce/tinymce-react';
14
+ import { CirclePlus, CloudDownload, Copy, TrashCan } from 'akar-icons';
15
+ import { toast } from 'react-toastify';
16
+ import styles from './styles/Field.module.scss';
17
+
18
+ import CustomFetch from './Fetch';
19
+ import Form from './Form';
20
+ import MultiSelect from './MultiSelect';
21
+ import Select from './Select';
22
+ import VisnsAsyncSelect from './AsyncSelect';
23
+ import VisnsAutocomplete from './Autocomplete';
24
+ import VisnsDropZone from '../cms/DropZone';
25
+
26
+ import 'react-toggle/style.css';
27
+ import 'react-datepicker/dist/react-datepicker.css';
28
+
29
+ function Field({
30
+ api,
31
+ autocompleteCallback,
32
+ childDropdownCallback,
33
+ fetchData,
34
+ formData,
35
+ inputValue,
36
+ inputClass,
37
+ mapbox,
38
+ onChange,
39
+ onChangeCheckbox,
40
+ onChangeColour,
41
+ onChangeDate,
42
+ onChangeNumberFormat,
43
+ onChangeSelect,
44
+ onChangeSignature,
45
+ onChangeRicheditor,
46
+ onChangeTableRadio,
47
+ onChangeAddTableTextRow,
48
+ onChangeTableText,
49
+ onChangeToggle,
50
+ onFileDownload,
51
+ setFormData,
52
+ settings,
53
+ style,
54
+ userProfile = null,
55
+ }) {
56
+ const editorRef = useRef(null);
57
+ const fileImageInputRef = useRef(null);
58
+ const [colorPickerShow, setColorPickerShow] = useState(false);
59
+ const [counter, setCounter] = useState(0);
60
+ const [dataOptions, setDataOptions] = useState([]);
61
+ const [formItemStyle, setFormItemStyle] = useState({});
62
+ const [formItemClass, setFormItemClass] = useState('');
63
+ const [options, setOptions] = useState([]);
64
+
65
+ const cover = {
66
+ position: 'fixed',
67
+ top: '0px',
68
+ right: '0px',
69
+ bottom: '0px',
70
+ left: '0px',
71
+ };
72
+ const popover = {
73
+ position: 'absolute',
74
+ zIndex: '2',
75
+ left: '20px',
76
+ marginTop: '6px',
77
+ };
78
+
79
+ useEffect(() => {
80
+ const fetchOptions = () => {
81
+ let filter = {};
82
+ if (settings.where?.length > 0) {
83
+ filter = {
84
+ where: settings.where,
85
+ };
86
+ }
87
+
88
+ if (settings.fields?.length > 0) {
89
+ filter.fields = settings.fields;
90
+ }
91
+
92
+ if (
93
+ settings.order &&
94
+ settings.order.sortBy &&
95
+ settings.order.sort
96
+ ) {
97
+ filter.sortBy = settings.order.sortBy;
98
+ filter.sort = settings.order.sort;
99
+ }
100
+
101
+ CustomFetch(settings.url, 'POST', filter, function (result) {
102
+ setOptions(result.data);
103
+
104
+ let dataArray = [];
105
+
106
+ result.data.forEach((a) => {
107
+ let _tempObject = a;
108
+
109
+ if (!_.isEmpty(_tempObject)) {
110
+ let modifiedObject = {};
111
+
112
+ Object.keys(_tempObject).forEach(function (c) {
113
+ if (c !== 'id' && c !== 'label') {
114
+ modifiedObject['data-' + c] = _tempObject[c];
115
+ }
116
+ });
117
+
118
+ dataArray.push(modifiedObject);
119
+ }
120
+ });
121
+
122
+ if (dataArray.length > 0) {
123
+ setDataOptions(dataArray);
124
+ }
125
+ });
126
+ };
127
+
128
+ switch (settings.type) {
129
+ case 'hidden':
130
+ setFormItemStyle({
131
+ display: 'none',
132
+ });
133
+ break;
134
+ case 'dropdown-ajax':
135
+ case 'multi-dropdown-ajax':
136
+ case 'radio-ajax':
137
+ fetchOptions();
138
+ break;
139
+ default:
140
+ break;
141
+ }
142
+
143
+ switch (settings.size) {
144
+ case 'full':
145
+ setFormItemClass(`${styles.formItem} ${styles.fwItem}`);
146
+ break;
147
+ case 'quarter':
148
+ setFormItemClass(`${styles.formItem} ${styles.qtrItem}`);
149
+ break;
150
+ default:
151
+ setFormItemClass(`${styles.formItem}`);
152
+ break;
153
+ }
154
+ }, [settings, counter]);
155
+
156
+ useEffect(() => {
157
+ const fetchChildDropdownData = () => {
158
+ let filter = {};
159
+
160
+ if (settings.child && inputValue) {
161
+ let _inputValue = inputValue.value
162
+ ? inputValue.value
163
+ : inputValue;
164
+
165
+ if (_inputValue > 0) {
166
+ if (Array.isArray(settings.child)) {
167
+ settings.child.forEach((a) => {
168
+ filter = {
169
+ where: [
170
+ {
171
+ id: settings.id,
172
+ value: _inputValue,
173
+ },
174
+ ],
175
+ };
176
+
177
+ if (a.fields) {
178
+ filter.fields = a.fields;
179
+ }
180
+
181
+ if (a.orderBy) {
182
+ filter.orderBy = a.orderBy;
183
+ }
184
+
185
+ CustomFetch(
186
+ a.url,
187
+ 'POST',
188
+ filter,
189
+ function (result) {
190
+ childDropdownCallback({
191
+ id: a.id,
192
+ data: result.data,
193
+ });
194
+ }
195
+ );
196
+ });
197
+ } else {
198
+ filter = {
199
+ where: [
200
+ {
201
+ id: settings.id,
202
+ value: _inputValue,
203
+ },
204
+ ],
205
+ };
206
+
207
+ if (settings.fields) {
208
+ filter.fields = settings.fields;
209
+ }
210
+
211
+ if (settings.orderBy) {
212
+ filter.orderBy = settings.orderBy;
213
+ }
214
+
215
+ CustomFetch(
216
+ settings.child.url,
217
+ 'POST',
218
+ filter,
219
+ function (result) {
220
+ childDropdownCallback({
221
+ id: settings.child.id,
222
+ data: result.data,
223
+ });
224
+ }
225
+ );
226
+ }
227
+ }
228
+ }
229
+ };
230
+
231
+ fetchChildDropdownData();
232
+ }, [inputValue, settings, counter]);
233
+
234
+ useEffect(() => {
235
+ const processOptions = () => {
236
+ if (settings.options?.length > 0) {
237
+ let dataArray = [];
238
+
239
+ settings.options.forEach((a) => {
240
+ let _tempObject = a;
241
+
242
+ if (!_.isEmpty(_tempObject)) {
243
+ let modifiedObject = {};
244
+
245
+ Object.keys(_tempObject).forEach(function (c) {
246
+ if (c !== 'id' && c !== 'label') {
247
+ modifiedObject['data-' + c] = _tempObject[c];
248
+ }
249
+ });
250
+
251
+ dataArray.push(modifiedObject);
252
+ }
253
+ });
254
+
255
+ if (dataArray.length > 0) {
256
+ setDataOptions(dataArray);
257
+ }
258
+ }
259
+ };
260
+
261
+ processOptions();
262
+ }, [settings.options, settings]);
263
+
264
+ const renderLabel = () => {
265
+ if (
266
+ [
267
+ 'address',
268
+ 'async-dropdown-ajax',
269
+ 'checkbox',
270
+ 'colour',
271
+ 'copytoclipboard',
272
+ 'date',
273
+ 'datetime',
274
+ 'dropdown',
275
+ 'dropdown-ajax',
276
+ 'dynamicdata',
277
+ 'file',
278
+ 'gallery',
279
+ 'image',
280
+ 'multi-dropdown',
281
+ 'multi-dropdown-ajax',
282
+ 'plaindate',
283
+ 'plaindatetime',
284
+ 'plainrelation',
285
+ 'plainrelationarray',
286
+ 'radio',
287
+ 'radio-ajax',
288
+ 'richeditor',
289
+ 'signature',
290
+ 'table_radio',
291
+ 'table_text',
292
+ 'time',
293
+ ].includes(settings.type)
294
+ ) {
295
+ return (
296
+ <span className={`${styles.fi__span} ${styles.prefocus}`}>
297
+ {settings.label} {settings.required ? '*' : ''}
298
+ </span>
299
+ );
300
+ } else if (['plaintext'].includes(settings.type)) {
301
+ if (settings.description) {
302
+ return (
303
+ <span>
304
+ {settings.description
305
+ ? parse(settings.description)
306
+ : ''}
307
+ </span>
308
+ );
309
+ } else {
310
+ return (
311
+ <span className={`${styles.fi__span} ${styles.prefocus}`}>
312
+ {settings.label} {settings.required ? '*' : ''}
313
+ </span>
314
+ );
315
+ }
316
+ } else if (['plaintextheading'].includes(settings.type)) {
317
+ return <h2>{settings.label ? settings.label : ''}</h2>;
318
+ }
319
+ };
320
+
321
+ const renderRelationText = (value) => {
322
+ let text = '';
323
+
324
+ const processKeys = (obj) => {
325
+ let tmpValue = obj;
326
+ settings.keys.forEach((key) => {
327
+ tmpValue = tmpValue[key];
328
+ });
329
+ return tmpValue;
330
+ };
331
+
332
+ if (Array.isArray(value) && value[0] && settings.keys) {
333
+ text = processKeys(value[0]);
334
+ } else if (typeof value === 'object' && value !== null) {
335
+ text = processKeys(value);
336
+ }
337
+
338
+ return text;
339
+ };
340
+
341
+ const renderRelationArrayText = (value) => {
342
+ let text = '';
343
+
344
+ if (value && settings.nameFrom) {
345
+ value.forEach((a, b) => {
346
+ if (b > 0) {
347
+ text += ', ';
348
+ }
349
+
350
+ text += a[settings.nameFrom];
351
+ });
352
+ }
353
+
354
+ return text;
355
+ };
356
+
357
+ const renderInput = () => {
358
+ switch (settings.type) {
359
+ case 'address':
360
+ return (
361
+ <VisnsAutocomplete
362
+ api="pk.eyJ1IjoidmlzbnMtc3R1ZGlvIiwiYSI6ImNrbGlraW5vZDBhMDYycHBsdmk5b3ljbGQifQ.ZGUBk0PWac5GahUeVHdTpg"
363
+ country="AU"
364
+ field={settings.id}
365
+ inputValue={inputValue}
366
+ mapbox={mapbox}
367
+ onSelect={autocompleteCallback}
368
+ setFormData={setFormData}
369
+ style={style}
370
+ />
371
+ );
372
+ case 'async-dropdown-ajax':
373
+ return (
374
+ <VisnsAsyncSelect
375
+ settings={settings}
376
+ className={inputClass[settings.id]}
377
+ multi={
378
+ settings.hasOwnProperty('multi')
379
+ ? settings.multi
380
+ : false
381
+ }
382
+ onChange={onChangeSelect}
383
+ inputValue={
384
+ inputValue === null || inputValue === undefined
385
+ ? ''
386
+ : inputValue
387
+ }
388
+ options={options}
389
+ dataOptions={dataOptions}
390
+ />
391
+ );
392
+ case 'checkbox':
393
+ return settings.options?.length > 0 ? (
394
+ <div
395
+ className="fi__optionscontainer"
396
+ style={{ paddingTop: '10px' }}
397
+ >
398
+ {settings.options.map((option, index) => (
399
+ <div
400
+ key={`${settings.id}-checkbox-option-${index}`}
401
+ className="fi__checkboxcontainer"
402
+ >
403
+ <input
404
+ name={settings.id}
405
+ data-name={settings.id}
406
+ type="checkbox"
407
+ className="fi__customcheckbox"
408
+ value={option.label}
409
+ checked={inputValue[index]}
410
+ onChange={onChangeCheckbox}
411
+ />
412
+ <label className="fi__checkboxlabel">
413
+ {option.label}
414
+ </label>{' '}
415
+ </div>
416
+ ))}
417
+ </div>
418
+ ) : null;
419
+ case 'colour':
420
+ return (
421
+ <div className="cpicker">
422
+ <div
423
+ className="cpicker__box"
424
+ style={
425
+ inputValue && inputValue !== 'null'
426
+ ? { background: inputValue }
427
+ : {}
428
+ }
429
+ ></div>
430
+ <div className="cpicker__btn">
431
+ <button
432
+ onClick={(e) => {
433
+ e.preventDefault();
434
+
435
+ setColorPickerShow(
436
+ colorPickerShow === true ? false : true
437
+ );
438
+ }}
439
+ >
440
+ Pick Color
441
+ </button>
442
+ {colorPickerShow === true ? (
443
+ <div style={popover}>
444
+ <div
445
+ style={cover}
446
+ onClick={() => {
447
+ setColorPickerShow(false);
448
+ }}
449
+ />
450
+
451
+ <BlockPicker
452
+ color={
453
+ inputValue && inputValue !== 'null'
454
+ ? inputValue
455
+ : ''
456
+ }
457
+ onChangeComplete={(color, event) => {
458
+ onChangeColour(
459
+ event,
460
+ color,
461
+ settings.id
462
+ );
463
+ }}
464
+ />
465
+ </div>
466
+ ) : null}
467
+ </div>
468
+ </div>
469
+ );
470
+ case 'copytoclipboard':
471
+ return (
472
+ <>
473
+ <input
474
+ type={settings.type}
475
+ data-name={settings.id}
476
+ className={inputClass[settings.id]}
477
+ value={
478
+ inputValue && inputValue !== 'null'
479
+ ? inputValue
480
+ : ''
481
+ }
482
+ readOnly
483
+ />
484
+ <CopyToClipboard
485
+ text={
486
+ inputValue && inputValue !== 'null'
487
+ ? inputValue
488
+ : ''
489
+ }
490
+ onCopy={() => console.info('copied')}
491
+ >
492
+ <Copy
493
+ data-tooltip-id="system-tooltip"
494
+ data-tooltip-content="Copy to Clipboard"
495
+ strokeWidth={2}
496
+ size={24}
497
+ />
498
+ </CopyToClipboard>
499
+ </>
500
+ );
501
+ case 'currency':
502
+ return (
503
+ <NumericFormat
504
+ data-name={settings.id}
505
+ className={inputClass[settings.id]}
506
+ onValueChange={(values) => {
507
+ onChangeNumberFormat(values, settings.id);
508
+ }}
509
+ thousandSeparator={true}
510
+ prefix={'$'}
511
+ value={
512
+ inputValue && inputValue !== 'null'
513
+ ? inputValue
514
+ : ''
515
+ }
516
+ />
517
+ );
518
+ case 'decimal':
519
+ case 'number':
520
+ return (
521
+ <NumericFormat
522
+ data-name={settings.id}
523
+ className={inputClass[settings.id]}
524
+ onValueChange={(values) => {
525
+ onChangeNumberFormat(values, settings.id);
526
+ }}
527
+ thousandSeparator={
528
+ settings.hasOwnProperty('thousandSeperator')
529
+ ? settings.thousandSeperator
530
+ : true
531
+ }
532
+ decimalSeparator={
533
+ settings.type === 'decimal' ? '.' : '.'
534
+ }
535
+ decimalScale={settings.type === 'decimal' ? 2 : 2}
536
+ value={
537
+ inputValue && inputValue !== 'null'
538
+ ? inputValue
539
+ : ''
540
+ }
541
+ />
542
+ );
543
+ case 'dropdown':
544
+ case 'dropdown-ajax':
545
+ return (
546
+ <div className={styles.dropdownContainer}>
547
+ <Select
548
+ settings={settings}
549
+ className={
550
+ settings.create ? styles.selectFullWidth : ''
551
+ }
552
+ onChange={onChange}
553
+ inputValue={inputValue === null ? '' : inputValue}
554
+ options={
555
+ settings.type === 'dropdown'
556
+ ? settings.options
557
+ : options
558
+ }
559
+ dataOptions={dataOptions}
560
+ />
561
+
562
+ {settings.create && (
563
+ <button
564
+ className={styles.buttonRight}
565
+ onClick={(e) => {
566
+ e.preventDefault();
567
+
568
+ handleAddEntry(settings.create);
569
+ }}
570
+ >
571
+ <CirclePlus strokeWidth={2} size={16} />
572
+ </button>
573
+ )}
574
+ </div>
575
+ );
576
+ case 'dynamicdata':
577
+ return (
578
+ <div
579
+ className="fi__div"
580
+ style={
581
+ settings.height
582
+ ? {
583
+ height: settings.height,
584
+ paddingTop: '10px',
585
+ marginLeft: '13px',
586
+ }
587
+ : {
588
+ paddingTop: '10px',
589
+ marginLeft: '13px',
590
+ }
591
+ }
592
+ >
593
+ {inputValue && inputValue !== 'null' ? inputValue : ''}
594
+ </div>
595
+ );
596
+ case 'file':
597
+ if (
598
+ settings.hasOwnProperty('multiple') &&
599
+ settings.multiple === true
600
+ ) {
601
+ return (
602
+ <>
603
+ <input
604
+ type="file"
605
+ multiple
606
+ data-name={settings.id}
607
+ className={inputClass[settings.id]}
608
+ onChange={onChange}
609
+ />
610
+ {inputValue && inputValue.length > 0 && (
611
+ <ul className="file-list">
612
+ {inputValue.map((file, index) => (
613
+ <li
614
+ key={`file-${settings.id}-${index}`}
615
+ >
616
+ {file.name}
617
+ <button
618
+ className="trash-button"
619
+ onClick={(e) => {
620
+ e.preventDefault();
621
+ e.stopPropagation();
622
+
623
+ const updatedFiles =
624
+ inputValue.filter(
625
+ (_, fileIndex) =>
626
+ fileIndex !==
627
+ index
628
+ );
629
+
630
+ setFormData(
631
+ (prevFormData) => ({
632
+ ...prevFormData,
633
+ [settings.id]:
634
+ updatedFiles,
635
+ })
636
+ );
637
+ }}
638
+ >
639
+ <TrashCan
640
+ data-tooltip-id="system-tooltip"
641
+ data-tooltip-content="Remove File"
642
+ strokeWidth={2}
643
+ size={24}
644
+ />
645
+ </button>
646
+ </li>
647
+ ))}
648
+ </ul>
649
+ )}
650
+ </>
651
+ );
652
+ } else {
653
+ return (
654
+ <div
655
+ style={{
656
+ display: 'inline-flex',
657
+ alignItems: 'center',
658
+ }}
659
+ >
660
+ <label
661
+ htmlFor={settings.id}
662
+ style={{
663
+ padding: '6px 12px',
664
+ border: '1px solid #ccc',
665
+ display: 'inline-block',
666
+ backgroundColor: '#f8f8f8',
667
+ cursor: 'pointer',
668
+ }}
669
+ >
670
+ {inputValue?.filename
671
+ ? 'Replace File...'
672
+ : 'Choose file...'}
673
+ </label>
674
+ <input
675
+ id={settings.id}
676
+ data-name={settings.id}
677
+ name={settings.id}
678
+ type="file"
679
+ className={inputClass[settings.id]}
680
+ onChange={onChange}
681
+ style={{ display: 'none' }}
682
+ />
683
+ <span style={{ marginLeft: '10px' }}>
684
+ {inputValue
685
+ ? inputValue.filename
686
+ ? inputValue.filename
687
+ : inputValue.name
688
+ ? inputValue.name
689
+ : ''
690
+ : ''}
691
+ </span>
692
+ {inputValue &&
693
+ inputValue.key &&
694
+ inputValue.uuid && (
695
+ <div
696
+ style={{
697
+ marginLeft: '10px',
698
+ cursor: 'pointer',
699
+ }}
700
+ data-tooltip-id="system-tooltip"
701
+ data-tooltip-content={
702
+ inputValue.filename
703
+ }
704
+ onClick={(e) => {
705
+ e.preventDefault();
706
+ onFileDownload(inputValue);
707
+ }}
708
+ >
709
+ <CloudDownload size={24} />
710
+ </div>
711
+ )}
712
+ </div>
713
+ );
714
+ }
715
+ case 'gallery':
716
+ let htmlContainer = '';
717
+
718
+ if (formData[settings.key] && formData[settings.key] > 0) {
719
+ const dropzoneUrl = `${settings.url}/${
720
+ formData[settings.key]
721
+ }`;
722
+
723
+ htmlContainer = (
724
+ <VisnsDropZone
725
+ fetchData={fetchData}
726
+ files={formData[settings.id]}
727
+ settings={{
728
+ url: dropzoneUrl,
729
+ method: settings.method,
730
+ type: 'gallery',
731
+ data: settings.data,
732
+ }}
733
+ />
734
+ );
735
+ }
736
+
737
+ return htmlContainer;
738
+ case 'html5_date':
739
+ return (
740
+ <input
741
+ type="date"
742
+ data-name={settings.id}
743
+ className={inputClass[settings.id]}
744
+ placeholder=" "
745
+ onChange={onChange}
746
+ value={
747
+ inputValue && inputValue !== 'null'
748
+ ? inputValue
749
+ : ''
750
+ }
751
+ autoComplete="off"
752
+ />
753
+ );
754
+ case 'html5_datetime':
755
+ return (
756
+ <input
757
+ type="datetime-local"
758
+ data-name={settings.id}
759
+ className={inputClass[settings.id]}
760
+ placeholder=" "
761
+ onChange={onChange}
762
+ value={
763
+ inputValue && inputValue !== 'null'
764
+ ? inputValue
765
+ : ''
766
+ }
767
+ autoComplete="off"
768
+ />
769
+ );
770
+ case 'html5_time':
771
+ return (
772
+ <input
773
+ type="time"
774
+ data-name={settings.id}
775
+ className={inputClass[settings.id]}
776
+ placeholder=" "
777
+ onChange={onChange}
778
+ value={
779
+ inputValue && inputValue !== 'null'
780
+ ? inputValue
781
+ : ''
782
+ }
783
+ autoComplete="off"
784
+ />
785
+ );
786
+ case 'image':
787
+ return (
788
+ <div
789
+ style={{
790
+ position: 'relative',
791
+ display: 'inline-flex',
792
+ alignItems: 'center',
793
+ cursor: 'pointer',
794
+ }}
795
+ >
796
+ <input
797
+ type="file"
798
+ data-name={settings.id}
799
+ className={inputClass[settings.id]}
800
+ onChange={onChange}
801
+ ref={fileImageInputRef}
802
+ style={{
803
+ position: 'absolute',
804
+ left: 0,
805
+ top: 0,
806
+ width: '100%',
807
+ height: '100%',
808
+ opacity: 0,
809
+ cursor: 'pointer',
810
+ }}
811
+ />
812
+ {inputValue.imageSrc ? (
813
+ <img
814
+ src={inputValue.imageSrc}
815
+ alt="Uploaded"
816
+ style={{
817
+ marginLeft: '10px',
818
+ maxHeight: '100px',
819
+ }}
820
+ />
821
+ ) : (
822
+ <img
823
+ src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAJ3UlEQVR4nO3b60/aXhwG8KflJijIJQgTt8y5mLkxl73w//8HzBbdXLLFqJsg3rjKnUJ/L0wJpYUC9ovbL8/nlRbac077tOf0tCiHh4c6iFymPncF6P+JwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEvEfmhiBahNiQpEAAAAASUVORK5CYII="
824
+ alt="Placeholder"
825
+ />
826
+ )}
827
+ </div>
828
+ );
829
+ case 'json':
830
+ return (
831
+ <input
832
+ type={settings.type}
833
+ data-name={settings.id}
834
+ data-parent={settings.parent}
835
+ className={inputClass[settings.id]}
836
+ placeholder=" "
837
+ onChange={onChange}
838
+ value={
839
+ inputValue && inputValue !== 'null'
840
+ ? inputValue
841
+ : ''
842
+ }
843
+ autoComplete="off"
844
+ />
845
+ );
846
+ case 'line-break':
847
+ return (
848
+ <div className="formbreak">
849
+ <span>
850
+ {settings.label}{' '}
851
+ {settings.required === true ? '*' : ''}
852
+ </span>
853
+ </div>
854
+ );
855
+ case 'mobile':
856
+ case 'phone':
857
+ return (
858
+ <PatternFormat
859
+ className={inputClass[settings.id]}
860
+ onValueChange={(values) => {
861
+ onChangeNumberFormat(values, settings.id);
862
+ }}
863
+ format={
864
+ settings.type === 'phone'
865
+ ? '## #### ####'
866
+ : '#### ### ###'
867
+ }
868
+ allowEmptyFormatting
869
+ mask="_"
870
+ value={
871
+ inputValue && inputValue !== 'null'
872
+ ? inputValue
873
+ : ''
874
+ }
875
+ />
876
+ );
877
+ case 'multi-dropdown':
878
+ case 'multi-dropdown-ajax':
879
+ return (
880
+ <div className={styles.dropdownContainer}>
881
+ <MultiSelect
882
+ settings={settings}
883
+ className={
884
+ settings.create ? styles.selectFullWidth : ''
885
+ }
886
+ multi={
887
+ settings.hasOwnProperty('multi')
888
+ ? settings.multi
889
+ : false
890
+ }
891
+ onChange={onChangeSelect}
892
+ inputValue={
893
+ inputValue === null || inputValue === undefined
894
+ ? ''
895
+ : inputValue
896
+ }
897
+ options={
898
+ settings.type === 'multi-dropdown'
899
+ ? settings.options
900
+ : options
901
+ }
902
+ dataOptions={dataOptions}
903
+ style={style}
904
+ />
905
+ {settings.create && (
906
+ <button
907
+ className={styles.buttonRight}
908
+ onClick={(e) => {
909
+ e.preventDefault();
910
+
911
+ handleAddEntry(settings.create);
912
+ }}
913
+ >
914
+ <CirclePlus strokeWidth={2} size={16} />
915
+ </button>
916
+ )}
917
+ </div>
918
+ );
919
+ case 'percentage':
920
+ return (
921
+ <NumericFormat
922
+ data-name={settings.id}
923
+ className={inputClass[settings.id]}
924
+ onValueChange={(values) => {
925
+ onChangeNumberFormat(values, settings.id);
926
+ }}
927
+ thousandSeparator={true}
928
+ suffix={'%'}
929
+ value={
930
+ inputValue && inputValue !== 'null'
931
+ ? inputValue
932
+ : ''
933
+ }
934
+ />
935
+ );
936
+ case 'plaintext':
937
+ return (
938
+ <div
939
+ className="fi__div"
940
+ style={
941
+ settings.height
942
+ ? {
943
+ height: settings.height,
944
+ paddingTop: '10px',
945
+ marginLeft: '13px',
946
+ }
947
+ : {
948
+ paddingTop: '10px',
949
+ marginLeft: '13px',
950
+ }
951
+ }
952
+ >
953
+ {inputValue && inputValue !== 'null' ? inputValue : ''}
954
+ </div>
955
+ );
956
+ case 'plaintextheading':
957
+ return (
958
+ <div
959
+ className="fi__div"
960
+ style={
961
+ settings.height
962
+ ? {
963
+ height: settings.height,
964
+ }
965
+ : {}
966
+ }
967
+ >
968
+ {inputValue && inputValue !== 'null'
969
+ ? `<h2>${inputValue}</h2>`
970
+ : ''}
971
+ </div>
972
+ );
973
+ case 'plainrelation':
974
+ return (
975
+ <div
976
+ className="fi__div"
977
+ style={
978
+ settings.height
979
+ ? {
980
+ height: settings.height,
981
+ }
982
+ : {}
983
+ }
984
+ >
985
+ {renderRelationText(inputValue)}
986
+ </div>
987
+ );
988
+ case 'plainrelationarray':
989
+ return (
990
+ <div
991
+ className="fi__div"
992
+ style={
993
+ settings.height
994
+ ? {
995
+ height: settings.height,
996
+ }
997
+ : {}
998
+ }
999
+ >
1000
+ {renderRelationArrayText(inputValue)}
1001
+ </div>
1002
+ );
1003
+ case 'plaindate':
1004
+ return (
1005
+ <div
1006
+ className="fi__div"
1007
+ style={
1008
+ settings.height
1009
+ ? {
1010
+ height: settings.height,
1011
+ }
1012
+ : {}
1013
+ }
1014
+ >
1015
+ {inputValue && inputValue !== 'null'
1016
+ ? moment(inputValue).format('DD-MM-YYYY')
1017
+ : ''}
1018
+ </div>
1019
+ );
1020
+ case 'plaindatetime':
1021
+ return (
1022
+ <div
1023
+ className="fi__div"
1024
+ style={
1025
+ settings.height ? { height: settings.height } : {}
1026
+ }
1027
+ >
1028
+ {inputValue && inputValue !== 'null'
1029
+ ? moment(inputValue).format('DD-MM-YYYY hh:mm A')
1030
+ : ''}
1031
+ </div>
1032
+ );
1033
+ case 'radio':
1034
+ return settings.options?.length > 0 ? (
1035
+ <div className="fi__optionscontainer">
1036
+ {settings.options.map((option, index) => (
1037
+ <div
1038
+ key={`${settings.id}-checkbox-option-${index}`}
1039
+ className="fi__checkboxcontainer"
1040
+ >
1041
+ <input
1042
+ name={settings.id}
1043
+ data-name={settings.id}
1044
+ type="radio"
1045
+ className="fi__customcheckbox"
1046
+ value={option.id}
1047
+ checked={
1048
+ parseInt(inputValue) ===
1049
+ parseInt(option.id)
1050
+ }
1051
+ onChange={onChange}
1052
+ />
1053
+ <label className="fi__checkboxlabel">
1054
+ {option.label}
1055
+ </label>{' '}
1056
+ </div>
1057
+ ))}
1058
+ </div>
1059
+ ) : null;
1060
+ case 'radio-ajax':
1061
+ return options?.length > 0 ? (
1062
+ <div className="fi__optionscontainer">
1063
+ {options.map((option, index) => (
1064
+ <div
1065
+ key={`${settings.id}-checkbox-option-${index}`}
1066
+ className="fi__checkboxcontainer"
1067
+ >
1068
+ <input
1069
+ name={settings.id}
1070
+ data-name={settings.id}
1071
+ type="radio"
1072
+ className="fi__customcheckbox"
1073
+ value={option.id}
1074
+ checked={
1075
+ parseInt(inputValue) ===
1076
+ parseInt(option.id)
1077
+ }
1078
+ onChange={onChange}
1079
+ />
1080
+ <label className="fi__checkboxlabel">
1081
+ {option.label}
1082
+ </label>{' '}
1083
+ </div>
1084
+ ))}
1085
+ </div>
1086
+ ) : null;
1087
+ case 'richeditor':
1088
+ return (
1089
+ <Editor
1090
+ tinymceScriptSrc="https://d16lktya8ojp5z.cloudfront.net/generic/packages/tinymce_v701/tinymce.min.js"
1091
+ licenseKey="gpl"
1092
+ onEditorChange={(value, e) => {
1093
+ onChangeRicheditor(e, value, settings.id);
1094
+ }}
1095
+ onInit={(evt, editor) => (editorRef.current = editor)}
1096
+ value={inputValue || ''}
1097
+ init={{
1098
+ branding: false,
1099
+ height: settings.height ? settings.height : 500,
1100
+ menubar: false,
1101
+ plugins: [
1102
+ 'advlist',
1103
+ 'autolink',
1104
+ 'lists',
1105
+ 'link',
1106
+ 'image',
1107
+ 'charmap',
1108
+ 'preview',
1109
+ 'anchor',
1110
+ 'searchreplace',
1111
+ 'visualblocks',
1112
+ 'code',
1113
+ 'fullscreen',
1114
+ 'insertdatetime',
1115
+ 'media',
1116
+ 'table',
1117
+ 'code',
1118
+ ],
1119
+ toolbar:
1120
+ 'undo redo | blocks | ' +
1121
+ 'bold italic forecolor | alignleft aligncenter ' +
1122
+ 'alignright alignjustify | bullist numlist outdent indent | ' +
1123
+ 'removeformat | table',
1124
+ content_style:
1125
+ 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }',
1126
+ }}
1127
+ />
1128
+ );
1129
+ case 'signature':
1130
+ return (
1131
+ <>
1132
+ {inputValue.signature ? (
1133
+ <div className={styles.signaturePlaceholder}>
1134
+ <img
1135
+ src={inputValue.signature}
1136
+ alt="Signature"
1137
+ className={styles.signatureImage}
1138
+ />
1139
+ <p>
1140
+ <strong>Name:</strong>{' '}
1141
+ {inputValue.name ? inputValue.name : null}
1142
+ </p>
1143
+ <p>
1144
+ <strong>Date:</strong>{' '}
1145
+ {inputValue.date
1146
+ ? moment(inputValue.date).format(
1147
+ 'DD-MM-YYYY'
1148
+ )
1149
+ : null}
1150
+ </p>
1151
+ </div>
1152
+ ) : (
1153
+ <button
1154
+ type="button"
1155
+ className={styles.signButton}
1156
+ onClick={(e) => {
1157
+ e.preventDefault();
1158
+
1159
+ if (settings.role) {
1160
+ if (
1161
+ userProfile?.roles[0]?.name ===
1162
+ settings.role
1163
+ ) {
1164
+ onChangeSignature(settings.id);
1165
+ } else {
1166
+ toast.error(
1167
+ `A user with the role of ${settings.role} is required to sign this document`
1168
+ );
1169
+ }
1170
+ } else {
1171
+ onChangeSignature(settings.id);
1172
+ }
1173
+ }}
1174
+ >
1175
+ Click to Sign
1176
+ </button>
1177
+ )}
1178
+ </>
1179
+ );
1180
+ case 'table_radio':
1181
+ let tableRadioColumns = [];
1182
+ let tableRadioRows = [];
1183
+
1184
+ for (const key in formData) {
1185
+ if (formData[key].id === settings.id) {
1186
+ if (formData[key].hasOwnProperty('options')) {
1187
+ tableRadioColumns = formData[key].options;
1188
+ tableRadioRows = formData[key].rows;
1189
+ break; // Assuming there's only one match needed, break out of the loop
1190
+ }
1191
+ }
1192
+ }
1193
+
1194
+ return (
1195
+ <table className={styles.contentTable}>
1196
+ <thead>
1197
+ <tr>
1198
+ <th></th>
1199
+ {tableRadioColumns.map((column) => (
1200
+ <th
1201
+ key={`${settings.id}-${column.id}`}
1202
+ style={{
1203
+ width: '250px',
1204
+ whiteSpace: 'nowrap',
1205
+ }}
1206
+ >
1207
+ {column.label}
1208
+ </th>
1209
+ ))}
1210
+ </tr>
1211
+ </thead>
1212
+ <tbody>
1213
+ {tableRadioRows.map((row) => (
1214
+ <tr
1215
+ key={`table-radio-row-${settings.id}-${row.id}`}
1216
+ >
1217
+ <td
1218
+ style={{
1219
+ whiteSpace: 'nowrap',
1220
+ }}
1221
+ >
1222
+ {row.label}
1223
+ </td>
1224
+ {tableRadioColumns.map((column) => (
1225
+ <td
1226
+ key={`table-radio-cell-${settings.id}-${row.id}-${column.id}`}
1227
+ >
1228
+ <input
1229
+ type="checkbox"
1230
+ name={row.id}
1231
+ data-row-id={row.id}
1232
+ data-column-id={column.id}
1233
+ data-id={settings.id}
1234
+ onChange={onChangeTableRadio}
1235
+ checked={
1236
+ row.value?.[column.id] ===
1237
+ true
1238
+ }
1239
+ />
1240
+ </td>
1241
+ ))}
1242
+ </tr>
1243
+ ))}
1244
+ </tbody>
1245
+ </table>
1246
+ );
1247
+ case 'table_text':
1248
+ let tableTextColumns = [];
1249
+ let tableTextValues = [];
1250
+
1251
+ for (const key in formData) {
1252
+ if (formData[key].id === settings.id) {
1253
+ if (formData[key].hasOwnProperty('options')) {
1254
+ tableTextColumns = formData[key].options;
1255
+ tableTextValues = formData[key].value;
1256
+ break; // Assuming there's only one match needed, break out of the loop
1257
+ }
1258
+ }
1259
+ }
1260
+ return (
1261
+ <table className={styles.contentTable}>
1262
+ <thead>
1263
+ <tr>
1264
+ {tableTextColumns.map((column, columnKey) => (
1265
+ <th
1266
+ key={`${settings.id}-${column.id}-${columnKey}`}
1267
+ >
1268
+ {column.label}
1269
+ </th>
1270
+ ))}
1271
+ <th style={{ textAlign: 'center' }}>
1272
+ <CirclePlus
1273
+ onClick={() => {
1274
+ onChangeAddTableTextRow(
1275
+ settings.id
1276
+ );
1277
+ }}
1278
+ size={24}
1279
+ data-id={settings.id}
1280
+ />
1281
+ </th>
1282
+ </tr>
1283
+ </thead>
1284
+ <tbody>
1285
+ {tableTextValues?.length > 0 &&
1286
+ tableTextValues?.map((row, rowKey) => (
1287
+ <tr
1288
+ key={`${settings.id}-${row.id}-${rowKey}-row`}
1289
+ >
1290
+ {row?.map((cell, cellKey) => (
1291
+ <td
1292
+ key={`${settings.id}}-${cellKey}-input`}
1293
+ >
1294
+ {tableTextColumns[cellKey]
1295
+ .type === 'checkbox' ? (
1296
+ <input
1297
+ type={'checkbox'}
1298
+ checked={cell || false}
1299
+ data-id={settings.id}
1300
+ onChange={(e) =>
1301
+ onChangeTableText(
1302
+ e,
1303
+ rowKey,
1304
+ cellKey
1305
+ )
1306
+ }
1307
+ />
1308
+ ) : (
1309
+ <input
1310
+ type={'text'}
1311
+ value={cell || ''}
1312
+ data-id={settings.id}
1313
+ onChange={(e) =>
1314
+ onChangeTableText(
1315
+ e,
1316
+ rowKey,
1317
+ cellKey
1318
+ )
1319
+ }
1320
+ />
1321
+ )}
1322
+ </td>
1323
+ ))}
1324
+ </tr>
1325
+ ))}
1326
+ </tbody>
1327
+ </table>
1328
+ );
1329
+ case 'textarea':
1330
+ return (
1331
+ <textarea
1332
+ data-name={settings.id}
1333
+ className={inputClass[settings.id]}
1334
+ onChange={onChange}
1335
+ value={
1336
+ inputValue && inputValue !== 'null'
1337
+ ? inputValue
1338
+ : ''
1339
+ }
1340
+ style={{ height: '200px' }}
1341
+ ></textarea>
1342
+ );
1343
+ case 'text':
1344
+ case 'password':
1345
+ return (
1346
+ <input
1347
+ type={settings.type}
1348
+ data-name={settings.id}
1349
+ className={inputClass[settings.id]}
1350
+ placeholder=" "
1351
+ onChange={onChange}
1352
+ value={
1353
+ inputValue && inputValue !== 'null'
1354
+ ? inputValue
1355
+ : ''
1356
+ }
1357
+ readOnly={settings.readOnly ? settings.readOnly : false}
1358
+ autoComplete="off"
1359
+ />
1360
+ );
1361
+ default:
1362
+ return '';
1363
+ }
1364
+ };
1365
+
1366
+ const renderFieldLabel = () => {
1367
+ if (
1368
+ ![
1369
+ 'address',
1370
+ 'async-dropdown-ajax',
1371
+ 'checkbox',
1372
+ 'colour',
1373
+ 'copytoclipboard',
1374
+ 'date',
1375
+ 'datetime',
1376
+ 'dropdown',
1377
+ 'dropdown-ajax',
1378
+ 'dynamicdata',
1379
+ 'file',
1380
+ 'gallery',
1381
+ 'image',
1382
+ 'line-break',
1383
+ 'multi-dropdown',
1384
+ 'multi-dropdown-ajax',
1385
+ 'plaindate',
1386
+ 'plaindatetime',
1387
+ 'plainrelation',
1388
+ 'plainrelationarray',
1389
+ 'plaintext',
1390
+ 'plaintextheading',
1391
+ 'radio',
1392
+ 'radio-ajax',
1393
+ 'richeditor',
1394
+ 'signature',
1395
+ 'table_radio',
1396
+ 'table_text',
1397
+ 'time',
1398
+ 'toggle',
1399
+ ].includes(settings.type)
1400
+ ) {
1401
+ return (
1402
+ <span className={styles.fi__span}>
1403
+ {settings.label} {settings.required ? '*' : ''}
1404
+ </span>
1405
+ );
1406
+ }
1407
+ };
1408
+
1409
+ const renderAdditionalContainer = () => {
1410
+ switch (settings.type) {
1411
+ case 'date':
1412
+ case 'datetime':
1413
+ return (
1414
+ <DatePicker
1415
+ dateFormat={
1416
+ settings.format
1417
+ ? settings.format
1418
+ : settings.type === 'datetime'
1419
+ ? 'dd-MM-yyyy hh:mm aa'
1420
+ : 'dd-MM-yyyy'
1421
+ }
1422
+ isClearable
1423
+ className={inputClass[settings.id]}
1424
+ selected={inputValue || ''}
1425
+ showMonthDropdown
1426
+ showYearDropdown
1427
+ scrollableYearDropdown
1428
+ onChange={(date) => onChangeDate(date, settings.id)}
1429
+ showTimeSelect={settings.type === 'datetime'}
1430
+ showTimeSelectOnly={settings.type === 'time'}
1431
+ timeIntervals={
1432
+ settings.type === 'time' ? 15 : undefined
1433
+ }
1434
+ timeCaption={
1435
+ settings.type === 'time' ? 'Time' : undefined
1436
+ }
1437
+ shouldCloseOnSelect={true}
1438
+ />
1439
+ );
1440
+ case 'time':
1441
+ return (
1442
+ <DatePicker
1443
+ dateFormat="hh:mm aa"
1444
+ isClearable
1445
+ className={inputClass[settings.id]}
1446
+ selected={inputValue || ''}
1447
+ showMonthDropdown
1448
+ showYearDropdown
1449
+ scrollableYearDropdown
1450
+ onChange={(date) => onChangeDate(date, settings.id)}
1451
+ showTimeSelect={true}
1452
+ showTimeSelectOnly={true}
1453
+ timeIntervals={15}
1454
+ timeCaption={'Time'}
1455
+ shouldCloseOnSelect={true}
1456
+ />
1457
+ );
1458
+ case 'toggle':
1459
+ return (
1460
+ <div>
1461
+ <Toggle
1462
+ name={settings.id}
1463
+ data-name={settings.id}
1464
+ data-show={
1465
+ settings.show
1466
+ ? JSON.stringify(settings.show)
1467
+ : ''
1468
+ }
1469
+ checked={
1470
+ inputValue !== undefined
1471
+ ? inputValue === ''
1472
+ ? false
1473
+ : inputValue === 'on'
1474
+ ? false
1475
+ : inputValue
1476
+ : false
1477
+ }
1478
+ onChange={onChangeToggle}
1479
+ />
1480
+ <span className={styles.fi__toggletxt}>
1481
+ {settings.label} {settings.required ? '*' : ''}
1482
+ </span>
1483
+ </div>
1484
+ );
1485
+ default:
1486
+ return '';
1487
+ }
1488
+ };
1489
+
1490
+ /** Child Form */
1491
+ const [childForm, setChildForm] = useState({});
1492
+ const [childFormShow, setChildFormShow] = useState(false);
1493
+
1494
+ const childFormClose = () => {
1495
+ setChildFormShow(false);
1496
+ setChildForm({});
1497
+ };
1498
+
1499
+ const childFormOpen = () => {
1500
+ setChildFormShow(true);
1501
+ };
1502
+
1503
+ const handleAddEntry = (form) => {
1504
+ if (form) {
1505
+ let f = form;
1506
+
1507
+ form.fields.forEach((item, itemKey) => {
1508
+ if (item.hasOwnProperty('dataId') && formData[item.dataId]) {
1509
+ f.fields[itemKey].value = formData[item.dataId].value
1510
+ ? formData[item.dataId].value
1511
+ : formData[item.dataId];
1512
+ }
1513
+ });
1514
+
1515
+ setChildForm(f);
1516
+ childFormOpen();
1517
+ }
1518
+ };
1519
+
1520
+ const handleReload = () => {
1521
+ setCounter(counter + 1);
1522
+ };
1523
+
1524
+ return (
1525
+ <div className={formItemClass} style={formItemStyle}>
1526
+ <label className={styles.fi__label}>
1527
+ {renderLabel()}
1528
+ {renderInput()}
1529
+ {renderFieldLabel()}
1530
+ </label>
1531
+ {renderAdditionalContainer()}
1532
+ <Popup
1533
+ open={childFormShow}
1534
+ onClose={childFormClose}
1535
+ closeOnDocumentClick={false}
1536
+ >
1537
+ <Form
1538
+ ajaxSetting={childForm.ajaxSetting}
1539
+ api={api}
1540
+ closeModal={childFormClose}
1541
+ columnId={0}
1542
+ fetchTable={handleReload}
1543
+ formSettings={childForm}
1544
+ formType={'create'}
1545
+ gridRef={null}
1546
+ mapbox={null}
1547
+ modalOpen={childFormOpen}
1548
+ paramValue={null}
1549
+ style={style}
1550
+ updateForm={setChildForm}
1551
+ />
1552
+ </Popup>
1553
+ </div>
1554
+ );
1555
+ }
1556
+
1557
+ export default Field;