@visns-studio/visns-components 1.0.3 → 1.0.5
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.
- package/components/cms/sorting/item.jsx +21 -0
- package/components/cms/sorting/list.jsx +21 -0
- package/components/cms/visns-data-grid.jsx +597 -0
- package/components/cms/visns-dropzone.jsx +190 -0
- package/components/cms/visns-field.jsx +696 -0
- package/components/cms/visns-form.jsx +467 -0
- package/components/crm/visns-download.jsx +102 -0
- package/index.js +27 -15
- package/package.json +1 -1
- /package/components/{visns-download.jsx → cms/visns-download.jsx} +0 -0
- /package/components/{visns-async-select.jsx → crm/visns-async-select.jsx} +0 -0
- /package/components/{visns-autocomplete.jsx → crm/visns-autocomplete.jsx} +0 -0
- /package/components/{visns-call.jsx → crm/visns-call.jsx} +0 -0
- /package/components/{visns-data-grid.jsx → crm/visns-data-grid.jsx} +0 -0
- /package/components/{visns-fetch.jsx → crm/visns-fetch.jsx} +0 -0
- /package/components/{visns-field.jsx → crm/visns-field.jsx} +0 -0
- /package/components/{visns-form.jsx → crm/visns-form.jsx} +0 -0
- /package/components/{visns-loader.jsx → crm/visns-loader.jsx} +0 -0
- /package/components/{visns-multi-select.jsx → crm/visns-multi-select.jsx} +0 -0
- /package/components/{visns-notification.jsx → crm/visns-notification.jsx} +0 -0
- /package/components/{visns-select-list.jsx → crm/visns-select-list.jsx} +0 -0
- /package/components/{visns-select.jsx → crm/visns-select.jsx} +0 -0
- /package/components/{visns-table-filter.jsx → crm/visns-table-filter.jsx} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import React, { 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 { File, TrashCan } from "akar-icons";
|
|
6
|
+
|
|
7
|
+
import "react-confirm-alert/src/react-confirm-alert.css";
|
|
8
|
+
|
|
9
|
+
import CustomFetch from "../crm/visns-fetch";
|
|
10
|
+
|
|
11
|
+
function VisnsDropZone(props) {
|
|
12
|
+
const { alertStateChange, fetchData, files, settings } = props;
|
|
13
|
+
const [loadingProgress, setLoadingProgress] = useState(0);
|
|
14
|
+
|
|
15
|
+
const onDrop = useCallback((acceptedFiles) => {
|
|
16
|
+
acceptedFiles.forEach((a) => {
|
|
17
|
+
Vapor.store(a, {
|
|
18
|
+
progress: (progress) => {
|
|
19
|
+
setLoadingProgress(progress * 100);
|
|
20
|
+
},
|
|
21
|
+
}).then((response) => {
|
|
22
|
+
setLoadingProgress(0);
|
|
23
|
+
CustomFetch(
|
|
24
|
+
settings.url,
|
|
25
|
+
settings.method,
|
|
26
|
+
{
|
|
27
|
+
uuid: response.uuid,
|
|
28
|
+
key: response.key,
|
|
29
|
+
bucket: response.bucket,
|
|
30
|
+
filename: a.name,
|
|
31
|
+
filesize: a.size,
|
|
32
|
+
extension: response.extension,
|
|
33
|
+
...settings.data,
|
|
34
|
+
},
|
|
35
|
+
function (result) {
|
|
36
|
+
if (result.error === "") {
|
|
37
|
+
fetchData();
|
|
38
|
+
|
|
39
|
+
alertStateChange({
|
|
40
|
+
show: true,
|
|
41
|
+
alertClass: "dialog success",
|
|
42
|
+
alertText: String(
|
|
43
|
+
"File has been successfully uploaded."
|
|
44
|
+
),
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
alertStateChange({
|
|
48
|
+
show: true,
|
|
49
|
+
alertClass: "dialog error",
|
|
50
|
+
alertText: String(result.error),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
function (error) {
|
|
55
|
+
alertStateChange({
|
|
56
|
+
show: true,
|
|
57
|
+
alertClass: "dialog error",
|
|
58
|
+
alertText: String(error),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
67
|
+
onDrop,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const handleDownload = (id) => {
|
|
71
|
+
if (id && id > 0) {
|
|
72
|
+
window.open(`/ajax/file/download/${id}/${settings.model}`);
|
|
73
|
+
} else {
|
|
74
|
+
alertStateChange({
|
|
75
|
+
show: true,
|
|
76
|
+
alertClass: "dialog error",
|
|
77
|
+
alertText: String("Issue with downloading the selected file."),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleDelete = (e, id, name) => {
|
|
83
|
+
if (e) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
|
|
87
|
+
if (id && id > 0) {
|
|
88
|
+
confirmAlert({
|
|
89
|
+
title: "Confirm to Delete File",
|
|
90
|
+
message: "Are you sure you want to delete " + name,
|
|
91
|
+
buttons: [
|
|
92
|
+
{
|
|
93
|
+
label: "Yes",
|
|
94
|
+
onClick: () => {
|
|
95
|
+
CustomFetch(
|
|
96
|
+
`/ajax/file/delete`,
|
|
97
|
+
"POST",
|
|
98
|
+
{
|
|
99
|
+
file_id: id,
|
|
100
|
+
},
|
|
101
|
+
function (result) {
|
|
102
|
+
if (result.error === "") {
|
|
103
|
+
fetchData();
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
function (error) {
|
|
107
|
+
alertStateChange({
|
|
108
|
+
show: true,
|
|
109
|
+
alertClass: "dialog error",
|
|
110
|
+
alertText: String(error),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
label: "No",
|
|
118
|
+
onClick: () => close(),
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
alertStateChange({
|
|
124
|
+
show: true,
|
|
125
|
+
alertClass: "dialog error",
|
|
126
|
+
alertText: String("Issue with deleting the selected file."),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
<div className="progress">
|
|
135
|
+
<motion.div
|
|
136
|
+
className="progress__bar"
|
|
137
|
+
initial={{ width: "0%" }}
|
|
138
|
+
animate={{
|
|
139
|
+
width: loadingProgress + "%",
|
|
140
|
+
}}
|
|
141
|
+
transition={{
|
|
142
|
+
duration: 1,
|
|
143
|
+
ease: [0.165, 0.84, 0.44, 1.0],
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
<section className="dropzone__container">
|
|
148
|
+
<div {...getRootProps()}>
|
|
149
|
+
<input {...getInputProps()} />
|
|
150
|
+
{isDragActive ? (
|
|
151
|
+
<p>Drop the files here ...</p>
|
|
152
|
+
) : (
|
|
153
|
+
<p>
|
|
154
|
+
Drag 'n' drop some files here, or click to select
|
|
155
|
+
files
|
|
156
|
+
</p>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
<ul className="dropzone__files">
|
|
160
|
+
{files && files.length > 0
|
|
161
|
+
? files.map((a, b) => (
|
|
162
|
+
<li
|
|
163
|
+
onClick={() => {
|
|
164
|
+
handleDownload(a.id);
|
|
165
|
+
}}
|
|
166
|
+
key={"tf-" + b}
|
|
167
|
+
>
|
|
168
|
+
<File strokeWidth={2} size={18} />
|
|
169
|
+
{a.file_name}
|
|
170
|
+
<button
|
|
171
|
+
onClick={(event) => {
|
|
172
|
+
handleDelete(
|
|
173
|
+
event,
|
|
174
|
+
a.id,
|
|
175
|
+
a.file_name
|
|
176
|
+
);
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
<TrashCan strokeWidth={2} size={18} />
|
|
180
|
+
</button>
|
|
181
|
+
</li>
|
|
182
|
+
))
|
|
183
|
+
: null}
|
|
184
|
+
</ul>
|
|
185
|
+
</section>
|
|
186
|
+
</>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export default VisnsDropZone;
|