nurseitaly-components 0.0.4 → 0.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.
@@ -7,75 +7,79 @@ 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 handleClose = () => {
14
- toast.dismiss();
16
+ const clearMessage = () => {
15
17
  dispatch(messageAction(EMPTY_TOAST));
16
18
  };
19
+ const handleClose = () => {
20
+ toast.dismiss(MESSAGE_TOAST_ID);
21
+ clearMessage();
22
+ };
17
23
  const handleClipboard = () => {
18
24
  navigator.clipboard.writeText(state.message.value);
19
25
  };
20
26
  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
- const attachCloseToEscape = () => {
27
+ useEffect(() => {
22
28
  const closeOnEscape = (e) => {
23
- if (e.keyCode === 27)
29
+ if (e.key === 'Escape')
24
30
  handleClose();
25
31
  };
26
32
  window.addEventListener('keydown', closeOnEscape);
27
33
  return () => window.removeEventListener('keydown', closeOnEscape);
28
- };
29
- useEffect(() => {
30
- attachCloseToEscape();
31
34
  }, []);
32
35
  useEffect(() => {
33
36
  if (state.toastLoading) {
34
37
  toast(getLoading(), {
35
- toastId: 'loading',
38
+ toastId: LOADING_TOAST_ID,
36
39
  position: 'top-right',
37
40
  autoClose: false,
38
- hideProgressBar: false,
41
+ hideProgressBar: true,
39
42
  closeOnClick: false,
40
43
  pauseOnHover: true,
41
44
  draggable: false,
42
- progress: undefined,
43
45
  theme: 'light',
44
46
  });
45
47
  }
46
48
  else {
47
- toast.dismiss();
49
+ toast.dismiss(LOADING_TOAST_ID);
48
50
  }
49
51
  }, [state.toastLoading, state.toastLoadingText]);
50
52
  useEffect(() => {
51
- if (state.message && state.message.value !== '') {
52
- switch (state.message.type) {
53
- case 'error':
54
- toast.error(state.message.value, {
55
- onClose: () => handleClose(),
56
- onClick: () => handleClipboard(),
57
- });
58
- break;
59
- case 'warning':
60
- toast.warning(state.message.value, {
61
- onClose: () => handleClose(),
62
- });
63
- break;
64
- case 'success':
65
- toast.success(state.message.value, {
66
- onClose: () => handleClose(),
67
- });
68
- break;
69
- default:
70
- toast(state.message.value, {
71
- onClose: () => handleClose(),
72
- });
73
- break;
74
- }
53
+ if (!state.message?.value) {
54
+ return;
75
55
  }
76
- else {
77
- dispatch(messageAction(EMPTY_TOAST));
56
+ const baseOptions = {
57
+ toastId: MESSAGE_TOAST_ID,
58
+ autoClose: MESSAGE_AUTO_CLOSE_MS,
59
+ closeOnClick: true,
60
+ pauseOnFocusLoss: false,
61
+ onClose: () => clearMessage(),
62
+ };
63
+ switch (state.message.type) {
64
+ case 'error':
65
+ toast.error(state.message.value, {
66
+ ...baseOptions,
67
+ onClick: () => handleClipboard(),
68
+ });
69
+ break;
70
+ case 'warning':
71
+ toast.warning(state.message.value, baseOptions);
72
+ break;
73
+ case 'success':
74
+ toast.success(state.message.value, {
75
+ ...baseOptions,
76
+ onClick: () => handleClose(),
77
+ });
78
+ break;
79
+ default:
80
+ toast(state.message.value, baseOptions);
81
+ break;
78
82
  }
79
83
  }, [state.message]);
80
- return _jsx(ToastContainer, { closeOnClick: true });
84
+ return (_jsx(ToastContainer, { closeOnClick: true, autoClose: MESSAGE_AUTO_CLOSE_MS, pauseOnFocusLoss: false }));
81
85
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nurseitaly-components",
3
3
  "private": false,
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {