tycho-components 0.3.1 → 0.3.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.
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useContext, useState } from
|
|
3
|
-
import Dropzone from
|
|
4
|
-
import { useTranslation } from
|
|
5
|
-
import AppModal from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
2
|
+
import { useContext, useState } from "react";
|
|
3
|
+
import Dropzone from "react-dropzone";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import AppModal from "../AppModal";
|
|
6
|
+
import CommonContext from "../configs/CommonContext";
|
|
7
|
+
import { toastLoading } from "../configs/store/actions";
|
|
8
|
+
import { useMessageUtils } from "../configs/useMessageUtils";
|
|
9
|
+
import "./style.scss";
|
|
10
|
+
import UploadService from "./UploadService";
|
|
11
11
|
export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, }) {
|
|
12
|
-
const { t } = useTranslation(
|
|
12
|
+
const { t } = useTranslation("upload");
|
|
13
13
|
const { state, dispatch } = useContext(CommonContext);
|
|
14
14
|
const { dispatchError } = useMessageUtils();
|
|
15
15
|
const [file, setFile] = useState();
|
|
16
16
|
const [preview, setPreview] = useState();
|
|
17
17
|
const isImageFile = (file) => {
|
|
18
|
-
return file.type.startsWith(
|
|
18
|
+
return file.type.startsWith("image/");
|
|
19
19
|
};
|
|
20
20
|
const handleDrop = async (files) => {
|
|
21
21
|
const file = files[0];
|
|
@@ -29,22 +29,22 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
|
|
|
29
29
|
return;
|
|
30
30
|
dispatch(toastLoading(true));
|
|
31
31
|
const data = new FormData();
|
|
32
|
-
data.append(
|
|
33
|
-
data.append(
|
|
34
|
-
keepName && data.append(
|
|
32
|
+
data.append("file", file);
|
|
33
|
+
data.append("folder", folder);
|
|
34
|
+
keepName && data.append("keepOriginalName", "true");
|
|
35
35
|
UploadService.execute(data)
|
|
36
36
|
.then((r) => {
|
|
37
37
|
onSuccess(r.data);
|
|
38
38
|
})
|
|
39
39
|
.catch((err) => {
|
|
40
|
-
dispatchError({ err:
|
|
40
|
+
dispatchError({ err: "error.uploading.image", t, key: "upload" });
|
|
41
41
|
onError && onError(err);
|
|
42
42
|
})
|
|
43
43
|
.finally(() => {
|
|
44
44
|
dispatch(toastLoading(false));
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
-
return (_jsx(AppModal, { title: title || t(
|
|
47
|
+
return (_jsx(AppModal, { title: title || t("modal.title"), className: "modal-upload", close: onClose, confirm: upload, alternativeButton: alternativeButton, children: _jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t("label.dropzone") })] })) })), file && preview && (_jsx("img", { className: "preview", src: preview, onLoad: () => {
|
|
48
48
|
URL.revokeObjectURL(preview);
|
|
49
|
-
} })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t(
|
|
49
|
+
} })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t("label.uploaded.file") }), _jsx("span", { children: file.name }), _jsx("b", { children: t("label.confirm") })] }))] }) }));
|
|
50
50
|
}
|