nurseitaly-components 0.0.4 → 0.0.6
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.
|
@@ -9,5 +9,5 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
|
|
|
9
9
|
const handleConfirm = () => {
|
|
10
10
|
bodyRef.current?.upload();
|
|
11
11
|
};
|
|
12
|
-
return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: handleConfirm, disableConfirm: disableConfirm, alternativeButton: alternativeButton, children: _jsx(AppDropzoneBody, { ref: bodyRef, folder: folder, onSuccess: onSuccess, onError: onError, accept: accept, messages: messages, onDrop: onDrop, keepName: keepName, showConfirmButton: false }) }));
|
|
12
|
+
return (_jsx(AppModal, { title: title || t('modal.title', { defaultValue: 'Upload a file' }), className: "modal-upload", close: onClose, confirm: handleConfirm, disableConfirm: disableConfirm, alternativeButton: alternativeButton, children: _jsx(AppDropzoneBody, { ref: bodyRef, folder: folder, onSuccess: onSuccess, onError: onError, accept: accept, messages: messages, onDrop: onDrop, keepName: keepName, showConfirmButton: false }) }));
|
|
13
13
|
}
|
|
@@ -66,9 +66,14 @@ function AppDropzoneBodyInner({ folder, onSuccess, onError, accept, messages, on
|
|
|
66
66
|
};
|
|
67
67
|
const resolveMessage = (key) => {
|
|
68
68
|
const customMessage = messages?.[key]?.trim();
|
|
69
|
-
return customMessage ||
|
|
69
|
+
return (customMessage ||
|
|
70
|
+
t(key, {
|
|
71
|
+
defaultValue: key === 'label.dropzone'
|
|
72
|
+
? 'Drag and drop or click to upload a file'
|
|
73
|
+
: 'You are uploading the following file:',
|
|
74
|
+
}));
|
|
70
75
|
};
|
|
71
|
-
return (_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: resolveMessage('label.dropzone') })] })) })), file && (_jsxs("div", { className: "uploaded-file", children: [preview && _jsx("img", { className: "preview", src: preview, alt: "" }), !preview && (_jsxs(_Fragment, { children: [_jsx("b", { children: resolveMessage('label.uploaded.file') }), _jsx("span", { children: file.name })] })), showConfirmButton && (_jsxs("div", { className: "buttons", children: [_jsx(Button, { onClick: handleCancel, text: t('common:button.cancel'), size: "small", mode: "outlined", color: "danger" }), _jsx(Button, { onClick: upload, text: t('common:button.confirm'), size: "small", mode: "outlined", disabled: disableConfirm })] }))] }))] }));
|
|
76
|
+
return (_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: resolveMessage('label.dropzone') })] })) })), file && (_jsxs("div", { className: "uploaded-file", children: [preview && _jsx("img", { className: "preview", src: preview, alt: "" }), !preview && (_jsxs(_Fragment, { children: [_jsx("b", { children: resolveMessage('label.uploaded.file') }), _jsx("span", { children: file.name })] })), showConfirmButton && (_jsxs("div", { className: "buttons", children: [_jsx(Button, { onClick: handleCancel, text: t('common:button.cancel', { defaultValue: 'Cancel' }), size: "small", mode: "outlined", color: "danger" }), _jsx(Button, { onClick: upload, text: t('common:button.confirm', { defaultValue: 'Confirm' }), size: "small", mode: "outlined", disabled: disableConfirm })] }))] }))] }));
|
|
72
77
|
}
|
|
73
78
|
const AppDropzoneBody = forwardRef(AppDropzoneBodyInner);
|
|
74
79
|
export default AppDropzoneBody;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useContext, useEffect } from 'react';
|
|
2
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import ReactLoading from 'react-loading';
|
|
5
5
|
import { ToastContainer, toast } from 'react-toastify';
|
|
@@ -7,75 +7,74 @@ import 'react-toastify/dist/ReactToastify.css';
|
|
|
7
7
|
import CommonContext from '../../configs/CommonContext';
|
|
8
8
|
import { messageAction } from '../../configs/sessionTypes';
|
|
9
9
|
import { EMPTY_TOAST } from './ToastMessage';
|
|
10
|
+
const LOADING_TOAST_ID = 'loading';
|
|
11
|
+
const MESSAGE_TOAST_ID = 'app-message';
|
|
12
|
+
const MESSAGE_AUTO_CLOSE_MS = 5000;
|
|
10
13
|
export default function AppToast() {
|
|
11
14
|
const { t } = useTranslation('common');
|
|
12
15
|
const { dispatch, state } = useContext(CommonContext);
|
|
13
|
-
const
|
|
14
|
-
|
|
16
|
+
const messageValueRef = useRef(state.message.value);
|
|
17
|
+
messageValueRef.current = state.message.value;
|
|
18
|
+
const clearMessage = () => {
|
|
19
|
+
if (!messageValueRef.current)
|
|
20
|
+
return;
|
|
15
21
|
dispatch(messageAction(EMPTY_TOAST));
|
|
16
22
|
};
|
|
17
|
-
const handleClipboard = () => {
|
|
18
|
-
navigator.clipboard.writeText(state.message.value);
|
|
19
|
-
};
|
|
20
23
|
const getLoading = () => (_jsxs("div", { className: "d-flex", children: [_jsx(ReactLoading, { type: "spinningBubbles", color: "blue", height: 24, width: 24 }), _jsx("span", { className: "ms-3", children: state.toastLoadingText ?? t('generic.loading') })] }));
|
|
21
|
-
|
|
24
|
+
useEffect(() => {
|
|
22
25
|
const closeOnEscape = (e) => {
|
|
23
|
-
if (e.
|
|
24
|
-
|
|
26
|
+
if (e.key === 'Escape')
|
|
27
|
+
toast.dismiss(MESSAGE_TOAST_ID);
|
|
25
28
|
};
|
|
26
29
|
window.addEventListener('keydown', closeOnEscape);
|
|
27
30
|
return () => window.removeEventListener('keydown', closeOnEscape);
|
|
28
|
-
};
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
attachCloseToEscape();
|
|
31
31
|
}, []);
|
|
32
32
|
useEffect(() => {
|
|
33
33
|
if (state.toastLoading) {
|
|
34
34
|
toast(getLoading(), {
|
|
35
|
-
toastId:
|
|
35
|
+
toastId: LOADING_TOAST_ID,
|
|
36
36
|
position: 'top-right',
|
|
37
37
|
autoClose: false,
|
|
38
|
-
hideProgressBar:
|
|
38
|
+
hideProgressBar: true,
|
|
39
39
|
closeOnClick: false,
|
|
40
40
|
pauseOnHover: true,
|
|
41
41
|
draggable: false,
|
|
42
|
-
progress: undefined,
|
|
43
42
|
theme: 'light',
|
|
44
43
|
});
|
|
45
44
|
}
|
|
46
45
|
else {
|
|
47
|
-
toast.dismiss();
|
|
46
|
+
toast.dismiss(LOADING_TOAST_ID);
|
|
48
47
|
}
|
|
49
48
|
}, [state.toastLoading, state.toastLoadingText]);
|
|
50
49
|
useEffect(() => {
|
|
51
|
-
if (state.message
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
50
|
+
if (!state.message?.value)
|
|
51
|
+
return;
|
|
52
|
+
const baseOptions = {
|
|
53
|
+
toastId: MESSAGE_TOAST_ID,
|
|
54
|
+
autoClose: MESSAGE_AUTO_CLOSE_MS,
|
|
55
|
+
closeOnClick: true,
|
|
56
|
+
pauseOnFocusLoss: false,
|
|
57
|
+
onClose: () => clearMessage(),
|
|
58
|
+
};
|
|
59
|
+
switch (state.message.type) {
|
|
60
|
+
case 'error':
|
|
61
|
+
toast.error(state.message.value, {
|
|
62
|
+
...baseOptions,
|
|
63
|
+
onClick: () => {
|
|
64
|
+
navigator.clipboard.writeText(state.message.value);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
break;
|
|
68
|
+
case 'warning':
|
|
69
|
+
toast.warning(state.message.value, baseOptions);
|
|
70
|
+
break;
|
|
71
|
+
case 'success':
|
|
72
|
+
toast.success(state.message.value, baseOptions);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
toast(state.message.value, baseOptions);
|
|
76
|
+
break;
|
|
78
77
|
}
|
|
79
78
|
}, [state.message]);
|
|
80
|
-
return _jsx(ToastContainer, { closeOnClick: true });
|
|
79
|
+
return (_jsx(ToastContainer, { closeOnClick: true, autoClose: MESSAGE_AUTO_CLOSE_MS, pauseOnFocusLoss: false }));
|
|
81
80
|
}
|