@zauru-sdk/hooks 1.0.49 → 1.0.51

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.
Files changed (46) hide show
  1. package/dist/alerts.d.ts +1 -1
  2. package/dist/{alerts.js → cjs/alerts.js} +13 -9
  3. package/dist/{automaticNumbers.js → cjs/automaticNumbers.js} +20 -16
  4. package/dist/cjs/catalogs.js +267 -0
  5. package/dist/{components → cjs/components}/Alert.js +18 -15
  6. package/dist/cjs/components/index.js +17 -0
  7. package/dist/cjs/index.js +26 -0
  8. package/dist/{onlineStatus.js → cjs/onlineStatus.js} +8 -4
  9. package/dist/cjs/profiles.js +64 -0
  10. package/dist/{receptions.js → cjs/receptions.js} +67 -52
  11. package/dist/{session.js → cjs/session.js} +19 -15
  12. package/dist/{templates.js → cjs/templates.js} +20 -16
  13. package/dist/{useWindowDimensions.js → cjs/useWindowDimensions.js} +8 -4
  14. package/dist/esm/alerts.js +37 -0
  15. package/dist/esm/automaticNumbers.js +57 -0
  16. package/dist/esm/catalogs.js +267 -0
  17. package/dist/esm/components/Alert.js +100 -0
  18. package/dist/esm/components/index.js +17 -0
  19. package/dist/esm/index.js +26 -0
  20. package/dist/esm/onlineStatus.js +31 -0
  21. package/dist/esm/profiles.js +64 -0
  22. package/dist/esm/receptions.js +348 -0
  23. package/dist/esm/session.js +55 -0
  24. package/dist/esm/templates.js +58 -0
  25. package/dist/esm/useWindowDimensions.js +31 -0
  26. package/dist/receptions.d.ts +2 -2
  27. package/package.json +16 -21
  28. package/.eslintrc.cjs +0 -83
  29. package/CHANGELOG.md +0 -224
  30. package/dist/catalogs.js +0 -230
  31. package/dist/components/index.js +0 -1
  32. package/dist/index.js +0 -10
  33. package/dist/profiles.js +0 -57
  34. package/src/alerts.ts +0 -43
  35. package/src/automaticNumbers.ts +0 -74
  36. package/src/catalogs.ts +0 -557
  37. package/src/components/Alert.tsx +0 -149
  38. package/src/components/index.ts +0 -1
  39. package/src/index.ts +0 -11
  40. package/src/onlineStatus.ts +0 -34
  41. package/src/profiles.ts +0 -103
  42. package/src/receptions.ts +0 -548
  43. package/src/session.ts +0 -69
  44. package/src/templates.ts +0 -84
  45. package/src/useWindowDimensions.ts +0 -34
  46. package/tsconfig.json +0 -26
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGetInvoiceFormSubmissionsByInvoiceId = exports.useGetMyCaseFormSubmissions = exports.useGetInvoiceFormSubmissionsByAgencyId = exports.useGetCaseForms = exports.useGetInvoiceForms = exports.useGetBitacoraRechazoMasivo = exports.useGetMotivosDeRechazo = exports.useGetTiposDeMuestra = exports.useGetInvoicesByLab = exports.useGetShipmentsToMyAgency = exports.useGetEmployeesByCurrentAgency = exports.useGetEmployeesByLab = exports.useGetPaymentTerms = exports.useGetSuggestedPrices = exports.useGetAgencies = exports.useGetPayeesForLab = exports.useGetPayees = exports.useGetClientCategories = exports.useGetProviderCategories = exports.useGetMyCases = exports.useGetProviders = exports.useGetReceptionTypes = exports.useGetCurrencies = exports.useGetBundlesForLab = exports.useGetBundlesRecipForLab = exports.useGetPayeeCategoriesLabPrices = exports.useGetTemplates = exports.useGetBookings = exports.useGetItemCategoriesForLab = exports.useGetItemServicesByLab = exports.useGetMyAgencyLotStocks = exports.useGetItemsByLab = exports.useGetItemsByReception = exports.useGetItems = void 0;
4
+ const react_1 = require("@remix-run/react");
5
+ const react_2 = require("react");
6
+ const index_js_1 = require("./components/index.js");
7
+ const redux_1 = require("@zauru-sdk/redux");
8
+ const useApiCatalog = (CATALOG_NAME, otherParams) => {
9
+ const fetcher = (0, react_1.useFetcher)();
10
+ const [data, setData] = (0, react_2.useState)({
11
+ data: [],
12
+ loading: true,
13
+ });
14
+ (0, react_2.useEffect)(() => {
15
+ if (fetcher.data?.title) {
16
+ (0, index_js_1.showAlert)({
17
+ description: fetcher.data?.description?.toString(),
18
+ title: fetcher.data?.title?.toString(),
19
+ type: fetcher.data?.type?.toString(),
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 });
28
+ }
29
+ }
30
+ }, [fetcher, CATALOG_NAME]);
31
+ (0, react_2.useEffect)(() => {
32
+ try {
33
+ setData({ ...data, loading: true });
34
+ // Convert otherParams to query string
35
+ const paramsString = otherParams
36
+ ? Object.entries(otherParams)
37
+ .map(([key, value]) => `${key}=${value}`)
38
+ .join("&")
39
+ : "";
40
+ const url = `/api/catalogs?catalog=${CATALOG_NAME}${paramsString ? `&${paramsString}` : ""}`;
41
+ fetcher.load(url);
42
+ }
43
+ catch (ex) {
44
+ (0, index_js_1.showAlert)({
45
+ type: "error",
46
+ title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
47
+ description: "Error: " + ex,
48
+ });
49
+ }
50
+ }, []);
51
+ return data;
52
+ };
53
+ const useGetReduxCatalog = (CATALOG_NAME, { online = false, wheres = [], otherParams } = {}) => {
54
+ const fetcher = (0, react_1.useFetcher)();
55
+ const dispatch = (0, redux_1.useAppDispatch)();
56
+ const catalogData = (0, redux_1.useAppSelector)((state) => state.catalogs[CATALOG_NAME]);
57
+ const [data, setData] = (0, react_2.useState)({
58
+ data: catalogData?.data?.length ? catalogData.data : [],
59
+ loading: catalogData.loading,
60
+ });
61
+ (0, react_2.useEffect)(() => {
62
+ if (fetcher.data?.description) {
63
+ (0, index_js_1.showAlert)({
64
+ description: fetcher.data?.description?.toString(),
65
+ title: fetcher.data?.title?.toString(),
66
+ type: fetcher.data?.type?.toString(),
67
+ });
68
+ }
69
+ }, [fetcher.data]);
70
+ (0, react_2.useEffect)(() => {
71
+ if (fetcher.state === "idle" && fetcher.data != null) {
72
+ const receivedData = fetcher.data;
73
+ if (receivedData) {
74
+ setData({ data: receivedData[CATALOG_NAME], loading: false });
75
+ dispatch((0, redux_1.catalogsFetchSuccess)({
76
+ name: CATALOG_NAME,
77
+ data: receivedData[CATALOG_NAME],
78
+ }));
79
+ }
80
+ }
81
+ }, [fetcher, dispatch, CATALOG_NAME]);
82
+ (0, react_2.useEffect)(() => {
83
+ if (catalogData?.data?.length <= 0 || catalogData?.reFetch || online) {
84
+ try {
85
+ setData({ ...data, loading: true });
86
+ dispatch((0, redux_1.catalogsFetchStart)(CATALOG_NAME));
87
+ // Convierte cada elemento del array a una cadena codificada para URL
88
+ const encodedWheres = wheres.map((where) => encodeURIComponent(where));
89
+ // Une los elementos codificados con '&'
90
+ const wheresQueryParam = encodedWheres.join("&");
91
+ // Convert otherParams to query string
92
+ const paramsString = otherParams
93
+ ? Object.entries(otherParams)
94
+ .map(([key, value]) => `${key}=${value}`)
95
+ .join("&")
96
+ : "";
97
+ fetcher.load(`/api/catalogs?catalog=${CATALOG_NAME}&wheres=${wheresQueryParam}${paramsString ? `&${paramsString}` : ""}`);
98
+ }
99
+ catch (ex) {
100
+ (0, index_js_1.showAlert)({
101
+ type: "error",
102
+ title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
103
+ description: "Error: " + ex,
104
+ });
105
+ }
106
+ }
107
+ }, []);
108
+ return data;
109
+ };
110
+ /**
111
+ *
112
+ * ======================= HOOKS
113
+ */
114
+ const useGetItems = (config) => useGetReduxCatalog("items", config);
115
+ exports.useGetItems = useGetItems;
116
+ const useGetItemsByReception = (config) => useGetReduxCatalog("itemsByReception", config);
117
+ exports.useGetItemsByReception = useGetItemsByReception;
118
+ const useGetItemsByLab = (config) => useGetReduxCatalog("itemsByLab", config);
119
+ exports.useGetItemsByLab = useGetItemsByLab;
120
+ const useGetMyAgencyLotStocks = (config) => useGetReduxCatalog("myAgencyLotStocks", config);
121
+ exports.useGetMyAgencyLotStocks = useGetMyAgencyLotStocks;
122
+ const useGetItemServicesByLab = (config) => useGetReduxCatalog("itemServicesByLab", config);
123
+ exports.useGetItemServicesByLab = useGetItemServicesByLab;
124
+ const useGetItemCategoriesForLab = (config) => useGetReduxCatalog("itemCategoriesForLab", config);
125
+ exports.useGetItemCategoriesForLab = useGetItemCategoriesForLab;
126
+ const useGetBookings = (config) => useGetReduxCatalog("bookings", config);
127
+ exports.useGetBookings = useGetBookings;
128
+ const useGetTemplates = (config) => useGetReduxCatalog("templates", config);
129
+ exports.useGetTemplates = useGetTemplates;
130
+ const useGetPayeeCategoriesLabPrices = (config = { withPriceListIdNull: false }) => {
131
+ const data = useGetReduxCatalog("payeeCategoriesLabPrices");
132
+ let tempData = data.data;
133
+ if (!config.withPriceListIdNull) {
134
+ tempData = data.data.filter((x) => x.price_list_id);
135
+ }
136
+ return { ...data, data: tempData };
137
+ };
138
+ exports.useGetPayeeCategoriesLabPrices = useGetPayeeCategoriesLabPrices;
139
+ const useGetBundlesRecipForLab = (config) => useGetReduxCatalog("bundlesRecipForLab", config);
140
+ exports.useGetBundlesRecipForLab = useGetBundlesRecipForLab;
141
+ const useGetBundlesForLab = (config) => useGetReduxCatalog("bundlesForLab", config);
142
+ exports.useGetBundlesForLab = useGetBundlesForLab;
143
+ const useGetCurrencies = (config) => useGetReduxCatalog("currencies", config);
144
+ exports.useGetCurrencies = useGetCurrencies;
145
+ const useGetReceptionTypes = (config) => useGetReduxCatalog("receptionTypes", config);
146
+ exports.useGetReceptionTypes = useGetReceptionTypes;
147
+ const useGetProviders = (config) => useGetReduxCatalog("providers", config);
148
+ exports.useGetProviders = useGetProviders;
149
+ const useGetMyCases = (config) => useGetReduxCatalog("myCases", config);
150
+ exports.useGetMyCases = useGetMyCases;
151
+ const useGetProviderCategories = (config) => useGetReduxCatalog("providerCategories", config);
152
+ exports.useGetProviderCategories = useGetProviderCategories;
153
+ const useGetClientCategories = (config) => useGetReduxCatalog("clientCategories", config);
154
+ exports.useGetClientCategories = useGetClientCategories;
155
+ const useGetPayees = (config) => useGetReduxCatalog("payees", config);
156
+ exports.useGetPayees = useGetPayees;
157
+ const useGetPayeesForLab = (config) => useGetReduxCatalog("payeesForLab", config);
158
+ exports.useGetPayeesForLab = useGetPayeesForLab;
159
+ const useGetAgencies = (config) => useGetReduxCatalog("agencies", config);
160
+ exports.useGetAgencies = useGetAgencies;
161
+ const useGetSuggestedPrices = (config) => useGetReduxCatalog("suggestedPrices", config);
162
+ exports.useGetSuggestedPrices = useGetSuggestedPrices;
163
+ const useGetPaymentTerms = (config) => useGetReduxCatalog("paymentTerms", config);
164
+ exports.useGetPaymentTerms = useGetPaymentTerms;
165
+ const useGetEmployeesByLab = (config) => useGetReduxCatalog("employeesByLab", config);
166
+ exports.useGetEmployeesByLab = useGetEmployeesByLab;
167
+ const useGetEmployeesByCurrentAgency = (config) => useGetReduxCatalog("employeesByCurrentAgency", config);
168
+ exports.useGetEmployeesByCurrentAgency = useGetEmployeesByCurrentAgency;
169
+ const useGetShipmentsToMyAgency = (config) => useGetReduxCatalog("shipmentsToMyAgency", config);
170
+ exports.useGetShipmentsToMyAgency = useGetShipmentsToMyAgency;
171
+ const useGetInvoicesByLab = (config) => useGetReduxCatalog("invoicesByLab", config);
172
+ exports.useGetInvoicesByLab = useGetInvoicesByLab;
173
+ const useGetTiposDeMuestra = (config) => useGetReduxCatalog("tiposDeMuestra", config);
174
+ exports.useGetTiposDeMuestra = useGetTiposDeMuestra;
175
+ const useGetMotivosDeRechazo = (config) => useGetReduxCatalog("motivosRechazo", config);
176
+ exports.useGetMotivosDeRechazo = useGetMotivosDeRechazo;
177
+ const useGetBitacoraRechazoMasivo = (config) => useGetReduxCatalog("bitacoraRechazoMasivo", config);
178
+ exports.useGetBitacoraRechazoMasivo = useGetBitacoraRechazoMasivo;
179
+ const useGetInvoiceForms = (config) => {
180
+ const data = useGetReduxCatalog("invoiceForms", config);
181
+ // Filtrar los registros para obtener sólo los de la versión más alta.
182
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
183
+ const zid = record.zid;
184
+ if (!acc[zid]) {
185
+ acc[zid] = record;
186
+ }
187
+ return acc;
188
+ }, {});
189
+ const latestVersionRecords = Object.values(groupedByVersion);
190
+ return {
191
+ loading: data.loading,
192
+ data: latestVersionRecords.filter((x) => x.active),
193
+ };
194
+ };
195
+ exports.useGetInvoiceForms = useGetInvoiceForms;
196
+ const useGetCaseForms = (config) => {
197
+ const data = useGetReduxCatalog("caseForms", config);
198
+ // Filtrar los registros para obtener sólo el primero de cada zid.
199
+ const firstRecordByZid = (data.data || []).reduce((acc, record) => {
200
+ const zid = record.zid;
201
+ if (!acc[zid]) {
202
+ acc[zid] = record;
203
+ }
204
+ return acc;
205
+ }, {});
206
+ const firstRecords = Object.values(firstRecordByZid);
207
+ return {
208
+ loading: data.loading,
209
+ data: firstRecords.filter((x) => x.active),
210
+ };
211
+ };
212
+ exports.useGetCaseForms = useGetCaseForms;
213
+ const useGetInvoiceFormSubmissionsByAgencyId = (agency_id) => {
214
+ const data = useApiCatalog("invoiceFormSubmissionsByAgencyId", {
215
+ agency_id: `${agency_id}`,
216
+ });
217
+ // Filtrar los registros para obtener sólo los de la versión más alta.
218
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
219
+ const zid = record.settings_form_submission.zid;
220
+ if (!acc[zid]) {
221
+ acc[zid] = record;
222
+ }
223
+ return acc;
224
+ }, {});
225
+ const latestVersionRecords = Object.values(groupedByVersion);
226
+ return {
227
+ loading: data.loading,
228
+ data: latestVersionRecords,
229
+ };
230
+ };
231
+ exports.useGetInvoiceFormSubmissionsByAgencyId = useGetInvoiceFormSubmissionsByAgencyId;
232
+ const useGetMyCaseFormSubmissions = (config) => {
233
+ const data = useGetReduxCatalog("myCaseFormSubmissions", config);
234
+ // Filtrar los registros para obtener sólo los de la versión más alta.
235
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
236
+ const zid = record.settings_form_submission.zid;
237
+ if (!acc[zid]) {
238
+ acc[zid] = record;
239
+ }
240
+ return acc;
241
+ }, {});
242
+ const latestVersionRecords = Object.values(groupedByVersion);
243
+ return {
244
+ loading: data.loading,
245
+ data: latestVersionRecords,
246
+ };
247
+ };
248
+ exports.useGetMyCaseFormSubmissions = useGetMyCaseFormSubmissions;
249
+ const useGetInvoiceFormSubmissionsByInvoiceId = (invoice_id) => {
250
+ const data = useApiCatalog("invoiceFormSubmissionsByInvoiceId", {
251
+ invoice_id: `${invoice_id}`,
252
+ });
253
+ // Filtrar los registros para obtener sólo los de la versión más alta.
254
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
255
+ const zid = record.settings_form_submission.zid;
256
+ if (!acc[zid]) {
257
+ acc[zid] = record;
258
+ }
259
+ return acc;
260
+ }, {});
261
+ const latestVersionRecords = Object.values(groupedByVersion);
262
+ return {
263
+ loading: data.loading,
264
+ data: latestVersionRecords,
265
+ };
266
+ };
267
+ exports.useGetInvoiceFormSubmissionsByInvoiceId = useGetInvoiceFormSubmissionsByInvoiceId;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.showAlert = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const icons_1 = require("@zauru-sdk/icons");
7
+ const client_1 = require("react-dom/client");
8
+ const Alert = ({ type, title, description, onClose }) => {
9
+ const [, setLifetime] = (0, react_1.useState)(4000);
10
+ const [progress, setProgress] = (0, react_1.useState)(0);
11
+ const intervalRef = (0, react_1.useRef)(null);
12
+ const getColor = () => {
13
+ switch (type) {
14
+ case "success":
15
+ return "bg-green-100 text-green-800";
16
+ case "error":
17
+ return "bg-red-100 text-red-800";
18
+ case "info":
19
+ return "bg-blue-100 text-blue-800";
20
+ case "warning":
21
+ return "bg-yellow-100 text-yellow-800";
22
+ default:
23
+ return "bg-gray-100 text-gray-800";
24
+ }
25
+ };
26
+ (0, react_1.useEffect)(() => {
27
+ const startTimer = () => {
28
+ intervalRef.current = setInterval(() => {
29
+ setLifetime((lifetime) => {
30
+ if (lifetime <= 0) {
31
+ onClose && onClose();
32
+ clearInterval(intervalRef.current);
33
+ return 0;
34
+ }
35
+ else {
36
+ setProgress((4000 - lifetime) / 4000);
37
+ return lifetime - 50;
38
+ }
39
+ });
40
+ }, 50);
41
+ };
42
+ const pauseTimer = () => {
43
+ clearInterval(intervalRef.current);
44
+ };
45
+ startTimer();
46
+ return () => {
47
+ pauseTimer();
48
+ };
49
+ }, [onClose]);
50
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `fixed top-0 right-0 w-80 mt-10 mr-10 rounded-md shadow-lg ${getColor()} p-4 transition-transform duration-300`, style: {
51
+ zIndex: 1000,
52
+ transform: `translateY(calc(var(--alert-offset, 0)))`,
53
+ }, onMouseEnter: () => clearInterval(intervalRef.current), onMouseLeave: () => {
54
+ intervalRef.current = setInterval(() => {
55
+ setLifetime((lifetime) => {
56
+ if (lifetime <= 0) {
57
+ onClose && onClose();
58
+ clearInterval(intervalRef.current);
59
+ return 0;
60
+ }
61
+ else {
62
+ setProgress((4000 - lifetime) / 4000);
63
+ return lifetime - 50;
64
+ }
65
+ });
66
+ }, 50);
67
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("h3", { className: "font-semibold", children: title }), (0, jsx_runtime_1.jsx)("button", { className: "text-gray-400 hover:text-gray-500 focus:outline-none focus:text-gray-500 transition duration-150 ease-in-out", onClick: () => {
68
+ setLifetime(0);
69
+ onClose && onClose();
70
+ }, children: (0, jsx_runtime_1.jsx)(icons_1.ExitSvg, {}) })] }), (0, jsx_runtime_1.jsx)("div", { className: "mt-2", children: (0, jsx_runtime_1.jsx)("p", { className: "text-sm overflow-wrap break-words", children: description }) }), (0, jsx_runtime_1.jsx)("div", { className: "relative h-1 mt-4 bg-gray-200 rounded", children: (0, jsx_runtime_1.jsx)("div", { className: `absolute left-0 top-0 h-full ${getColor()} rounded`, style: { width: `${progress * 100}%` } }) })] }));
71
+ };
72
+ let activeAlerts = [];
73
+ const showAlert = (alertProps) => {
74
+ if (typeof document === "undefined") {
75
+ return;
76
+ }
77
+ const container = document.createElement("div");
78
+ document.body.appendChild(container);
79
+ const onClose = () => {
80
+ root.unmount();
81
+ container.remove();
82
+ activeAlerts = activeAlerts.filter((alert) => alert !== container);
83
+ updateAlertOffsets();
84
+ };
85
+ const asyncOnClose = () => {
86
+ setTimeout(() => {
87
+ onClose();
88
+ }, 0);
89
+ };
90
+ activeAlerts.push(container);
91
+ updateAlertOffsets();
92
+ const root = (0, client_1.createRoot)(container);
93
+ root.render((0, jsx_runtime_1.jsx)(Alert, { ...alertProps, onClose: asyncOnClose }));
94
+ };
95
+ exports.showAlert = showAlert;
96
+ const updateAlertOffsets = () => {
97
+ activeAlerts.forEach((alertContainer, index) => {
98
+ alertContainer.style.setProperty("--alert-offset", `${index * 100}px`);
99
+ });
100
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Alert.js"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./components/index.js"), exports);
18
+ __exportStar(require("./alerts.js"), exports);
19
+ __exportStar(require("./automaticNumbers.js"), exports);
20
+ __exportStar(require("./catalogs.js"), exports);
21
+ __exportStar(require("./onlineStatus.js"), exports);
22
+ __exportStar(require("./profiles.js"), exports);
23
+ __exportStar(require("./receptions.js"), exports);
24
+ __exportStar(require("./session.js"), exports);
25
+ __exportStar(require("./templates.js"), exports);
26
+ __exportStar(require("./useWindowDimensions.js"), exports);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIsOnline = void 0;
4
+ const react_1 = require("react");
5
+ // Hook personalizado para verificar el estado de conexión
6
+ const useIsOnline = () => {
7
+ // Verificar si estamos en el entorno del servidor o del cliente
8
+ const isServer = typeof window === "undefined";
9
+ // Estado local para almacenar si la aplicación está en línea o no
10
+ const [isOnline, setIsOnline] = (0, react_1.useState)(!isServer && navigator.onLine);
11
+ // Función para manejar el cambio de estado de conexión
12
+ const handleConnectionChange = () => {
13
+ setIsOnline(navigator.onLine);
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);
27
+ };
28
+ }, [isServer]);
29
+ return isOnline;
30
+ };
31
+ exports.useIsOnline = useIsOnline;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGetEmployeeProfile = exports.useGetOauthProfile = exports.useGetUserProfile = exports.useGetAgencyProfile = void 0;
4
+ const react_1 = require("@remix-run/react");
5
+ const react_2 = require("react");
6
+ const index_js_1 = require("./index.js");
7
+ const redux_1 = require("@zauru-sdk/redux");
8
+ const useGetProfile = (PROFILE_NAME) => {
9
+ const fetcher = (0, react_1.useFetcher)();
10
+ const dispatch = (0, redux_1.useAppDispatch)();
11
+ const profileData = (0, redux_1.useAppSelector)((state) => state.profiles[PROFILE_NAME]);
12
+ const [data, setData] = (0, react_2.useState)({
13
+ data: Object.keys(profileData?.data)?.length
14
+ ? profileData?.data
15
+ : {},
16
+ loading: profileData?.loading,
17
+ });
18
+ (0, react_2.useEffect)(() => {
19
+ if (fetcher.data?.title) {
20
+ (0, index_js_1.showAlert)({
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) {
47
+ (0, index_js_1.showAlert)({
48
+ type: "error",
49
+ title: `Ocurrió un error al cargar el perfil: ${PROFILE_NAME}.`,
50
+ description: "Error: " + ex,
51
+ });
52
+ }
53
+ }
54
+ }, []);
55
+ return data;
56
+ };
57
+ const useGetAgencyProfile = () => useGetProfile("agencyProfile");
58
+ exports.useGetAgencyProfile = useGetAgencyProfile;
59
+ const useGetUserProfile = () => useGetProfile("userProfile");
60
+ exports.useGetUserProfile = useGetUserProfile;
61
+ const useGetOauthProfile = () => useGetProfile("oauthProfile");
62
+ exports.useGetOauthProfile = useGetOauthProfile;
63
+ const useGetEmployeeProfile = () => useGetProfile("employeeProfile");
64
+ exports.useGetEmployeeProfile = useGetEmployeeProfile;