tycho-components 0.0.17-SNAPSHOT-29 → 0.0.18-SNAPSHOT

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,13 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
2
+ import { useContext, useState } from 'react';
3
3
  import Dropzone from 'react-dropzone';
4
4
  import { useTranslation } from 'react-i18next';
5
+ import AppModal from '../AppModal';
6
+ import { useMessageUtils } from '../configs/useMessageUtils';
5
7
  import './style.scss';
6
8
  import UploadService from './UploadService';
7
- import { useMessageUtils } from '../configs/useMessageUtils';
8
- import AppModal from '../AppModal';
9
+ import CommonContext from '../configs/CommonContext';
10
+ import { toastLoading } from '../configs/store/actions';
9
11
  export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, }) {
10
12
  const { t } = useTranslation('upload');
13
+ const { state, dispatch } = useContext(CommonContext);
11
14
  const { dispatchError } = useMessageUtils();
12
15
  const [file, setFile] = useState();
13
16
  const [preview, setPreview] = useState();
@@ -22,8 +25,9 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
22
25
  onDrop && onDrop();
23
26
  };
24
27
  const upload = async () => {
25
- if (!file)
28
+ if (!file || state.toastLoading)
26
29
  return;
30
+ dispatch(toastLoading(true));
27
31
  const data = new FormData();
28
32
  data.append('file', file);
29
33
  data.append('folder', folder);
@@ -35,6 +39,9 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
35
39
  .catch((err) => {
36
40
  dispatchError({ err: 'error.uploading.image', t });
37
41
  onError && onError(err);
42
+ })
43
+ .finally(() => {
44
+ dispatch(toastLoading(false));
38
45
  });
39
46
  };
40
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: () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.0.17-SNAPSHOT-29",
4
+ "version": "0.0.18-SNAPSHOT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {