@visns-studio/visns-components 2.9.0 → 2.9.2

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.
@@ -2,9 +2,10 @@ import React, { useEffect, useState, useCallback } from 'react';
2
2
  import { motion } from 'framer-motion';
3
3
  import { useDropzone } from 'react-dropzone';
4
4
  import { confirmAlert } from 'react-confirm-alert';
5
- import { File, TrashCan } from 'akar-icons';
5
+ import { CircleX, File, TrashCan } from 'akar-icons';
6
6
  import { toast } from 'react-toastify';
7
7
  import { arrayMoveImmutable } from 'array-move';
8
+ import Popup from 'reactjs-popup';
8
9
 
9
10
  import 'react-confirm-alert/src/react-confirm-alert.css';
10
11
 
@@ -14,6 +15,23 @@ import SortableList from './sorting/List';
14
15
  function VisnsDropZone({ fetchData, files, settings }) {
15
16
  const [data, setData] = useState(files);
16
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
+
17
35
  const [loadingProgress, setLoadingProgress] = useState(0);
18
36
 
19
37
  const onSortEnd = ({ oldIndex, newIndex }) => {
@@ -70,6 +88,36 @@ function VisnsDropZone({ fetchData, files, settings }) {
70
88
  }
71
89
  };
72
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
+ title: res.data.file_title,
112
+ description: res.data.file_description,
113
+ }));
114
+
115
+ modalOpen();
116
+ } catch (error) {
117
+ console.info(error);
118
+ }
119
+ };
120
+
73
121
  const handleDelete = (id, name) => {
74
122
  console.info(id, name);
75
123
  if (id && id > 0) {
@@ -107,6 +155,32 @@ function VisnsDropZone({ fetchData, files, settings }) {
107
155
  }
108
156
  };
109
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_title: modalData.title,
169
+ file_description: modalData.description,
170
+ }
171
+ );
172
+
173
+ if (res.data.error === '') {
174
+ toast.success('File metadata has been successfully updated.');
175
+ modalClose();
176
+ } else {
177
+ toast.error(res.data.error);
178
+ }
179
+ } catch (error) {
180
+ console.info(error);
181
+ }
182
+ };
183
+
110
184
  useEffect(() => {
111
185
  if (data.length > 0) {
112
186
  CustomFetch(
@@ -137,6 +211,7 @@ function VisnsDropZone({ fetchData, files, settings }) {
137
211
  helperClass="dragitem"
138
212
  transitionDuration={250}
139
213
  handleDelete={handleDelete}
214
+ handleEdit={handleEdit}
140
215
  useDragHandle
141
216
  />
142
217
  ) : null}
@@ -195,6 +270,68 @@ function VisnsDropZone({ fetchData, files, settings }) {
195
270
  </ul>
196
271
  ) : null}
197
272
  </section>
273
+ <Popup
274
+ open={modalShow}
275
+ onClose={modalClose}
276
+ closeOnDocumentClick={false}
277
+ >
278
+ <div className="modalwrap top--modal">
279
+ <div className="modal">
280
+ <div className="modal__header">
281
+ <h1>Update File Metadata</h1>
282
+ <button
283
+ className="modal__close"
284
+ onClick={modalClose}
285
+ >
286
+ <CircleX strokeWidth={1} size={24} />
287
+ </button>
288
+ </div>
289
+ <div className="modal__content">
290
+ <div className="formcontainer">
291
+ <form
292
+ className="modalForm"
293
+ onSubmit={handleSubmit}
294
+ >
295
+ <div className="formItem fwItem">
296
+ <label className="fi__label">
297
+ <input
298
+ type="text"
299
+ name="title"
300
+ onChange={handleChange}
301
+ value={modalData.title}
302
+ />
303
+ <span className="fi__span">
304
+ Title
305
+ </span>
306
+ </label>
307
+ </div>
308
+ <div className="formItem fwItem">
309
+ <label className="fi__label">
310
+ <textarea
311
+ name="description"
312
+ rows="5"
313
+ onChange={handleChange}
314
+ value={modalData.description}
315
+ ></textarea>
316
+ <span className="fi__span">
317
+ Description
318
+ </span>
319
+ </label>
320
+ </div>
321
+ <div className="formItem fwItem lastItem">
322
+ <button
323
+ className="btn modalsave"
324
+ type="submit"
325
+ >
326
+ Save
327
+ </button>
328
+ </div>
329
+ </form>
330
+ </div>
331
+ </div>
332
+ </div>
333
+ </div>
334
+ </Popup>
198
335
  </>
199
336
  );
200
337
  }
@@ -1,12 +1,18 @@
1
1
  import React from 'react';
2
2
  import { SortableElement, sortableHandle } from 'react-sortable-hoc';
3
- import { ChevronVertical, TrashCan } from 'akar-icons';
3
+ import { ChevronVertical, Pencil, TrashCan } from 'akar-icons';
4
4
 
5
5
  const DragHandle = sortableHandle(() => (
6
6
  <ChevronVertical strokeWidth={1} size={26} />
7
7
  ));
8
8
 
9
- const SortableItem = ({ containerIndex, handleClick, handleDelete, value }) => {
9
+ const SortableItem = ({
10
+ containerIndex,
11
+ handleClick,
12
+ handleEdit,
13
+ handleDelete,
14
+ value,
15
+ }) => {
10
16
  return (
11
17
  <li
12
18
  onClick={(e) => {
@@ -31,6 +37,23 @@ const SortableItem = ({ containerIndex, handleClick, handleDelete, value }) => {
31
37
  <img src={value.file_url} />
32
38
  </div>
33
39
  ) : null}
40
+
41
+ {handleEdit &&
42
+ value.hasOwnProperty('file_title') &&
43
+ value.hasOwnProperty('file_description') && (
44
+ <Pencil
45
+ className="delete pencil-edit"
46
+ strokeWidth={1}
47
+ size={26}
48
+ onClick={(e) => {
49
+ e.preventDefault();
50
+ e.stopPropagation();
51
+
52
+ handleEdit(value);
53
+ }}
54
+ />
55
+ )}
56
+
34
57
  {handleDelete && (
35
58
  <TrashCan
36
59
  className="delete trash-delete"
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import VisnsSortableItem from './Item';
3
3
  import { SortableContainer } from 'react-sortable-hoc';
4
4
 
5
- const SortableList = ({ handleClick, handleDelete, items }) => {
5
+ const SortableList = ({ handleClick, handleDelete, handleEdit, items }) => {
6
6
  return (
7
7
  <ul className="sortlist">
8
8
  {items.map((value, index) => (
@@ -13,6 +13,7 @@ const SortableList = ({ handleClick, handleDelete, items }) => {
13
13
  value={value}
14
14
  handleClick={handleClick}
15
15
  handleDelete={handleDelete}
16
+ handleEdit={handleEdit}
16
17
  />
17
18
  ))}
18
19
  </ul>
@@ -104,10 +104,6 @@ function GenericIndex({ layout = 'full', setting, userProfile }) {
104
104
  };
105
105
  }, []);
106
106
 
107
- useEffect(() => {
108
- console.info(config);
109
- }, [config]);
110
-
111
107
  return (
112
108
  <>
113
109
  <div className="grid">
package/package.json CHANGED
@@ -44,7 +44,7 @@
44
44
  "react-dom": "^17.0.1"
45
45
  },
46
46
  "name": "@visns-studio/visns-components",
47
- "version": "2.9.0",
47
+ "version": "2.9.2",
48
48
  "description": "Various packages to assist in the development of our Custom Applications.",
49
49
  "main": "index.js",
50
50
  "scripts": {