@visns-studio/visns-components 1.0.7 → 1.0.9

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.
@@ -0,0 +1,700 @@
1
+ import React, { useState, useEffect, useRef } from "react";
2
+ import CustomFetch from "../crm/visns-fetch";
3
+ import Select from "../crm/visns-select";
4
+ import MultiSelect from "../crm/visns-multi-select";
5
+ import VisnsAutocomplete from "../crm/visns-autocomplete";
6
+ import DatePicker from "react-datepicker";
7
+ import _ from "lodash";
8
+ import ReactQuill from "react-quill";
9
+ import Toggle from "react-toggle";
10
+ import { NumericFormat, PatternFormat } from "react-number-format";
11
+ import { motion } from "framer-motion";
12
+ import "react-toggle/style.css";
13
+ import "react-quill/dist/quill.snow.css";
14
+ import "react-datepicker/dist/react-datepicker.css";
15
+
16
+ function Field(props) {
17
+ const inputFile = useRef(null);
18
+ const [options, setOptions] = useState([]);
19
+ const [dataOptions, setDataOptions] = useState([]);
20
+ const [formItemStyle, setFormItemStyle] = useState({});
21
+ const [formItemClass, setFormItemClass] = useState("formItem");
22
+ const {
23
+ settings,
24
+ inputValue,
25
+ inputClass,
26
+ alertStateChange,
27
+ onChange,
28
+ onChangeFile,
29
+ onChangeRicheditor,
30
+ onChangeSelect,
31
+ setFormData,
32
+ uploadProgress,
33
+ } = props;
34
+
35
+ useEffect(() => {
36
+ switch (settings.type) {
37
+ case "hidden":
38
+ setFormItemStyle({
39
+ display: "none",
40
+ });
41
+ break;
42
+ case "dropdown-ajax":
43
+ let filter = {};
44
+
45
+ if (
46
+ settings.hasOwnProperty("where") &&
47
+ settings.where.length > 0
48
+ ) {
49
+ filter = {
50
+ where: settings.where,
51
+ };
52
+ }
53
+
54
+ CustomFetch(
55
+ settings.url,
56
+ "POST",
57
+ filter,
58
+ function (result) {
59
+ setOptions(result.data);
60
+
61
+ let dataArray = [];
62
+
63
+ result.data.forEach((a) => {
64
+ let _tempObject = a;
65
+
66
+ if (!_.isEmpty(_tempObject)) {
67
+ let modifiedObject = {};
68
+
69
+ Object.keys(_tempObject).forEach(function (c) {
70
+ if (c !== "id" && c !== "label") {
71
+ modifiedObject["data-" + c] =
72
+ _tempObject[c];
73
+ }
74
+ });
75
+
76
+ dataArray.push(modifiedObject);
77
+ }
78
+ });
79
+
80
+ if (dataArray.length > 0) {
81
+ setDataOptions(dataArray);
82
+ }
83
+ },
84
+ function (error) {
85
+ alertStateChange({
86
+ show: true,
87
+ alertClass: "dialog error",
88
+ alertText: String(error),
89
+ });
90
+ }
91
+ );
92
+ break;
93
+ case "multi-dropdown-ajax":
94
+ let multiFilter = {};
95
+
96
+ if (
97
+ settings.hasOwnProperty("where") &&
98
+ settings.where.length > 0
99
+ ) {
100
+ multiFilter = {
101
+ where: settings.where,
102
+ };
103
+ }
104
+
105
+ CustomFetch(
106
+ settings.url,
107
+ "POST",
108
+ multiFilter,
109
+ function (result) {
110
+ setOptions(result.data);
111
+
112
+ let dataArray = [];
113
+
114
+ result.data.forEach((a) => {
115
+ let _tempObject = a;
116
+
117
+ if (!_.isEmpty(_tempObject)) {
118
+ let modifiedObject = {};
119
+
120
+ Object.keys(_tempObject).forEach(function (c) {
121
+ if (c !== "id" && c !== "label") {
122
+ modifiedObject["data-" + c] =
123
+ _tempObject[c];
124
+ }
125
+ });
126
+
127
+ dataArray.push(modifiedObject);
128
+ }
129
+ });
130
+
131
+ if (dataArray.length > 0) {
132
+ setDataOptions(dataArray);
133
+ }
134
+ },
135
+ function (error) {
136
+ alertStateChange({
137
+ show: true,
138
+ alertClass: "dialog error",
139
+ alertText: String(error),
140
+ });
141
+ }
142
+ );
143
+ break;
144
+ default:
145
+ break;
146
+ }
147
+
148
+ if (settings.size === "full") {
149
+ setFormItemClass("formItem fwItem");
150
+ }
151
+ }, [settings]);
152
+
153
+ useEffect(() => {
154
+ let filter = {};
155
+
156
+ if (settings.hasOwnProperty("child")) {
157
+ if (inputValue > 0) {
158
+ filter = {
159
+ where: [
160
+ {
161
+ id: settings.id,
162
+ value: inputValue,
163
+ },
164
+ ],
165
+ };
166
+
167
+ CustomFetch(
168
+ settings.child.url,
169
+ "POST",
170
+ filter,
171
+ function (result) {
172
+ childDropdownCallback({
173
+ id: settings.child.id,
174
+ data: result.data,
175
+ });
176
+ },
177
+ function (error) {
178
+ alertStateChange({
179
+ show: true,
180
+ alertClass: "dialog error",
181
+ alertText: String(error),
182
+ });
183
+ }
184
+ );
185
+ }
186
+ }
187
+ }, [inputValue, settings]);
188
+
189
+ useEffect(() => {
190
+ if (settings.hasOwnProperty("options")) {
191
+ if (settings.options.length > 0) {
192
+ let dataArray = [];
193
+
194
+ settings.options.forEach((a) => {
195
+ let _tempObject = a;
196
+
197
+ if (!_.isEmpty(_tempObject)) {
198
+ let modifiedObject = {};
199
+
200
+ Object.keys(_tempObject).forEach(function (c) {
201
+ if (c !== "id" && c !== "label") {
202
+ modifiedObject["data-" + c] = _tempObject[c];
203
+ }
204
+ });
205
+
206
+ dataArray.push(modifiedObject);
207
+ }
208
+ });
209
+
210
+ if (dataArray.length > 0) {
211
+ setDataOptions(dataArray);
212
+ }
213
+ }
214
+ }
215
+ }, [settings.options, settings]);
216
+
217
+ return (
218
+ <div className={formItemClass} style={formItemStyle}>
219
+ <label
220
+ className={
221
+ settings.type === "image"
222
+ ? "fi__flabel"
223
+ : settings.type === "richeditor"
224
+ ? "fi__flabel"
225
+ : "fi__label"
226
+ }
227
+ >
228
+ {(() => {
229
+ if (
230
+ settings.type === "address" ||
231
+ settings.type === "date" ||
232
+ settings.type === "datetime" ||
233
+ settings.type === "checkbox" ||
234
+ settings.type === "multi-dropdown" ||
235
+ settings.type === "multi-dropdown-ajax"
236
+ ) {
237
+ return (
238
+ <span className="fi__span prefocus">
239
+ {settings.label}{" "}
240
+ {settings.required === true ? "*" : ""}
241
+ </span>
242
+ );
243
+ }
244
+ })()}
245
+
246
+ {(() => {
247
+ if (
248
+ settings.type === "image" ||
249
+ settings.type === "richeditor"
250
+ ) {
251
+ return (
252
+ <>
253
+ {settings.label}{" "}
254
+ {settings.required === true ? "*" : ""}
255
+ </>
256
+ );
257
+ }
258
+ })()}
259
+
260
+ {(() => {
261
+ let htmlContainer;
262
+ switch (settings.type) {
263
+ case "text":
264
+ htmlContainer = (
265
+ <input
266
+ type="text"
267
+ name={settings.id}
268
+ readOnly={
269
+ settings.hasOwnProperty("readOnly")
270
+ ? settings.readOnly
271
+ : false
272
+ }
273
+ className={inputClass[settings.id]}
274
+ placeholder=" "
275
+ onChange={onChange}
276
+ value={
277
+ inputValue && inputValue !== "null"
278
+ ? inputValue
279
+ : ""
280
+ }
281
+ />
282
+ );
283
+ break;
284
+ case "json":
285
+ htmlContainer = (
286
+ <input
287
+ type="text"
288
+ name={settings.id}
289
+ data-jsonkey={settings.key}
290
+ className={inputClass[settings.id]}
291
+ placeholder=" "
292
+ onChange={onChange}
293
+ value={
294
+ inputValue && inputValue !== "null"
295
+ ? inputValue
296
+ : ""
297
+ }
298
+ />
299
+ );
300
+ break;
301
+ case "password":
302
+ htmlContainer = (
303
+ <input
304
+ type="password"
305
+ name={settings.id}
306
+ className={inputClass[settings.id]}
307
+ placeholder=" "
308
+ onChange={onChange}
309
+ value={
310
+ inputValue && inputValue !== "null"
311
+ ? inputValue
312
+ : ""
313
+ }
314
+ />
315
+ );
316
+ break;
317
+ case "phone":
318
+ htmlContainer = (
319
+ <PatternFormat
320
+ name={settings.id}
321
+ className={inputClass[settings.id]}
322
+ onValueChange={(values) => {
323
+ onChangeNumberFormat(
324
+ values,
325
+ settings.id
326
+ );
327
+ }}
328
+ format="## #### ####"
329
+ allowEmptyFormatting
330
+ mask="_"
331
+ value={
332
+ inputValue && inputValue !== "null"
333
+ ? inputValue
334
+ : ""
335
+ }
336
+ />
337
+ );
338
+ break;
339
+ case "mobile":
340
+ htmlContainer = (
341
+ <PatternFormat
342
+ className={inputClass[settings.id]}
343
+ onValueChange={(values) => {
344
+ onChangeNumberFormat(
345
+ values,
346
+ settings.id
347
+ );
348
+ }}
349
+ format="#### ### ###"
350
+ allowEmptyFormatting
351
+ mask="_"
352
+ value={
353
+ inputValue && inputValue !== "null"
354
+ ? inputValue
355
+ : ""
356
+ }
357
+ />
358
+ );
359
+ break;
360
+ case "currency":
361
+ htmlContainer = (
362
+ <NumericFormat
363
+ name={settings.id}
364
+ className={inputClass[settings.id]}
365
+ onValueChange={(values) => {
366
+ onChangeNumberFormat(
367
+ values,
368
+ settings.id
369
+ );
370
+ }}
371
+ thousandSeparator={true}
372
+ prefix={"$"}
373
+ value={
374
+ inputValue && inputValue !== "null"
375
+ ? inputValue
376
+ : ""
377
+ }
378
+ />
379
+ );
380
+ break;
381
+ case "textarea":
382
+ htmlContainer = (
383
+ <textarea
384
+ name={settings.id}
385
+ className={inputClass[settings.id]}
386
+ onChange={onChange}
387
+ value={
388
+ inputValue && inputValue !== "null"
389
+ ? inputValue
390
+ : ""
391
+ }
392
+ style={{ height: "200px" }}
393
+ ></textarea>
394
+ );
395
+ break;
396
+ case "address":
397
+ htmlContainer = (
398
+ <VisnsAutocomplete
399
+ onSelect={(place) =>
400
+ autocompleteCallback(place)
401
+ }
402
+ field={settings.id}
403
+ setFormData={setFormData}
404
+ api="pk.eyJ1IjoidmlzbnMtc3R1ZGlvIiwiYSI6ImNrbGlraW5vZDBhMDYycHBsdmk5b3ljbGQifQ.ZGUBk0PWac5GahUeVHdTpg"
405
+ inputValue={inputValue}
406
+ />
407
+ );
408
+ break;
409
+ case "dropdown":
410
+ htmlContainer = (
411
+ <Select
412
+ settings={settings}
413
+ className={inputClass[settings.id]}
414
+ onChange={onChange}
415
+ inputValue={
416
+ inputValue === null ? "" : inputValue
417
+ }
418
+ options={settings.options}
419
+ dataOptions={dataOptions}
420
+ />
421
+ );
422
+ break;
423
+ case "dropdown-ajax":
424
+ htmlContainer = (
425
+ <Select
426
+ settings={settings}
427
+ className={inputClass[settings.id]}
428
+ onChange={onChange}
429
+ inputValue={
430
+ inputValue === null ? "" : inputValue
431
+ }
432
+ options={options}
433
+ dataOptions={dataOptions}
434
+ />
435
+ );
436
+ break;
437
+ case "multi-dropdown":
438
+ htmlContainer = (
439
+ <MultiSelect
440
+ settings={settings}
441
+ className={inputClass[settings.id]}
442
+ onChange={onChangeSelect}
443
+ inputValue={
444
+ inputValue === null ? "" : inputValue
445
+ }
446
+ options={settings.options}
447
+ dataOptions={dataOptions}
448
+ />
449
+ );
450
+ break;
451
+ case "multi-dropdown-ajax":
452
+ htmlContainer = (
453
+ <MultiSelect
454
+ settings={settings}
455
+ className={inputClass[settings.id]}
456
+ onChange={onChangeSelect}
457
+ inputValue={
458
+ inputValue === null ? "" : inputValue
459
+ }
460
+ options={options}
461
+ dataOptions={dataOptions}
462
+ />
463
+ );
464
+ break;
465
+ case "file":
466
+ htmlContainer = (
467
+ <input
468
+ type="file"
469
+ name={settings.id}
470
+ className={inputClass[settings.id]}
471
+ onChange={onChangeFile}
472
+ />
473
+ );
474
+ break;
475
+
476
+ case "line-break":
477
+ htmlContainer = (
478
+ <div className="formbreak">
479
+ <span>
480
+ {settings.label}{" "}
481
+ {settings.required === true ? "*" : ""}
482
+ </span>
483
+ </div>
484
+ );
485
+ break;
486
+ case "checkbox":
487
+ htmlContainer = (
488
+ <input
489
+ type="checkbox"
490
+ name={settings.id}
491
+ className={inputClass[settings.id]}
492
+ placeholder=" "
493
+ onChange={onChange}
494
+ value={inputValue || ""}
495
+ />
496
+ );
497
+ break;
498
+ default:
499
+ htmlContainer = "";
500
+ break;
501
+ }
502
+
503
+ return htmlContainer;
504
+ })()}
505
+
506
+ {(() => {
507
+ if (
508
+ settings.type !== "address" &&
509
+ settings.type !== "date" &&
510
+ settings.type !== "datetime" &&
511
+ settings.type !== "line-break" &&
512
+ settings.type !== "checkbox" &&
513
+ settings.type !== "multi-dropdown" &&
514
+ settings.type !== "multi-dropdown-ajax" &&
515
+ settings.type !== "toggle" &&
516
+ settings.type !== "richeditor" &&
517
+ settings.type !== "image"
518
+ ) {
519
+ return (
520
+ <span className="fi__span">
521
+ {settings.label}{" "}
522
+ {settings.required === true ? "*" : ""}
523
+ </span>
524
+ );
525
+ }
526
+ })()}
527
+ </label>
528
+
529
+ {(() => {
530
+ let htmlContainer;
531
+ switch (settings.type) {
532
+ case "date":
533
+ htmlContainer = (
534
+ <DatePicker
535
+ dateFormat={
536
+ settings.format
537
+ ? settings.format
538
+ : "dd-MM-yyyy"
539
+ }
540
+ className={inputClass[settings.id]}
541
+ selected={inputValue || ""}
542
+ showMonthDropdown
543
+ showYearDropdown
544
+ dropdownMode="select"
545
+ onChange={(date) =>
546
+ onChangeDate(date, settings.id)
547
+ }
548
+ />
549
+ );
550
+ break;
551
+ case "datetime":
552
+ htmlContainer = (
553
+ <DatePicker
554
+ dateFormat={
555
+ settings.format
556
+ ? settings.format
557
+ : "dd-MM-yyyy hh:mm aa"
558
+ }
559
+ showTimeSelect
560
+ className={inputClass[settings.id]}
561
+ selected={inputValue || null}
562
+ showMonthDropdown
563
+ showYearDropdown
564
+ dropdownMode="select"
565
+ onChange={(date) =>
566
+ onChangeDate(date, settings.id)
567
+ }
568
+ shouldCloseOnSelect={true}
569
+ />
570
+ );
571
+ break;
572
+ case "time":
573
+ htmlContainer = (
574
+ <DatePicker
575
+ dateFormat={
576
+ settings.format
577
+ ? settings.format
578
+ : "hh:mm aa"
579
+ }
580
+ showTimeSelect
581
+ showTimeSelectOnly
582
+ timeIntervals={15}
583
+ timeCaption="Time"
584
+ className={inputClass[settings.id]}
585
+ selected={inputValue || ""}
586
+ onChange={(date) =>
587
+ onChangeDate(date, settings.id)
588
+ }
589
+ shouldCloseOnSelect={true}
590
+ />
591
+ );
592
+ break;
593
+ case "toggle":
594
+ htmlContainer = (
595
+ <div>
596
+ <Toggle
597
+ name={settings.id}
598
+ data-show={
599
+ settings.show
600
+ ? JSON.stringify(settings.show)
601
+ : ""
602
+ }
603
+ checked={
604
+ inputValue !== undefined
605
+ ? inputValue === ""
606
+ ? false
607
+ : inputValue === "on"
608
+ ? false
609
+ : inputValue
610
+ : false
611
+ }
612
+ onChange={onChangeToggle}
613
+ />
614
+ <span className="fi__toggletxt">
615
+ {settings.label}{" "}
616
+ {settings.required === true ? "*" : ""}
617
+ </span>
618
+ </div>
619
+ );
620
+ break;
621
+ case "richeditor":
622
+ htmlContainer = (
623
+ <ReactQuill
624
+ theme="snow"
625
+ name={settings.id}
626
+ onChange={(value) => {
627
+ onChangeRicheditor(value, settings.id);
628
+ }}
629
+ value={inputValue || ""}
630
+ />
631
+ );
632
+ break;
633
+ case "image":
634
+ htmlContainer = (
635
+ <>
636
+ <motion.div
637
+ className="progress__bar"
638
+ initial={{ width: "0%" }}
639
+ animate={{
640
+ width:
641
+ uploadProgress[settings.id] + "%",
642
+ }}
643
+ transition={{
644
+ duration: 3,
645
+ ease: [0.165, 0.84, 0.44, 1.0],
646
+ }}
647
+ />
648
+ <input
649
+ type="file"
650
+ name={settings.id}
651
+ className={inputClass[settings.id]}
652
+ onChange={onChangeFile}
653
+ ref={inputFile}
654
+ style={{ display: "none" }}
655
+ />
656
+ <div
657
+ onClick={() => {
658
+ inputFile.current.click();
659
+ }}
660
+ >
661
+ {inputValue && inputValue !== "" ? (
662
+ <>
663
+ {inputValue.file_url &&
664
+ inputValue.file_url !== "" ? (
665
+ <img
666
+ src={inputValue.file_url}
667
+ width="200"
668
+ />
669
+ ) : (
670
+ <img
671
+ src={URL.createObjectURL(
672
+ inputValue
673
+ )}
674
+ width="200"
675
+ />
676
+ )}
677
+ </>
678
+ ) : (
679
+ <div className="imageupload">
680
+ <span>
681
+ Click here to upload an image
682
+ </span>
683
+ </div>
684
+ )}
685
+ </div>
686
+ </>
687
+ );
688
+ break;
689
+ default:
690
+ htmlContainer = "";
691
+ break;
692
+ }
693
+
694
+ return htmlContainer;
695
+ })()}
696
+ </div>
697
+ );
698
+ }
699
+
700
+ export default Field;
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useEffect } from "react";
2
- import CustomFetch from "../crm/visns-fetch";
3
- import Field from "../crm/visns-field";
2
+ import CustomFetch from "./crm/visns-fetch";
3
+ import Field from "./visns-field";
4
4
  import slugify from "react-slugify";
5
5
  import moment from "moment";
6
6
  import Reveal from "react-reveal/Reveal";
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "react-dom": ">=18.2.0"
31
31
  },
32
32
  "name": "@visns-studio/visns-components",
33
- "version": "1.0.7",
33
+ "version": "1.0.9",
34
34
  "description": "Various packages to assist in the development of our Custom Applications.",
35
35
  "main": "index.js",
36
36
  "devDependencies": {},