@zauru-sdk/hooks 2.0.89 → 2.0.94
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/esm/automaticNumbers.js +57 -44
- package/dist/esm/catalogs.js +52 -42
- package/dist/esm/onlineStatus.js +27 -22
- package/dist/esm/profiles.js +54 -44
- package/dist/esm/receptions.js +66 -56
- package/dist/esm/session.js +51 -37
- package/dist/esm/templates.js +50 -45
- package/dist/esm/useWindowDimensions.js +22 -16
- package/package.json +5 -5
|
@@ -6,52 +6,65 @@ const redux_1 = require("@zauru-sdk/redux");
|
|
|
6
6
|
const react_2 = require("react");
|
|
7
7
|
const index_js_1 = require("./index.js");
|
|
8
8
|
const useGetAutomaticNumber = (AUTOMATIC_NUMBER_NAME) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
description: fetcher.data?.description,
|
|
22
|
-
title: fetcher.data?.title,
|
|
23
|
-
type: fetcher.data?.type,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}, [fetcher.data]);
|
|
27
|
-
(0, react_2.useEffect)(() => {
|
|
28
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
29
|
-
const receivedData = fetcher.data;
|
|
30
|
-
if (receivedData) {
|
|
31
|
-
setData({ data: receivedData[AUTOMATIC_NUMBER_NAME], loading: false });
|
|
32
|
-
dispatch((0, redux_1.automaticNumberFetchSuccess)({
|
|
33
|
-
name: AUTOMATIC_NUMBER_NAME,
|
|
34
|
-
data: receivedData[AUTOMATIC_NUMBER_NAME],
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, [fetcher, dispatch, AUTOMATIC_NUMBER_NAME]);
|
|
39
|
-
(0, react_2.useEffect)(() => {
|
|
40
|
-
if (objectData?.data && Object.keys(objectData?.data).length <= 0) {
|
|
41
|
-
try {
|
|
42
|
-
setData({ ...data, loading: true });
|
|
43
|
-
dispatch((0, redux_1.automaticNumberFetchStart)(AUTOMATIC_NUMBER_NAME));
|
|
44
|
-
fetcher.load(`/api/automaticNumbers?object=${AUTOMATIC_NUMBER_NAME}`);
|
|
45
|
-
}
|
|
46
|
-
catch (ex) {
|
|
9
|
+
try {
|
|
10
|
+
const fetcher = (0, react_1.useFetcher)();
|
|
11
|
+
const dispatch = (0, redux_1.useAppDispatch)();
|
|
12
|
+
const objectData = (0, redux_1.useAppSelector)((state) => state.automaticNumbers[AUTOMATIC_NUMBER_NAME]);
|
|
13
|
+
const [data, setData] = (0, react_2.useState)({
|
|
14
|
+
data: objectData?.data && Object.keys(objectData?.data).length
|
|
15
|
+
? objectData?.data
|
|
16
|
+
: {},
|
|
17
|
+
loading: objectData.loading,
|
|
18
|
+
});
|
|
19
|
+
(0, react_2.useEffect)(() => {
|
|
20
|
+
if (fetcher.data?.title) {
|
|
47
21
|
(0, index_js_1.showAlert)({
|
|
48
|
-
|
|
49
|
-
title:
|
|
50
|
-
|
|
22
|
+
description: fetcher.data?.description,
|
|
23
|
+
title: fetcher.data?.title,
|
|
24
|
+
type: fetcher.data?.type,
|
|
51
25
|
});
|
|
52
26
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
}, [fetcher.data]);
|
|
28
|
+
(0, react_2.useEffect)(() => {
|
|
29
|
+
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
30
|
+
const receivedData = fetcher.data;
|
|
31
|
+
if (receivedData) {
|
|
32
|
+
setData({
|
|
33
|
+
data: receivedData[AUTOMATIC_NUMBER_NAME],
|
|
34
|
+
loading: false,
|
|
35
|
+
});
|
|
36
|
+
dispatch((0, redux_1.automaticNumberFetchSuccess)({
|
|
37
|
+
name: AUTOMATIC_NUMBER_NAME,
|
|
38
|
+
data: receivedData[AUTOMATIC_NUMBER_NAME],
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, [fetcher, dispatch, AUTOMATIC_NUMBER_NAME]);
|
|
43
|
+
(0, react_2.useEffect)(() => {
|
|
44
|
+
if (objectData?.data && Object.keys(objectData?.data).length <= 0) {
|
|
45
|
+
try {
|
|
46
|
+
setData({ ...data, loading: true });
|
|
47
|
+
dispatch((0, redux_1.automaticNumberFetchStart)(AUTOMATIC_NUMBER_NAME));
|
|
48
|
+
fetcher.load(`/api/automaticNumbers?object=${AUTOMATIC_NUMBER_NAME}`);
|
|
49
|
+
}
|
|
50
|
+
catch (ex) {
|
|
51
|
+
(0, index_js_1.showAlert)({
|
|
52
|
+
type: "error",
|
|
53
|
+
title: `Ocurrió un error al cargar el object de automatic numbers: ${AUTOMATIC_NUMBER_NAME}.`,
|
|
54
|
+
description: "Error: " + ex,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, []);
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
catch (ex) {
|
|
62
|
+
(0, index_js_1.showAlert)({
|
|
63
|
+
type: "error",
|
|
64
|
+
title: `Ocurrió un error al cargar el object de automatic numbers: ${AUTOMATIC_NUMBER_NAME}.`,
|
|
65
|
+
description: "Error: " + ex,
|
|
66
|
+
});
|
|
67
|
+
return { data: {}, loading: false };
|
|
68
|
+
}
|
|
56
69
|
};
|
|
57
70
|
exports.useGetAutomaticNumber = useGetAutomaticNumber;
|
package/dist/esm/catalogs.js
CHANGED
|
@@ -6,49 +6,59 @@ const react_2 = require("react");
|
|
|
6
6
|
const index_js_1 = require("./components/index.js");
|
|
7
7
|
const redux_1 = require("@zauru-sdk/redux");
|
|
8
8
|
const useApiCatalog = (CATALOG_NAME, otherParams) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
data
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, [fetcher.data]);
|
|
23
|
-
(0, react_2.useEffect)(() => {
|
|
24
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
25
|
-
const receivedData = fetcher.data;
|
|
26
|
-
if (receivedData) {
|
|
27
|
-
setData({ data: receivedData[CATALOG_NAME], loading: false });
|
|
9
|
+
try {
|
|
10
|
+
const fetcher = (0, react_1.useFetcher)();
|
|
11
|
+
const [data, setData] = (0, react_2.useState)({
|
|
12
|
+
data: [],
|
|
13
|
+
loading: true,
|
|
14
|
+
});
|
|
15
|
+
(0, react_2.useEffect)(() => {
|
|
16
|
+
if (fetcher.data?.title) {
|
|
17
|
+
(0, index_js_1.showAlert)({
|
|
18
|
+
description: fetcher.data?.description?.toString(),
|
|
19
|
+
title: fetcher.data?.title?.toString(),
|
|
20
|
+
type: fetcher.data?.type?.toString(),
|
|
21
|
+
});
|
|
28
22
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
}, [fetcher.data]);
|
|
24
|
+
(0, react_2.useEffect)(() => {
|
|
25
|
+
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
26
|
+
const receivedData = fetcher.data;
|
|
27
|
+
if (receivedData) {
|
|
28
|
+
setData({ data: receivedData[CATALOG_NAME], loading: false });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, [fetcher, CATALOG_NAME]);
|
|
32
|
+
(0, react_2.useEffect)(() => {
|
|
33
|
+
try {
|
|
34
|
+
setData({ ...data, loading: true });
|
|
35
|
+
// Convert otherParams to query string
|
|
36
|
+
const paramsString = otherParams
|
|
37
|
+
? Object.entries(otherParams)
|
|
38
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
39
|
+
.join("&")
|
|
40
|
+
: "";
|
|
41
|
+
const url = `/api/catalogs?catalog=${CATALOG_NAME}${paramsString ? `&${paramsString}` : ""}`;
|
|
42
|
+
fetcher.load(url);
|
|
43
|
+
}
|
|
44
|
+
catch (ex) {
|
|
45
|
+
(0, index_js_1.showAlert)({
|
|
46
|
+
type: "error",
|
|
47
|
+
title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
|
|
48
|
+
description: "Error: " + ex,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}, []);
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
catch (ex) {
|
|
55
|
+
(0, index_js_1.showAlert)({
|
|
56
|
+
type: "error",
|
|
57
|
+
title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
|
|
58
|
+
description: "Error: " + ex,
|
|
59
|
+
});
|
|
60
|
+
return { data: [], loading: false };
|
|
61
|
+
}
|
|
52
62
|
};
|
|
53
63
|
/**
|
|
54
64
|
*
|
package/dist/esm/onlineStatus.js
CHANGED
|
@@ -4,28 +4,33 @@ exports.useIsOnline = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
// Hook personalizado para verificar el estado de conexión
|
|
6
6
|
const useIsOnline = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(0, react_1.useEffect)(() => {
|
|
16
|
-
if (isServer) {
|
|
17
|
-
// Si estamos en el servidor, no añadir los event listeners
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
// Añadir event listeners
|
|
21
|
-
window.addEventListener("online", handleConnectionChange);
|
|
22
|
-
window.addEventListener("offline", handleConnectionChange);
|
|
23
|
-
// Limpiar event listeners al desmontar el componente
|
|
24
|
-
return () => {
|
|
25
|
-
window.removeEventListener("online", handleConnectionChange);
|
|
26
|
-
window.removeEventListener("offline", handleConnectionChange);
|
|
7
|
+
try {
|
|
8
|
+
// Verificar si estamos en el entorno del servidor o del cliente
|
|
9
|
+
const isServer = typeof window === "undefined";
|
|
10
|
+
// Estado local para almacenar si la aplicación está en línea o no
|
|
11
|
+
const [isOnline, setIsOnline] = (0, react_1.useState)(!isServer && navigator.onLine);
|
|
12
|
+
// Función para manejar el cambio de estado de conexión
|
|
13
|
+
const handleConnectionChange = () => {
|
|
14
|
+
setIsOnline(navigator.onLine);
|
|
27
15
|
};
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
if (isServer) {
|
|
18
|
+
// Si estamos en el servidor, no añadir los event listeners
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// Añadir event listeners
|
|
22
|
+
window.addEventListener("online", handleConnectionChange);
|
|
23
|
+
window.addEventListener("offline", handleConnectionChange);
|
|
24
|
+
// Limpiar event listeners al desmontar el componente
|
|
25
|
+
return () => {
|
|
26
|
+
window.removeEventListener("online", handleConnectionChange);
|
|
27
|
+
window.removeEventListener("offline", handleConnectionChange);
|
|
28
|
+
};
|
|
29
|
+
}, [isServer]);
|
|
30
|
+
return isOnline;
|
|
31
|
+
}
|
|
32
|
+
catch (ex) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
30
35
|
};
|
|
31
36
|
exports.useIsOnline = useIsOnline;
|
package/dist/esm/profiles.js
CHANGED
|
@@ -6,53 +6,63 @@ const react_2 = require("react");
|
|
|
6
6
|
const index_js_1 = require("./index.js");
|
|
7
7
|
const redux_1 = require("@zauru-sdk/redux");
|
|
8
8
|
const useGetProfile = (PROFILE_NAME) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
data
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
description: fetcher.data?.description?.toString(),
|
|
22
|
-
title: fetcher.data?.title?.toString(),
|
|
23
|
-
type: fetcher.data?.type?.toString(),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}, [fetcher.data]);
|
|
27
|
-
(0, react_2.useEffect)(() => {
|
|
28
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
29
|
-
const receivedData = fetcher.data;
|
|
30
|
-
if (receivedData) {
|
|
31
|
-
setData({ data: receivedData[PROFILE_NAME], loading: false });
|
|
32
|
-
dispatch((0, redux_1.profileFetchSuccess)({
|
|
33
|
-
name: PROFILE_NAME,
|
|
34
|
-
data: receivedData[PROFILE_NAME],
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, [fetcher, dispatch, PROFILE_NAME]);
|
|
39
|
-
(0, react_2.useEffect)(() => {
|
|
40
|
-
if (Object.keys(profileData?.data).length <= 0) {
|
|
41
|
-
try {
|
|
42
|
-
setData({ ...data, loading: true });
|
|
43
|
-
dispatch((0, redux_1.profileFetchStart)(PROFILE_NAME));
|
|
44
|
-
fetcher.load(`/api/profiles?profile=${PROFILE_NAME}`);
|
|
45
|
-
}
|
|
46
|
-
catch (ex) {
|
|
9
|
+
try {
|
|
10
|
+
const fetcher = (0, react_1.useFetcher)();
|
|
11
|
+
const dispatch = (0, redux_1.useAppDispatch)();
|
|
12
|
+
const profileData = (0, redux_1.useAppSelector)((state) => state.profiles[PROFILE_NAME]);
|
|
13
|
+
const [data, setData] = (0, react_2.useState)({
|
|
14
|
+
data: Object.keys(profileData?.data)?.length
|
|
15
|
+
? profileData?.data
|
|
16
|
+
: {},
|
|
17
|
+
loading: profileData?.loading,
|
|
18
|
+
});
|
|
19
|
+
(0, react_2.useEffect)(() => {
|
|
20
|
+
if (fetcher.data?.title) {
|
|
47
21
|
(0, index_js_1.showAlert)({
|
|
48
|
-
|
|
49
|
-
title:
|
|
50
|
-
|
|
22
|
+
description: fetcher.data?.description?.toString(),
|
|
23
|
+
title: fetcher.data?.title?.toString(),
|
|
24
|
+
type: fetcher.data?.type?.toString(),
|
|
51
25
|
});
|
|
52
26
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
}, [fetcher.data]);
|
|
28
|
+
(0, react_2.useEffect)(() => {
|
|
29
|
+
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
30
|
+
const receivedData = fetcher.data;
|
|
31
|
+
if (receivedData) {
|
|
32
|
+
setData({ data: receivedData[PROFILE_NAME], loading: false });
|
|
33
|
+
dispatch((0, redux_1.profileFetchSuccess)({
|
|
34
|
+
name: PROFILE_NAME,
|
|
35
|
+
data: receivedData[PROFILE_NAME],
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [fetcher, dispatch, PROFILE_NAME]);
|
|
40
|
+
(0, react_2.useEffect)(() => {
|
|
41
|
+
if (Object.keys(profileData?.data).length <= 0) {
|
|
42
|
+
try {
|
|
43
|
+
setData({ ...data, loading: true });
|
|
44
|
+
dispatch((0, redux_1.profileFetchStart)(PROFILE_NAME));
|
|
45
|
+
fetcher.load(`/api/profiles?profile=${PROFILE_NAME}`);
|
|
46
|
+
}
|
|
47
|
+
catch (ex) {
|
|
48
|
+
(0, index_js_1.showAlert)({
|
|
49
|
+
type: "error",
|
|
50
|
+
title: `Ocurrió un error al cargar el perfil: ${PROFILE_NAME}.`,
|
|
51
|
+
description: "Error: " + ex,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, []);
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
catch (ex) {
|
|
59
|
+
(0, index_js_1.showAlert)({
|
|
60
|
+
type: "error",
|
|
61
|
+
title: `Ocurrió un error al cargar el perfil: ${PROFILE_NAME}.`,
|
|
62
|
+
description: "Error: " + ex,
|
|
63
|
+
});
|
|
64
|
+
return { data: {}, loading: false };
|
|
65
|
+
}
|
|
56
66
|
};
|
|
57
67
|
const useGetAgencyProfile = () => useGetProfile("agencyProfile");
|
|
58
68
|
exports.useGetAgencyProfile = useGetAgencyProfile;
|
package/dist/esm/receptions.js
CHANGED
|
@@ -7,65 +7,75 @@ const react_2 = require("react");
|
|
|
7
7
|
const index_js_1 = require("./index.js");
|
|
8
8
|
const common_1 = require("@zauru-sdk/common");
|
|
9
9
|
const useGetReceptionObject = (RECEPTION_NAME, { online = false, wheres = [] } = {}) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
data
|
|
15
|
-
|
|
16
|
-
? objectData?.data
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
description: fetcher.data?.description?.toString(),
|
|
27
|
-
title: fetcher.data?.title?.toString(),
|
|
28
|
-
type: fetcher.data?.type?.toString(),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}, [fetcher.data]);
|
|
32
|
-
(0, react_2.useEffect)(() => {
|
|
33
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
34
|
-
const receivedData = fetcher.data;
|
|
35
|
-
if (receivedData) {
|
|
36
|
-
setData({ data: receivedData[RECEPTION_NAME], loading: false });
|
|
37
|
-
dispatch((0, redux_1.receptionFetchSuccess)({
|
|
38
|
-
name: RECEPTION_NAME,
|
|
39
|
-
data: receivedData[RECEPTION_NAME],
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}, [fetcher, dispatch, RECEPTION_NAME]);
|
|
44
|
-
(0, react_2.useEffect)(() => {
|
|
45
|
-
const isEmptyData = (objectData?.data &&
|
|
46
|
-
Array.isArray(objectData?.data) &&
|
|
47
|
-
objectData?.data.length <= 0) ||
|
|
48
|
-
(objectData?.data && Object.keys(objectData?.data).length <= 0);
|
|
49
|
-
if (isEmptyData || objectData.reFetch || online) {
|
|
50
|
-
try {
|
|
51
|
-
setData({ ...data, loading: true });
|
|
52
|
-
dispatch((0, redux_1.receptionFetchStart)(RECEPTION_NAME));
|
|
53
|
-
// Convierte cada elemento del array a una cadena codificada para URL
|
|
54
|
-
const encodedWheres = wheres.map((where) => encodeURIComponent(where));
|
|
55
|
-
// Une los elementos codificados con '&'
|
|
56
|
-
const wheresQueryParam = encodedWheres.join("&");
|
|
57
|
-
fetcher.load(`/api/receptions?object=${RECEPTION_NAME}&wheres=${wheresQueryParam}`);
|
|
58
|
-
}
|
|
59
|
-
catch (ex) {
|
|
10
|
+
try {
|
|
11
|
+
const fetcher = (0, react_1.useFetcher)();
|
|
12
|
+
const dispatch = (0, redux_1.useAppDispatch)();
|
|
13
|
+
const objectData = (0, redux_1.useAppSelector)((state) => state.receptions[RECEPTION_NAME]);
|
|
14
|
+
const [data, setData] = (0, react_2.useState)({
|
|
15
|
+
data: Array.isArray(objectData?.data)
|
|
16
|
+
? objectData?.data.length
|
|
17
|
+
? objectData?.data
|
|
18
|
+
: []
|
|
19
|
+
: Object.keys(objectData?.data || {}).length
|
|
20
|
+
? objectData?.data
|
|
21
|
+
: {},
|
|
22
|
+
loading: objectData.loading,
|
|
23
|
+
});
|
|
24
|
+
(0, react_2.useEffect)(() => {
|
|
25
|
+
if (fetcher.data?.title) {
|
|
60
26
|
(0, index_js_1.showAlert)({
|
|
61
|
-
|
|
62
|
-
title:
|
|
63
|
-
|
|
27
|
+
description: fetcher.data?.description?.toString(),
|
|
28
|
+
title: fetcher.data?.title?.toString(),
|
|
29
|
+
type: fetcher.data?.type?.toString(),
|
|
64
30
|
});
|
|
65
31
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
32
|
+
}, [fetcher.data]);
|
|
33
|
+
(0, react_2.useEffect)(() => {
|
|
34
|
+
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
35
|
+
const receivedData = fetcher.data;
|
|
36
|
+
if (receivedData) {
|
|
37
|
+
setData({ data: receivedData[RECEPTION_NAME], loading: false });
|
|
38
|
+
dispatch((0, redux_1.receptionFetchSuccess)({
|
|
39
|
+
name: RECEPTION_NAME,
|
|
40
|
+
data: receivedData[RECEPTION_NAME],
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, [fetcher, dispatch, RECEPTION_NAME]);
|
|
45
|
+
(0, react_2.useEffect)(() => {
|
|
46
|
+
const isEmptyData = (objectData?.data &&
|
|
47
|
+
Array.isArray(objectData?.data) &&
|
|
48
|
+
objectData?.data.length <= 0) ||
|
|
49
|
+
(objectData?.data && Object.keys(objectData?.data).length <= 0);
|
|
50
|
+
if (isEmptyData || objectData.reFetch || online) {
|
|
51
|
+
try {
|
|
52
|
+
setData({ ...data, loading: true });
|
|
53
|
+
dispatch((0, redux_1.receptionFetchStart)(RECEPTION_NAME));
|
|
54
|
+
// Convierte cada elemento del array a una cadena codificada para URL
|
|
55
|
+
const encodedWheres = wheres.map((where) => encodeURIComponent(where));
|
|
56
|
+
// Une los elementos codificados con '&'
|
|
57
|
+
const wheresQueryParam = encodedWheres.join("&");
|
|
58
|
+
fetcher.load(`/api/receptions?object=${RECEPTION_NAME}&wheres=${wheresQueryParam}`);
|
|
59
|
+
}
|
|
60
|
+
catch (ex) {
|
|
61
|
+
(0, index_js_1.showAlert)({
|
|
62
|
+
type: "error",
|
|
63
|
+
title: `Ocurrió un error al cargar el object de receptions: ${RECEPTION_NAME}.`,
|
|
64
|
+
description: "Error: " + ex,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, []);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
catch (ex) {
|
|
72
|
+
(0, index_js_1.showAlert)({
|
|
73
|
+
type: "error",
|
|
74
|
+
title: `Ocurrió un error al cargar el object de receptions: ${RECEPTION_NAME}.`,
|
|
75
|
+
description: "Error: " + ex,
|
|
76
|
+
});
|
|
77
|
+
return { data: {}, loading: false };
|
|
78
|
+
}
|
|
69
79
|
};
|
|
70
80
|
const useGetProcesses = (config) => useGetReceptionObject("queueReceptions", config);
|
|
71
81
|
exports.useGetProcesses = useGetProcesses;
|
package/dist/esm/session.js
CHANGED
|
@@ -11,45 +11,59 @@ const index_js_1 = require("./index.js");
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
const useGetSessionAttribute = (name, type) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
description: fetcher.data?.description,
|
|
22
|
-
title: fetcher.data?.title,
|
|
23
|
-
type: fetcher.data?.type,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}, [fetcher.data]);
|
|
27
|
-
(0, react_2.useEffect)(() => {
|
|
28
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
29
|
-
const receivedData = fetcher.data;
|
|
30
|
-
if (receivedData) {
|
|
31
|
-
setData(receivedData.data);
|
|
32
|
-
dispatch((0, redux_1.setSessionValue)({
|
|
33
|
-
name: name,
|
|
34
|
-
data: receivedData.data,
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, [fetcher, dispatch, name]);
|
|
39
|
-
(0, react_2.useEffect)(() => {
|
|
40
|
-
if (!sessionData) {
|
|
41
|
-
try {
|
|
42
|
-
fetcher.load(`/api/session?name=${name}&type=${type}`);
|
|
43
|
-
}
|
|
44
|
-
catch (ex) {
|
|
14
|
+
try {
|
|
15
|
+
const fetcher = (0, react_1.useFetcher)();
|
|
16
|
+
const dispatch = (0, redux_1.useAppDispatch)();
|
|
17
|
+
const sessionData = (0, redux_1.useAppSelector)((state) => state.session[name]);
|
|
18
|
+
const [data, setData] = (0, react_2.useState)(sessionData);
|
|
19
|
+
(0, react_2.useEffect)(() => {
|
|
20
|
+
if (fetcher.data?.title) {
|
|
45
21
|
(0, index_js_1.showAlert)({
|
|
46
|
-
|
|
47
|
-
title:
|
|
48
|
-
|
|
22
|
+
description: fetcher.data?.description,
|
|
23
|
+
title: fetcher.data?.title,
|
|
24
|
+
type: fetcher.data?.type,
|
|
49
25
|
});
|
|
50
26
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
}, [fetcher.data]);
|
|
28
|
+
(0, react_2.useEffect)(() => {
|
|
29
|
+
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
30
|
+
try {
|
|
31
|
+
const receivedData = fetcher.data;
|
|
32
|
+
if (receivedData) {
|
|
33
|
+
setData(receivedData.data);
|
|
34
|
+
dispatch((0, redux_1.setSessionValue)({
|
|
35
|
+
name: name,
|
|
36
|
+
data: receivedData.data,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (ex) {
|
|
41
|
+
(0, index_js_1.showAlert)({
|
|
42
|
+
type: "error",
|
|
43
|
+
title: `Ocurrió un error al cargar la variable de configuración: ${name}.`,
|
|
44
|
+
description: "Error: " + ex,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [fetcher, dispatch, name]);
|
|
49
|
+
(0, react_2.useEffect)(() => {
|
|
50
|
+
if (!sessionData) {
|
|
51
|
+
try {
|
|
52
|
+
fetcher.load(`/api/session?name=${name}&type=${type}`);
|
|
53
|
+
}
|
|
54
|
+
catch (ex) {
|
|
55
|
+
(0, index_js_1.showAlert)({
|
|
56
|
+
type: "error",
|
|
57
|
+
title: `Ocurrió un error al cargar la variable de configuración: ${name}.`,
|
|
58
|
+
description: "Error: " + ex,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
catch (ex) {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
54
68
|
};
|
|
55
69
|
exports.useGetSessionAttribute = useGetSessionAttribute;
|
package/dist/esm/templates.js
CHANGED
|
@@ -6,54 +6,59 @@ const redux_1 = require("@zauru-sdk/redux");
|
|
|
6
6
|
const react_2 = require("react");
|
|
7
7
|
const index_js_1 = require("./index.js");
|
|
8
8
|
const useGetTemplateObject = (TEMPLATE_NAME, config = { online: false }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
description: fetcher.data?.description,
|
|
22
|
-
title: fetcher.data?.title,
|
|
23
|
-
type: fetcher.data?.type,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}, [fetcher.data]);
|
|
27
|
-
(0, react_2.useEffect)(() => {
|
|
28
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
29
|
-
const receivedData = fetcher.data;
|
|
30
|
-
if (receivedData) {
|
|
31
|
-
setData({ data: receivedData[TEMPLATE_NAME], loading: false });
|
|
32
|
-
dispatch((0, redux_1.templateFetchSuccess)({
|
|
33
|
-
name: TEMPLATE_NAME,
|
|
34
|
-
data: receivedData[TEMPLATE_NAME],
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, [fetcher, dispatch, TEMPLATE_NAME]);
|
|
39
|
-
(0, react_2.useEffect)(() => {
|
|
40
|
-
if ((objectData?.data && Object.keys(objectData?.data).length <= 0) ||
|
|
41
|
-
config?.online) {
|
|
42
|
-
try {
|
|
43
|
-
setData({ ...data, loading: true });
|
|
44
|
-
dispatch((0, redux_1.templateFetchStart)(TEMPLATE_NAME));
|
|
45
|
-
fetcher.load(`/api/templates?object=${TEMPLATE_NAME}`);
|
|
46
|
-
}
|
|
47
|
-
catch (ex) {
|
|
9
|
+
try {
|
|
10
|
+
const fetcher = (0, react_1.useFetcher)();
|
|
11
|
+
const dispatch = (0, redux_1.useAppDispatch)();
|
|
12
|
+
const objectData = (0, redux_1.useAppSelector)((state) => state.templates[TEMPLATE_NAME]);
|
|
13
|
+
const [data, setData] = (0, react_2.useState)({
|
|
14
|
+
data: objectData?.data && Object.keys(objectData?.data).length
|
|
15
|
+
? objectData?.data
|
|
16
|
+
: {},
|
|
17
|
+
loading: objectData.loading,
|
|
18
|
+
});
|
|
19
|
+
(0, react_2.useEffect)(() => {
|
|
20
|
+
if (fetcher.data?.title) {
|
|
48
21
|
(0, index_js_1.showAlert)({
|
|
49
|
-
|
|
50
|
-
title:
|
|
51
|
-
|
|
22
|
+
description: fetcher.data?.description,
|
|
23
|
+
title: fetcher.data?.title,
|
|
24
|
+
type: fetcher.data?.type,
|
|
52
25
|
});
|
|
53
26
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
27
|
+
}, [fetcher.data]);
|
|
28
|
+
(0, react_2.useEffect)(() => {
|
|
29
|
+
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
30
|
+
const receivedData = fetcher.data;
|
|
31
|
+
if (receivedData) {
|
|
32
|
+
setData({ data: receivedData[TEMPLATE_NAME], loading: false });
|
|
33
|
+
dispatch((0, redux_1.templateFetchSuccess)({
|
|
34
|
+
name: TEMPLATE_NAME,
|
|
35
|
+
data: receivedData[TEMPLATE_NAME],
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [fetcher, dispatch, TEMPLATE_NAME]);
|
|
40
|
+
(0, react_2.useEffect)(() => {
|
|
41
|
+
if ((objectData?.data && Object.keys(objectData?.data).length <= 0) ||
|
|
42
|
+
config?.online) {
|
|
43
|
+
try {
|
|
44
|
+
setData({ ...data, loading: true });
|
|
45
|
+
dispatch((0, redux_1.templateFetchStart)(TEMPLATE_NAME));
|
|
46
|
+
fetcher.load(`/api/templates?object=${TEMPLATE_NAME}`);
|
|
47
|
+
}
|
|
48
|
+
catch (ex) {
|
|
49
|
+
(0, index_js_1.showAlert)({
|
|
50
|
+
type: "error",
|
|
51
|
+
title: `Ocurrió un error al cargar el object de templates: ${TEMPLATE_NAME}.`,
|
|
52
|
+
description: "Error: " + ex,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
catch (ex) {
|
|
60
|
+
return { data: {}, loading: false };
|
|
61
|
+
}
|
|
57
62
|
};
|
|
58
63
|
const useGetReceptionTemplate = (config) => useGetTemplateObject("receptionTemplate", config);
|
|
59
64
|
exports.useGetReceptionTemplate = useGetReceptionTemplate;
|
|
@@ -11,21 +11,27 @@ function getWindowDimensions() {
|
|
|
11
11
|
return 1000;
|
|
12
12
|
}
|
|
13
13
|
const useWindowDimensions = () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
try {
|
|
15
|
+
const [windowDimensions, setWindowDimensions] = (0, react_1.useState)(getWindowDimensions);
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
if (typeof window !== "undefined") {
|
|
18
|
+
const handleResize = () => {
|
|
19
|
+
setWindowDimensions(getWindowDimensions());
|
|
20
|
+
};
|
|
21
|
+
// Use window load event to ensure accurate window size on initial load
|
|
22
|
+
window.addEventListener("load", handleResize);
|
|
23
|
+
window.addEventListener("resize", handleResize);
|
|
24
|
+
return () => {
|
|
25
|
+
window.removeEventListener("load", handleResize);
|
|
26
|
+
window.removeEventListener("resize", handleResize);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}, []);
|
|
30
|
+
return windowDimensions;
|
|
31
|
+
}
|
|
32
|
+
catch (ex) {
|
|
33
|
+
console.error(ex);
|
|
34
|
+
return 1000;
|
|
35
|
+
}
|
|
30
36
|
};
|
|
31
37
|
exports.useWindowDimensions = useWindowDimensions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.94",
|
|
4
4
|
"description": "Hooks reutilizables dentro de las webapps de Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@remix-run/react": "^2.8.1",
|
|
29
|
-
"@zauru-sdk/common": "^2.0.
|
|
29
|
+
"@zauru-sdk/common": "^2.0.94",
|
|
30
30
|
"@zauru-sdk/icons": "^2.0.87",
|
|
31
|
-
"@zauru-sdk/redux": "^2.0.
|
|
32
|
-
"@zauru-sdk/types": "^2.0.
|
|
31
|
+
"@zauru-sdk/redux": "^2.0.92",
|
|
32
|
+
"@zauru-sdk/types": "^2.0.92",
|
|
33
33
|
"react": "^18.2.0",
|
|
34
34
|
"react-dom": "^18.2.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "609e3474b185d0220e35be6ea1932dee71c9dadc"
|
|
37
37
|
}
|