@visns-studio/visns-components 4.10.48 → 5.0.0

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 (41) hide show
  1. package/package.json +28 -30
  2. package/src/components/cms/Field.jsx +39 -63
  3. package/src/components/crm/Breadcrumb.jsx +2 -18
  4. package/src/components/crm/DataGrid.jsx +25 -419
  5. package/src/components/crm/Field.jsx +16 -215
  6. package/src/components/crm/Form.jsx +86 -87
  7. package/src/components/crm/MultiSelect.jsx +25 -71
  8. package/src/components/crm/Navigation.jsx +7 -11
  9. package/src/components/crm/QrCode.jsx +8 -12
  10. package/src/components/crm/QuickAction.jsx +1 -0
  11. package/src/components/crm/generic/GenericAuth.jsx +2 -6
  12. package/src/components/crm/generic/GenericDashboard.jsx +30 -340
  13. package/src/components/crm/generic/GenericDetail.jsx +37 -80
  14. package/src/components/crm/generic/GenericDynamic.jsx +76 -94
  15. package/src/components/crm/generic/GenericFormBuilder.jsx +19 -79
  16. package/src/components/crm/generic/GenericIndex.jsx +1 -2
  17. package/src/components/crm/generic/styles/GenericDetail.module.scss +0 -51
  18. package/src/components/crm/generic/styles/GenericFormBuilder.module.scss +0 -5
  19. package/src/components/crm/styles/DataGrid.module.scss +25 -0
  20. package/src/components/crm/styles/Field.module.scss +0 -210
  21. package/src/components/crm/styles/Form.module.scss +0 -78
  22. package/src/components/crm/styles/Navigation.module.scss +4 -10
  23. package/src/components/crm/styles/QrCode.module.scss +0 -18
  24. package/src/index.js +0 -8
  25. package/src/components/crm/generic/styles/GenericDashboard.module.scss +0 -325
  26. package/src/components/crm/sketch/SketchField.jsx +0 -395
  27. package/src/components/crm/sketch/arrow.jsx +0 -108
  28. package/src/components/crm/sketch/circle.jsx +0 -75
  29. package/src/components/crm/sketch/default-tool.jsx +0 -16
  30. package/src/components/crm/sketch/fabrictool.jsx +0 -22
  31. package/src/components/crm/sketch/history.jsx +0 -144
  32. package/src/components/crm/sketch/json/config.json +0 -14
  33. package/src/components/crm/sketch/line.jsx +0 -64
  34. package/src/components/crm/sketch/pan.jsx +0 -48
  35. package/src/components/crm/sketch/pencil.jsx +0 -36
  36. package/src/components/crm/sketch/rectangle-label-object.jsx +0 -69
  37. package/src/components/crm/sketch/rectangle-label.jsx +0 -93
  38. package/src/components/crm/sketch/rectangle.jsx +0 -76
  39. package/src/components/crm/sketch/select.jsx +0 -16
  40. package/src/components/crm/sketch/tools.jsx +0 -11
  41. package/src/components/crm/sketch/utils.jsx +0 -67
@@ -59,7 +59,7 @@ import 'react-confirm-alert/src/react-confirm-alert.css';
59
59
  import CustomFetch from './Fetch';
60
60
  import Download from './Download';
61
61
  import Form from './Form';
62
- import _, { set } from 'lodash';
62
+ import _ from 'lodash';
63
63
 
64
64
  const loadData = async (
65
65
  { skip, limit, sortInfo, filterValue },
@@ -94,7 +94,6 @@ const loadData = async (
94
94
  id: identifier,
95
95
  value: fv.value,
96
96
  operator: fv.operator,
97
- whereHas: fv.whereHas || [],
98
97
  });
99
98
  }
100
99
  } else {
@@ -150,19 +149,6 @@ const DataGrid = forwardRef(
150
149
  }
151
150
  }, [audioSource]);
152
151
 
153
- /** JSON Modal States */
154
- const [modalJsonShow, setModalJsonShow] = useState(false);
155
- const [jsonData, setJsonData] = useState({});
156
-
157
- /** JSON Modal Functions */
158
- const modalJsonOpen = () => {
159
- setModalJsonShow(true);
160
- };
161
-
162
- const modalJsonClose = () => {
163
- setModalJsonShow(false);
164
- };
165
-
166
152
  /** Gallery Modal States */
167
153
  const [modalGalleryShow, setModalGalleryShow] = useState(false);
168
154
  const [galleryData, setGalleryData] = useState([]);
@@ -182,32 +168,17 @@ const DataGrid = forwardRef(
182
168
  const [formId, setFormId] = useState(0);
183
169
  const [modalShow, setModalShow] = useState(false);
184
170
 
185
- const [formSettingData, setFormSettingData] = useState({});
186
- const [formSettingType, setFormSettingType] = useState('');
187
- const [formSettingId, setFormSettingId] = useState(0);
188
- const [modalSettingShow, setModalSettingShow] = useState(false);
189
-
190
171
  /** Modal Functions */
191
- const modalOpen = (type, id) => {
172
+ const modalOpen = (formType, formId) => {
192
173
  setModalShow(true);
193
- setFormType(type);
194
- setFormId(id);
174
+ setFormType(formType);
175
+ setFormId(formId);
195
176
  };
196
177
 
197
178
  const modalClose = () => {
198
179
  setModalShow(false);
199
180
  };
200
181
 
201
- const modalSettingOpen = (type, id) => {
202
- setModalSettingShow(true);
203
- setFormSettingType(type);
204
- setFormSettingId(id);
205
- };
206
-
207
- const modalSettingClose = () => {
208
- setModalSettingShow(false);
209
- };
210
-
211
182
  useEffect(() => {
212
183
  setFormData(form);
213
184
  }, [form]);
@@ -257,65 +228,23 @@ const DataGrid = forwardRef(
257
228
  const toastId = toast.loading('Starting download please wait...');
258
229
 
259
230
  try {
260
- if (d.id && d.id > 0) {
261
- const res = await Download(
262
- `/ajax/files/download/${d.id}/null`,
263
- 'GET',
264
- {}
265
- );
231
+ const res = await Download(
232
+ `/ajax/files/download/${d.id}/null`,
233
+ 'GET',
234
+ {}
235
+ );
266
236
 
267
- if (res.data.error) {
268
- toast.error(res.data.error);
269
- } else {
270
- // Assuming the response contains a Blob or similar data
271
- if (res.data && res.data instanceof Blob) {
272
- const fileName = `${d.file_name}`;
273
- saveAs(res.data, fileName);
274
- } else {
275
- // Handle the case where the response is not a Blob
276
- toast.error('Invalid file format received.');
277
- }
278
- }
237
+ if (res.data.error) {
238
+ toast.error(res.data.error);
279
239
  } else {
280
- toast.error(
281
- 'An issue with downloading the file has occurred.'
282
- );
283
- }
284
- } catch (error) {
285
- console.info(error);
286
- } finally {
287
- // Dismiss the loading toast in the finally block to ensure it's always dismissed
288
- toast.dismiss(toastId);
289
- }
290
- };
291
-
292
- const handleDownloadPath = async (file) => {
293
- const toastId = toast.loading('Starting download please wait...');
294
-
295
- try {
296
- if (file.file_path && file.file_name && file.file_extension) {
297
- const res = await Download(
298
- `/ajax/files/downloadByPath`,
299
- 'POST',
300
- { ...file }
301
- );
302
-
303
- if (res.data.error) {
304
- toast.error(res.data.error);
240
+ // Assuming the response contains a Blob or similar data
241
+ if (res.data && res.data instanceof Blob) {
242
+ const fileName = `${d.file_name}`;
243
+ saveAs(res.data, fileName);
305
244
  } else {
306
- // Assuming the response contains a Blob or similar data
307
- if (res.data && res.data instanceof Blob) {
308
- const fileName = `${file.file_name}`;
309
- saveAs(res.data, fileName);
310
- } else {
311
- // Handle the case where the response is not a Blob
312
- toast.error('Invalid file format received.');
313
- }
245
+ // Handle the case where the response is not a Blob
246
+ toast.error('Invalid file format received.');
314
247
  }
315
- } else {
316
- toast.error(
317
- 'An issue with downloading the file has occurred.'
318
- );
319
248
  }
320
249
  } catch (error) {
321
250
  console.info(error);
@@ -570,25 +499,6 @@ const DataGrid = forwardRef(
570
499
  ],
571
500
  });
572
501
  break;
573
- case 'form':
574
- if (s.key) {
575
- let fsd = s.form;
576
-
577
- if (fsd.fields && fsd.fields.length > 0) {
578
- fsd.fields.forEach((fItem, fKey) => {
579
- if (fItem.id === s.key) {
580
- fsd.fields[fKey].value = d.id;
581
- }
582
- });
583
-
584
- setFormSettingData((prevState) => ({
585
- ...prevState,
586
- ...fsd,
587
- }));
588
- }
589
- }
590
- modalSettingOpen('create', 0);
591
- break;
592
502
  case 'envelope':
593
503
  CustomFetch(s.url, 'POST', { id: d[s.key] }, (result) => {
594
504
  toast.success(result.message);
@@ -660,14 +570,6 @@ const DataGrid = forwardRef(
660
570
  );
661
571
  }
662
572
  break;
663
- case 'view':
664
- modalJsonOpen();
665
- setJsonData((prevState) => ({
666
- ...prevState,
667
- data: d[s.key],
668
- headers: s.headers,
669
- }));
670
- break;
671
573
  case 'update':
672
574
  modalOpen('update', d.id);
673
575
  break;
@@ -757,9 +659,7 @@ const DataGrid = forwardRef(
757
659
  } else {
758
660
  const column = rowProps.columns[columnIndex];
759
661
 
760
- const excludedColumnTypes = ['dropdown', 'text_input'];
761
-
762
- if (!excludedColumnTypes.includes(column.type)) {
662
+ if (column.type !== 'dropdown') {
763
663
  if (column.id !== '__checkbox-column') {
764
664
  if (column.link && column.link.hasOwnProperty('url')) {
765
665
  if (column.link.url) {
@@ -767,17 +667,7 @@ const DataGrid = forwardRef(
767
667
  const linkUrl = column.link.url;
768
668
  const linkKey =
769
669
  rowProps.columns[columnIndex].link.key;
770
- const rowData = linkKey.includes('.')
771
- ? linkKey
772
- .split('.')
773
- .reduce(
774
- (obj, key) =>
775
- obj && obj[key]
776
- ? obj[key]
777
- : null,
778
- rowProps.data
779
- )
780
- : rowProps.data[linkKey];
670
+ const rowData = rowProps.data[linkKey];
781
671
 
782
672
  if (column.link.hasOwnProperty('folder')) {
783
673
  const linkFolder =
@@ -794,13 +684,7 @@ const DataGrid = forwardRef(
794
684
  }
795
685
  }
796
686
  } else {
797
- if (rowData) {
798
- navigate(`${linkUrl}${rowData}`);
799
- } else {
800
- toast.warn(
801
- 'No data available for this link.'
802
- );
803
- }
687
+ navigate(`${linkUrl}${rowData}`);
804
688
  }
805
689
  } else {
806
690
  if (rowProps.data[column.id]) {
@@ -1231,7 +1115,6 @@ const DataGrid = forwardRef(
1231
1115
  return getIconComponent(Network);
1232
1116
  case 'gallery':
1233
1117
  return getIconComponent(Image);
1234
- case 'form':
1235
1118
  case 'link':
1236
1119
  return getIconComponent(LinkOut);
1237
1120
  case 'primary':
@@ -1244,8 +1127,6 @@ const DataGrid = forwardRef(
1244
1127
  return getIconComponent(Clock);
1245
1128
  case 'update':
1246
1129
  return getIconComponent(Edit);
1247
- case 'view':
1248
- return getIconComponent(Search);
1249
1130
  default:
1250
1131
  return null;
1251
1132
  }
@@ -1828,19 +1709,9 @@ const DataGrid = forwardRef(
1828
1709
  onClick={(e) => {
1829
1710
  e.stopPropagation();
1830
1711
  e.preventDefault();
1831
-
1832
- if (
1833
- file.id &&
1834
- file.id > 0
1835
- ) {
1836
- handleDownload(
1837
- file
1838
- );
1839
- } else {
1840
- handleDownloadPath(
1841
- file
1842
- );
1843
- }
1712
+ handleDownload(
1713
+ file
1714
+ );
1844
1715
  }}
1845
1716
  style={{
1846
1717
  marginRight:
@@ -2064,38 +1935,6 @@ const DataGrid = forwardRef(
2064
1935
  }, '');
2065
1936
 
2066
1937
  if (value) {
2067
- let columnStyle = {};
2068
- let columnValueChecker = '';
2069
-
2070
- if (
2071
- column?.active?.id &&
2072
- column?.active?.value
2073
- ) {
2074
- if (
2075
- data[column.active.id]
2076
- ?.value
2077
- ) {
2078
- columnValueChecker =
2079
- data[column.active.id]
2080
- ?.value;
2081
- } else if (
2082
- data[column.active.id]
2083
- ) {
2084
- columnValueChecker =
2085
- data[column.active.id];
2086
- }
2087
-
2088
- if (
2089
- columnValueChecker ===
2090
- column.active.value
2091
- ) {
2092
- columnStyle = {
2093
- color: column.active
2094
- .colour,
2095
- };
2096
- }
2097
- }
2098
-
2099
1938
  if (Array.isArray(value)) {
2100
1939
  if (value[0]) {
2101
1940
  value = value[0];
@@ -2128,7 +1967,7 @@ const DataGrid = forwardRef(
2128
1967
  column.placeholder !== ''
2129
1968
  ) {
2130
1969
  return (
2131
- <span style={columnStyle}>
1970
+ <span>
2132
1971
  {column.placeholder}
2133
1972
  </span>
2134
1973
  );
@@ -2149,13 +1988,7 @@ const DataGrid = forwardRef(
2149
1988
  }
2150
1989
 
2151
1990
  if (typeof value === 'string') {
2152
- return (
2153
- <span
2154
- style={columnStyle}
2155
- >
2156
- {value}
2157
- </span>
2158
- );
1991
+ return <span>{value}</span>;
2159
1992
  } else {
2160
1993
  return null;
2161
1994
  }
@@ -2376,51 +2209,6 @@ const DataGrid = forwardRef(
2376
2209
  return <span>{stage}</span>;
2377
2210
  },
2378
2211
  };
2379
- case 'text_input':
2380
- columnId = Array.isArray(column.id)
2381
- ? column.id.join('-')
2382
- : column.id;
2383
-
2384
- return {
2385
- ...commonProps,
2386
- name: columnId,
2387
- render: ({ data }) => {
2388
- const debouncedOnChange = debounce(
2389
- (name, value) => {
2390
- if (
2391
- column.update?.key &&
2392
- column.update?.url &&
2393
- column.update?.method
2394
- ) {
2395
- handleDropdownUpdate(
2396
- column.update.key,
2397
- `${column.update.url}/${data.id}`,
2398
- column.update.method,
2399
- value
2400
- );
2401
- }
2402
- },
2403
- 1000
2404
- );
2405
-
2406
- const handleChange = (e) => {
2407
- const { name, value } = e.target;
2408
- debouncedOnChange(name, value);
2409
- };
2410
-
2411
- return (
2412
- <input
2413
- name={column.id}
2414
- defaultValue={
2415
- data[column.id] || ''
2416
- }
2417
- style={{ padding: '7px' }}
2418
- onChange={handleChange}
2419
- type="text"
2420
- />
2421
- );
2422
- },
2423
- };
2424
2212
  case 'time':
2425
2213
  return {
2426
2214
  ...commonProps,
@@ -2677,7 +2465,6 @@ const DataGrid = forwardRef(
2677
2465
  name: filterName,
2678
2466
  operator: column.filter.operator,
2679
2467
  type: column.filter.type,
2680
- whereHas: column.filter.whereHas || [],
2681
2468
  value: filterValue,
2682
2469
  reset: column.filter.reset
2683
2470
  ? column.filter.reset
@@ -2739,69 +2526,6 @@ const DataGrid = forwardRef(
2739
2526
  }
2740
2527
  };
2741
2528
 
2742
- const snakeCaseToTitle = (text) => {
2743
- return text
2744
- .replace(/_/g, ' ')
2745
- .replace(/\b\w/g, (char) => char.toUpperCase()); // Capitalize first letter of each word
2746
- };
2747
-
2748
- // Recursive function to handle nested objects
2749
- const renderField = (key, value) => {
2750
- // If the value is an object, recursively render its fields
2751
- if (typeof value === 'object' && value !== null) {
2752
- return (
2753
- <div key={key} style={{ marginBottom: '1rem' }}>
2754
- <h4
2755
- style={{
2756
- fontSize: '1.2rem',
2757
- marginBottom: '0.5rem',
2758
- color: '#333',
2759
- borderBottom: '1px solid #ccc',
2760
- }}
2761
- >
2762
- {snakeCaseToTitle(key)}
2763
- </h4>
2764
- <div style={{ paddingLeft: '1.5rem' }}>
2765
- {Object.keys(value).map((childKey) =>
2766
- renderField(childKey, value[childKey])
2767
- )}
2768
- </div>
2769
- </div>
2770
- );
2771
- }
2772
- // Otherwise, render the key and value as a label and paragraph
2773
- return (
2774
- <div key={key} style={{ marginBottom: '1rem' }}>
2775
- <span
2776
- style={{
2777
- fontWeight: 'bold',
2778
- marginBottom: '0.2rem',
2779
- display: 'block',
2780
- color: '#444',
2781
- }}
2782
- >
2783
- {snakeCaseToTitle(key)}
2784
- </span>
2785
- <p
2786
- style={{
2787
- margin: 0,
2788
- color: '#666',
2789
- backgroundColor: '#f9f9f9',
2790
- padding: '0.5rem',
2791
- borderRadius: '5px',
2792
- }}
2793
- >
2794
- {value !== null ? value : 'N/A'}
2795
- </p>
2796
- </div>
2797
- );
2798
- };
2799
-
2800
- const getHeaderLabel = (headers, parentKey) => {
2801
- const headerObj = headers.find((header) => header.id === parentKey);
2802
- return headerObj ? headerObj.label : snakeCaseToTitle(parentKey);
2803
- };
2804
-
2805
2529
  useEffect(() => {
2806
2530
  columns.forEach((column) => {
2807
2531
  if (column.filter && column.filter.url) {
@@ -2854,7 +2578,6 @@ const DataGrid = forwardRef(
2854
2578
  : 400,
2855
2579
  boxShadow: 'none',
2856
2580
  });
2857
-
2858
2581
  const headerProps = {
2859
2582
  style: style ? style : {},
2860
2583
  };
@@ -2970,29 +2693,6 @@ const DataGrid = forwardRef(
2970
2693
  userProfile={userProfile}
2971
2694
  />
2972
2695
  </Popup>
2973
- <Popup
2974
- open={modalSettingShow}
2975
- onClose={modalSettingClose}
2976
- closeOnDocumentClick={false}
2977
- nested
2978
- >
2979
- <Form
2980
- ajaxSetting={ajaxSetting}
2981
- api={api}
2982
- closeModal={modalSettingClose}
2983
- columnId={formSettingId}
2984
- fetchTable={handleReload}
2985
- formSettings={formSettingData}
2986
- formType={formSettingType}
2987
- gridRef={gridRef}
2988
- mapbox={mapbox}
2989
- modalOpen={modalSettingOpen}
2990
- paramValue={paramValue}
2991
- style={style}
2992
- updateForm={setFormSettingData}
2993
- userProfile={userProfile}
2994
- />
2995
- </Popup>
2996
2696
  <Popup
2997
2697
  open={modalGalleryShow}
2998
2698
  onClose={modalGalleryClose}
@@ -3022,100 +2722,6 @@ const DataGrid = forwardRef(
3022
2722
  </div>
3023
2723
  </div>
3024
2724
  </Popup>
3025
- <Popup
3026
- open={modalJsonShow}
3027
- onClose={modalJsonClose}
3028
- closeOnDocumentClick={false}
3029
- >
3030
- <div
3031
- className={`${styles.modalwrap} ${styles['top--modal']}`}
3032
- >
3033
- <div className={styles.modal}>
3034
- <div className={styles.modal__header}>
3035
- <h1>View Data</h1>
3036
- <button
3037
- className={styles.modal__close}
3038
- onClick={modalJsonClose}
3039
- >
3040
- <CircleX strokeWidth={1} size={24} />
3041
- </button>
3042
- </div>
3043
- <div className={styles.modal__content}>
3044
- <div className={styles.formcontainer}>
3045
- <div
3046
- style={{
3047
- lineHeight: '1.5',
3048
- }}
3049
- >
3050
- {jsonData.headers &&
3051
- jsonData.headers.map((header) => {
3052
- const parentKey = header.id;
3053
-
3054
- // Skip rendering if the parentKey is "id" or doesn't exist in jsonData
3055
- if (
3056
- parentKey === 'id' ||
3057
- !(
3058
- parentKey in
3059
- jsonData.data
3060
- )
3061
- )
3062
- return null;
3063
-
3064
- return (
3065
- <div
3066
- key={parentKey}
3067
- style={{
3068
- marginBottom:
3069
- '2rem',
3070
- }}
3071
- >
3072
- {/* Section Header */}
3073
- <h3
3074
- style={{
3075
- fontSize:
3076
- '1.4rem',
3077
- marginBottom:
3078
- '1rem',
3079
- color: '#222',
3080
- borderBottom:
3081
- '2px solid #ddd',
3082
- }}
3083
- >
3084
- {getHeaderLabel(
3085
- jsonData.headers,
3086
- parentKey
3087
- )}
3088
- </h3>
3089
- <div
3090
- style={{
3091
- paddingLeft:
3092
- '1rem',
3093
- }}
3094
- >
3095
- {/* Render fields for each section */}
3096
- {Object.keys(
3097
- jsonData.data[
3098
- parentKey
3099
- ]
3100
- ).map((childKey) =>
3101
- renderField(
3102
- childKey,
3103
- jsonData
3104
- .data[
3105
- parentKey
3106
- ][childKey]
3107
- )
3108
- )}
3109
- </div>
3110
- </div>
3111
- );
3112
- })}
3113
- </div>
3114
- </div>
3115
- </div>
3116
- </div>
3117
- </div>
3118
- </Popup>
3119
2725
  </>
3120
2726
  );
3121
2727
  }