@visns-studio/visns-components 4.7.2 → 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 (99) 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/index.css +0 -2902
  94. package/dist/index.js +0 -2
  95. package/dist/index.js.LICENSE.txt +0 -150
  96. package/dist/main.83b033670d64419bb497.css +0 -1
  97. package/dist/main.b1723d17cd2d3513ab62.js +0 -1
  98. package/dist/report.html +0 -39
  99. package/dist/runtime.33c276593b23f8035b8d.js +0 -1
@@ -0,0 +1,349 @@
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
+ import { motion } from 'framer-motion';
3
+ import { useDropzone } from 'react-dropzone';
4
+ import { confirmAlert } from 'react-confirm-alert';
5
+ import { CircleX, File, TrashCan } from 'akar-icons';
6
+ import { toast } from 'react-toastify';
7
+ import { arrayMoveImmutable } from 'array-move';
8
+ import Popup from 'reactjs-popup';
9
+
10
+ import 'react-confirm-alert/src/react-confirm-alert.css';
11
+
12
+ import CustomFetch from '../crm/Fetch';
13
+ import SortableList from './sorting/List';
14
+
15
+ function VisnsDropZone({ fetchData, files, settings }) {
16
+ const [data, setData] = useState(files);
17
+
18
+ /** Modal States */
19
+ const [modalData, setModalData] = useState({
20
+ id: 0,
21
+ title: '',
22
+ description: '',
23
+ });
24
+ const [modalShow, setModalShow] = useState(false);
25
+
26
+ /** Modal Functions */
27
+ const modalOpen = () => {
28
+ setModalShow(true);
29
+ };
30
+
31
+ const modalClose = () => {
32
+ setModalShow(false);
33
+ };
34
+
35
+ const [loadingProgress, setLoadingProgress] = useState(0);
36
+
37
+ const onSortEnd = ({ oldIndex, newIndex }) => {
38
+ setData((prevItem) => arrayMoveImmutable(prevItem, oldIndex, newIndex));
39
+ };
40
+
41
+ const onDrop = useCallback((acceptedFiles) => {
42
+ acceptedFiles.forEach((a) => {
43
+ Vapor.store(a, {
44
+ progress: (progress) => {
45
+ setLoadingProgress(progress * 100);
46
+ },
47
+ }).then((response) => {
48
+ setLoadingProgress(0);
49
+ CustomFetch(
50
+ settings.url,
51
+ settings.method,
52
+ {
53
+ uuid: response.uuid,
54
+ key: response.key,
55
+ bucket: response.bucket,
56
+ filename: a.name,
57
+ filesize: a.size,
58
+ extension: response.extension,
59
+ ...settings.data,
60
+ },
61
+ function (result) {
62
+ if (result.error === '') {
63
+ if (typeof fetchData === 'function') {
64
+ fetchData();
65
+
66
+ toast.success(
67
+ 'File has been successfully uploaded.'
68
+ );
69
+ }
70
+ } else {
71
+ toast.error(String(result.error));
72
+ }
73
+ }
74
+ );
75
+ });
76
+ });
77
+ }, []);
78
+
79
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
80
+ onDrop,
81
+ });
82
+
83
+ const handleDownload = (id) => {
84
+ if (id && id > 0 && settings.model && settings.model !== '') {
85
+ window.open(`/ajax/files/download/${id}/${settings.model}`);
86
+ } else {
87
+ toast.warning('Issue with downloading the selected file.');
88
+ }
89
+ };
90
+
91
+ const handleChange = (e) => {
92
+ const { name, value } = e.target;
93
+
94
+ setModalData((prevState) => ({
95
+ ...prevState,
96
+ [name]: value,
97
+ }));
98
+ };
99
+
100
+ const handleEdit = async (fileData) => {
101
+ try {
102
+ const res = await CustomFetch(
103
+ `/ajax/files/${fileData.id}`,
104
+ 'GET',
105
+ {}
106
+ );
107
+
108
+ setModalData((prevState) => ({
109
+ ...prevState,
110
+ id: res.data.id,
111
+ file_name: res.data.file_name,
112
+ title: res.data.file_title,
113
+ description: res.data.file_description,
114
+ }));
115
+
116
+ modalOpen();
117
+ } catch (error) {
118
+ console.info(error);
119
+ }
120
+ };
121
+
122
+ const handleDelete = (id, name) => {
123
+ if (id && id > 0) {
124
+ confirmAlert({
125
+ title: 'Confirm to Delete File',
126
+ message: 'Are you sure you want to delete ' + name,
127
+ buttons: [
128
+ {
129
+ label: 'Yes',
130
+ onClick: () => {
131
+ CustomFetch(
132
+ `/ajax/files/delete`,
133
+ 'POST',
134
+ {
135
+ file_id: id,
136
+ },
137
+ function (result) {
138
+ if (result.error === '') {
139
+ if (typeof fetchData === 'function') {
140
+ fetchData();
141
+ }
142
+ }
143
+ }
144
+ );
145
+ },
146
+ },
147
+ {
148
+ label: 'No',
149
+ onClick: () => close(),
150
+ },
151
+ ],
152
+ });
153
+ } else {
154
+ toast.error('Issue with deleting the selected file.');
155
+ }
156
+ };
157
+
158
+ const handleSubmit = async (e) => {
159
+ try {
160
+ if (e) {
161
+ e.preventDefault();
162
+ }
163
+
164
+ const res = await CustomFetch(
165
+ `/ajax/files/${modalData.id}`,
166
+ 'PUT',
167
+ {
168
+ file_name: modalData.file_name,
169
+ file_title: modalData.title,
170
+ file_description: modalData.description,
171
+ }
172
+ );
173
+
174
+ if (res.data.error === '') {
175
+ toast.success('File metadata has been successfully updated.');
176
+ modalClose();
177
+
178
+ if (typeof fetchData === 'function') {
179
+ fetchData();
180
+ }
181
+ } else {
182
+ toast.error(res.data.error);
183
+ }
184
+ } catch (error) {
185
+ console.info(error);
186
+ }
187
+ };
188
+
189
+ useEffect(() => {
190
+ if (data?.length > 0) {
191
+ CustomFetch(
192
+ '/ajax/files/sort_update',
193
+ 'POST',
194
+ {
195
+ list: data,
196
+ },
197
+ function (result) {
198
+ if (result.error === '') {
199
+ } else {
200
+ toast.error(String(result.error));
201
+ }
202
+ }
203
+ );
204
+ }
205
+ }, [data]);
206
+
207
+ useEffect(() => {
208
+ setData(files);
209
+ }, [files]);
210
+
211
+ return (
212
+ <>
213
+ {settings.type === 'gallery' ? (
214
+ <div className="image-container">
215
+ {data && data.length > 0 ? (
216
+ <SortableList
217
+ items={data}
218
+ onSortEnd={onSortEnd}
219
+ axis="xy"
220
+ helperClass="dragitem"
221
+ transitionDuration={250}
222
+ handleDelete={handleDelete}
223
+ handleEdit={handleEdit}
224
+ useDragHandle
225
+ showImage={true}
226
+ />
227
+ ) : null}
228
+ </div>
229
+ ) : null}
230
+ <div className="progress">
231
+ <motion.div
232
+ className="progress__bar"
233
+ initial={{ width: '0%' }}
234
+ animate={{
235
+ width: loadingProgress + '%',
236
+ }}
237
+ transition={{
238
+ duration: 1,
239
+ ease: [0.165, 0.84, 0.44, 1.0],
240
+ }}
241
+ />
242
+ </div>
243
+ <section className="dropzone__container">
244
+ <div {...getRootProps()}>
245
+ <input {...getInputProps()} />
246
+ {isDragActive ? (
247
+ <p>Drop the files here ...</p>
248
+ ) : (
249
+ <p>
250
+ Drag 'n' drop some files here, or click to select
251
+ files
252
+ </p>
253
+ )}
254
+ </div>
255
+ {settings.type !== 'gallery' ? (
256
+ <ul className="dropzone__files">
257
+ {data && data.length > 0
258
+ ? data.map((a, b) => (
259
+ <li
260
+ onClick={() => {
261
+ handleDownload(a.id);
262
+ }}
263
+ key={'tf-' + b}
264
+ >
265
+ <File strokeWidth={2} size={18} />
266
+ {a.file_name}
267
+ <button
268
+ onClick={(e) => {
269
+ e.preventDefault();
270
+ e.stopPropagation();
271
+
272
+ handleDelete(a.id, a.file_name);
273
+ }}
274
+ >
275
+ <TrashCan strokeWidth={2} size={18} />
276
+ </button>
277
+ </li>
278
+ ))
279
+ : null}
280
+ </ul>
281
+ ) : null}
282
+ </section>
283
+ <Popup
284
+ open={modalShow}
285
+ onClose={modalClose}
286
+ closeOnDocumentClick={false}
287
+ >
288
+ <div className="modalwrap top--modal">
289
+ <div className="modal">
290
+ <div className="modal__header">
291
+ <h1>Update File Metadata</h1>
292
+ <button
293
+ className="modal__close"
294
+ onClick={modalClose}
295
+ >
296
+ <CircleX strokeWidth={1} size={24} />
297
+ </button>
298
+ </div>
299
+ <div className="modal__content">
300
+ <div className="formcontainer">
301
+ <form
302
+ className="modalForm"
303
+ onSubmit={handleSubmit}
304
+ >
305
+ <div className="formItem fwItem">
306
+ <label className="fi__label">
307
+ <input
308
+ type="text"
309
+ name="title"
310
+ onChange={handleChange}
311
+ value={modalData.title}
312
+ />
313
+ <span className="fi__span">
314
+ Title
315
+ </span>
316
+ </label>
317
+ </div>
318
+ <div className="formItem fwItem">
319
+ <label className="fi__label">
320
+ <textarea
321
+ name="description"
322
+ rows="5"
323
+ onChange={handleChange}
324
+ value={modalData.description}
325
+ ></textarea>
326
+ <span className="fi__span">
327
+ Description
328
+ </span>
329
+ </label>
330
+ </div>
331
+ <div className="formItem fwItem lastItem">
332
+ <button
333
+ className="btn modalsave"
334
+ type="submit"
335
+ >
336
+ Save
337
+ </button>
338
+ </div>
339
+ </form>
340
+ </div>
341
+ </div>
342
+ </div>
343
+ </div>
344
+ </Popup>
345
+ </>
346
+ );
347
+ }
348
+
349
+ export default VisnsDropZone;