tycho-components 0.9.4 → 0.10.0
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/dist/AppToast/AppToast.js +7 -4
- package/dist/configs/Localization.d.ts +3 -0
- package/dist/configs/localization/CommonTexts.d.ts +3 -0
- package/dist/configs/localization/CommonTexts.js +3 -0
- package/dist/configs/store/actions.d.ts +4 -1
- package/dist/configs/store/reducer.js +9 -1
- package/dist/configs/store/types.d.ts +5 -1
- package/dist/configs/useMessageUtils.d.ts +2 -2
- package/dist/configs/useMessageUtils.js +19 -16
- package/package.json +1 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import CommonContext from '../configs/CommonContext';
|
|
3
|
-
import { message } from '../configs/store/actions';
|
|
4
2
|
import { useContext, useEffect } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
5
4
|
import ReactLoading from 'react-loading';
|
|
6
5
|
import { ToastContainer, toast } from 'react-toastify';
|
|
7
6
|
import 'react-toastify/dist/ReactToastify.css';
|
|
7
|
+
import CommonContext from '../configs/CommonContext';
|
|
8
|
+
import { message } from '../configs/store/actions';
|
|
8
9
|
import { EMPTY_TOAST } from './ToastMessage';
|
|
9
10
|
export default function AppToast() {
|
|
11
|
+
const { t } = useTranslation('common');
|
|
10
12
|
const { dispatch, state } = useContext(CommonContext);
|
|
11
13
|
const handleClose = () => {
|
|
12
14
|
toast.dismiss();
|
|
@@ -15,7 +17,7 @@ export default function AppToast() {
|
|
|
15
17
|
const handleClipboard = () => {
|
|
16
18
|
navigator.clipboard.writeText(state.message.value);
|
|
17
19
|
};
|
|
18
|
-
const getLoading = () => (_jsxs("div", { className: "d-flex", children: [_jsx(ReactLoading, { type: "spinningBubbles", color: "blue", height: 24, width: 24 }), _jsx("span", { className: "ms-3", children:
|
|
20
|
+
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') })] }));
|
|
19
21
|
const attachCloseToEscape = () => {
|
|
20
22
|
const closeOnEscape = (e) => {
|
|
21
23
|
if (e.keyCode === 27)
|
|
@@ -30,6 +32,7 @@ export default function AppToast() {
|
|
|
30
32
|
useEffect(() => {
|
|
31
33
|
if (state.toastLoading) {
|
|
32
34
|
toast(getLoading(), {
|
|
35
|
+
toastId: 'loading',
|
|
33
36
|
position: 'top-right',
|
|
34
37
|
autoClose: false,
|
|
35
38
|
hideProgressBar: false,
|
|
@@ -43,7 +46,7 @@ export default function AppToast() {
|
|
|
43
46
|
else {
|
|
44
47
|
toast.dismiss();
|
|
45
48
|
}
|
|
46
|
-
}, [state.toastLoading]);
|
|
49
|
+
}, [state.toastLoading, state.toastLoadingText]);
|
|
47
50
|
useEffect(() => {
|
|
48
51
|
if (state.message && state.message.value !== '') {
|
|
49
52
|
switch (state.message.type) {
|
|
@@ -69,6 +69,7 @@ export declare const commonResources: {
|
|
|
69
69
|
'pagination.label.showing': string;
|
|
70
70
|
'pagination.label.results': string;
|
|
71
71
|
'pagination.label.total': string;
|
|
72
|
+
'generic.loading': string;
|
|
72
73
|
'generic.placeholder': string;
|
|
73
74
|
'generic.placeholder.comma.separated': string;
|
|
74
75
|
'generic.placeholder.select': string;
|
|
@@ -337,6 +338,7 @@ export declare const commonResources: {
|
|
|
337
338
|
'pagination.label.showing': string;
|
|
338
339
|
'pagination.label.results': string;
|
|
339
340
|
'pagination.label.total': string;
|
|
341
|
+
'generic.loading': string;
|
|
340
342
|
'generic.placeholder': string;
|
|
341
343
|
'generic.placeholder.select': string;
|
|
342
344
|
'generic.placeholder.comma.separated': string;
|
|
@@ -604,6 +606,7 @@ export declare const commonResources: {
|
|
|
604
606
|
'pagination.label.showing': string;
|
|
605
607
|
'pagination.label.results': string;
|
|
606
608
|
'pagination.label.total': string;
|
|
609
|
+
'generic.loading': string;
|
|
607
610
|
'generic.placeholder': string;
|
|
608
611
|
'generic.placeholder.select': string;
|
|
609
612
|
'generic.placeholder.comma.separated': string;
|
|
@@ -23,6 +23,7 @@ export declare const CommonTexts: {
|
|
|
23
23
|
'pagination.label.showing': string;
|
|
24
24
|
'pagination.label.results': string;
|
|
25
25
|
'pagination.label.total': string;
|
|
26
|
+
'generic.loading': string;
|
|
26
27
|
'generic.placeholder': string;
|
|
27
28
|
'generic.placeholder.comma.separated': string;
|
|
28
29
|
'generic.placeholder.select': string;
|
|
@@ -80,6 +81,7 @@ export declare const CommonTexts: {
|
|
|
80
81
|
'pagination.label.showing': string;
|
|
81
82
|
'pagination.label.results': string;
|
|
82
83
|
'pagination.label.total': string;
|
|
84
|
+
'generic.loading': string;
|
|
83
85
|
'generic.placeholder': string;
|
|
84
86
|
'generic.placeholder.select': string;
|
|
85
87
|
'generic.placeholder.comma.separated': string;
|
|
@@ -137,6 +139,7 @@ export declare const CommonTexts: {
|
|
|
137
139
|
'pagination.label.showing': string;
|
|
138
140
|
'pagination.label.results': string;
|
|
139
141
|
'pagination.label.total': string;
|
|
142
|
+
'generic.loading': string;
|
|
140
143
|
'generic.placeholder': string;
|
|
141
144
|
'generic.placeholder.select': string;
|
|
142
145
|
'generic.placeholder.comma.separated': string;
|
|
@@ -23,6 +23,7 @@ export const CommonTexts = {
|
|
|
23
23
|
'pagination.label.showing': '',
|
|
24
24
|
'pagination.label.results': 'results per page',
|
|
25
25
|
'pagination.label.total': 'Total',
|
|
26
|
+
'generic.loading': 'Loading...',
|
|
26
27
|
'generic.placeholder': 'Type here',
|
|
27
28
|
'generic.placeholder.comma.separated': 'Type here separated by commas',
|
|
28
29
|
'generic.placeholder.select': 'Select one here',
|
|
@@ -80,6 +81,7 @@ export const CommonTexts = {
|
|
|
80
81
|
'pagination.label.showing': 'Exibindo',
|
|
81
82
|
'pagination.label.results': 'resultados por página',
|
|
82
83
|
'pagination.label.total': 'Total',
|
|
84
|
+
'generic.loading': 'Carregando...',
|
|
83
85
|
'generic.placeholder': 'Digite aqui',
|
|
84
86
|
'generic.placeholder.select': 'Selecione um aqui',
|
|
85
87
|
'generic.placeholder.comma.separated': 'Digite aqui separado por vírgulas',
|
|
@@ -137,6 +139,7 @@ export const CommonTexts = {
|
|
|
137
139
|
'pagination.label.showing': 'Mostrando',
|
|
138
140
|
'pagination.label.results': 'risultati per pagina',
|
|
139
141
|
'pagination.label.total': 'Totale',
|
|
142
|
+
'generic.loading': 'Caricamento...',
|
|
140
143
|
'generic.placeholder': 'Scrivi qui',
|
|
141
144
|
'generic.placeholder.select': 'Seleziona uno qui',
|
|
142
145
|
'generic.placeholder.comma.separated': 'Scrivi qui separato per virgole',
|
|
@@ -5,6 +5,9 @@ import { StoreAction } from './types';
|
|
|
5
5
|
export declare const corpus: (data: Corpus | undefined) => StoreAction;
|
|
6
6
|
export declare const logged: (data: User | undefined) => StoreAction;
|
|
7
7
|
export declare const message: (data: ToastMessage) => StoreAction;
|
|
8
|
-
export declare const toastLoading: (data: boolean
|
|
8
|
+
export declare const toastLoading: (data: boolean | {
|
|
9
|
+
loading: boolean;
|
|
10
|
+
text?: string;
|
|
11
|
+
}) => StoreAction;
|
|
9
12
|
export declare const silentLoading: (data: boolean) => StoreAction;
|
|
10
13
|
export declare const tour: (data: boolean) => StoreAction;
|
|
@@ -17,9 +17,17 @@ function reducer(state, action) {
|
|
|
17
17
|
message: action.payload,
|
|
18
18
|
};
|
|
19
19
|
case types.TOAST_LOADING:
|
|
20
|
+
if (typeof action.payload === 'boolean') {
|
|
21
|
+
return {
|
|
22
|
+
...state,
|
|
23
|
+
toastLoading: action.payload,
|
|
24
|
+
toastLoadingText: undefined,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
20
27
|
return {
|
|
21
28
|
...state,
|
|
22
|
-
toastLoading: action.payload,
|
|
29
|
+
toastLoading: action.payload.loading,
|
|
30
|
+
toastLoadingText: action.payload.text,
|
|
23
31
|
};
|
|
24
32
|
case types.SILENT_LOADING:
|
|
25
33
|
return {
|
|
@@ -6,12 +6,16 @@ export type UserStore = {
|
|
|
6
6
|
logged: User | undefined;
|
|
7
7
|
message: ToastMessage;
|
|
8
8
|
toastLoading: boolean;
|
|
9
|
+
toastLoadingText?: string;
|
|
9
10
|
silentLoading: boolean;
|
|
10
11
|
tour: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type StoreAction = {
|
|
13
14
|
type: string;
|
|
14
|
-
payload?: Corpus | ToastMessage | boolean | User
|
|
15
|
+
payload?: Corpus | ToastMessage | boolean | User | {
|
|
16
|
+
loading: boolean;
|
|
17
|
+
text?: string;
|
|
18
|
+
};
|
|
15
19
|
};
|
|
16
20
|
export declare const types: {
|
|
17
21
|
CORPUS: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TFunction } from
|
|
1
|
+
import { TFunction } from "i18next";
|
|
2
2
|
type MessageDispatcher = {
|
|
3
3
|
key: string;
|
|
4
4
|
ns?: string;
|
|
@@ -10,7 +10,7 @@ type ErrorDispatcher = {
|
|
|
10
10
|
key?: string;
|
|
11
11
|
};
|
|
12
12
|
export declare const useMessageUtils: () => {
|
|
13
|
-
dispatchLoading: (val: boolean) => void;
|
|
13
|
+
dispatchLoading: (val: boolean, text?: string) => void;
|
|
14
14
|
dispatchError: ({ err, t, key }: ErrorDispatcher) => void;
|
|
15
15
|
dispatchMessage: ({ key, ns, t }: MessageDispatcher) => void;
|
|
16
16
|
dispatchMessageDirect: (value: string, type?: "success" | "error") => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { message, silentLoading, toastLoading } from
|
|
3
|
-
import CommonContext from
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { message, silentLoading, toastLoading } from "../configs/store/actions";
|
|
3
|
+
import CommonContext from "./CommonContext";
|
|
4
4
|
export const useMessageUtils = () => {
|
|
5
5
|
const { state, dispatch } = useContext(CommonContext);
|
|
6
6
|
const isSilentLoading = () => {
|
|
@@ -12,38 +12,41 @@ export const useMessageUtils = () => {
|
|
|
12
12
|
const isLoading = () => {
|
|
13
13
|
return state.toastLoading;
|
|
14
14
|
};
|
|
15
|
-
const dispatchLoading = (val) => {
|
|
16
|
-
dispatch(toastLoading(val));
|
|
15
|
+
const dispatchLoading = (val, text) => {
|
|
16
|
+
dispatch(text !== undefined ? toastLoading({ loading: val, text }) : toastLoading(val));
|
|
17
17
|
};
|
|
18
18
|
const dispatchError = ({ err, t, key }) => {
|
|
19
19
|
if (!err.response) {
|
|
20
|
-
const value = t(`${key ??
|
|
21
|
-
dispatch(message({ value, type:
|
|
20
|
+
const value = t(`${key ?? "message"}:${err}`);
|
|
21
|
+
dispatch(message({ value, type: "error" }));
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
if (err.response.status === 403) {
|
|
25
|
-
dispatch(message({ value: t(
|
|
25
|
+
dispatch(message({ value: t("error.access.authorization"), type: "error" }));
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
let errorKey =
|
|
29
|
-
if (err.response.data?.
|
|
28
|
+
let errorKey = "";
|
|
29
|
+
if (err.response.data?.message) {
|
|
30
|
+
errorKey = err.response.data.message;
|
|
31
|
+
}
|
|
32
|
+
else if (err.response.data?.description) {
|
|
30
33
|
errorKey = err.response.data.description;
|
|
31
34
|
}
|
|
32
35
|
else if (err.response.data?.errors?.length > 0) {
|
|
33
36
|
errorKey = err.response.data.errors[0].description;
|
|
34
37
|
}
|
|
35
38
|
else {
|
|
36
|
-
key =
|
|
37
|
-
errorKey =
|
|
39
|
+
key = "common";
|
|
40
|
+
errorKey = "internal.server.error";
|
|
38
41
|
}
|
|
39
|
-
const value = t(`${key ??
|
|
40
|
-
dispatch(message({ value, type:
|
|
42
|
+
const value = t(`${key ?? "message"}:${errorKey}`);
|
|
43
|
+
dispatch(message({ value, type: "error" }));
|
|
41
44
|
};
|
|
42
45
|
const dispatchMessage = ({ key, ns, t }) => {
|
|
43
46
|
const entry = ns ? `${ns}:${key}` : `message:${key}`;
|
|
44
|
-
dispatch(message({ value: t(entry), type:
|
|
47
|
+
dispatch(message({ value: t(entry), type: "success" }));
|
|
45
48
|
};
|
|
46
|
-
const dispatchMessageDirect = (value, type =
|
|
49
|
+
const dispatchMessageDirect = (value, type = "success") => {
|
|
47
50
|
dispatch(message({ value, type }));
|
|
48
51
|
};
|
|
49
52
|
return {
|