@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,348 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGetItemNameByPurchaseOrder = exports.useGetProviderNameByPurchaseOrder = exports.getBasketDetailsByForm = exports.useGetBasketDetails = exports.getPesadasByForm = exports.useGetPesadas = exports.useGetPurchaseOrderGeneralInfo = exports.useGetNewPurchaseOrderInfo = exports.useGetRejectionInfo = exports.useGetBasketLots = exports.useGetPOReceptions = exports.useGetProcesses = void 0;
4
+ const react_1 = require("@remix-run/react");
5
+ const redux_1 = require("@zauru-sdk/redux");
6
+ const react_2 = require("react");
7
+ const index_js_1 = require("./index.js");
8
+ const common_1 = require("@zauru-sdk/common");
9
+ const useGetReceptionObject = (RECEPTION_NAME, { online = false, wheres = [] } = {}) => {
10
+ const fetcher = (0, react_1.useFetcher)();
11
+ const dispatch = (0, redux_1.useAppDispatch)();
12
+ const objectData = (0, redux_1.useAppSelector)((state) => state.receptions[RECEPTION_NAME]);
13
+ const [data, setData] = (0, react_2.useState)({
14
+ data: Array.isArray(objectData?.data)
15
+ ? objectData?.data.length
16
+ ? objectData?.data
17
+ : []
18
+ : Object.keys(objectData?.data || {}).length
19
+ ? objectData?.data
20
+ : {},
21
+ loading: objectData.loading,
22
+ });
23
+ (0, react_2.useEffect)(() => {
24
+ if (fetcher.data?.title) {
25
+ (0, index_js_1.showAlert)({
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 = Array.isArray(objectData?.data)
46
+ ? objectData?.data.length <= 0
47
+ : Object.keys(objectData?.data || {}).length <= 0;
48
+ if (isEmptyData || objectData.reFetch || online) {
49
+ try {
50
+ setData({ ...data, loading: true });
51
+ dispatch((0, redux_1.receptionFetchStart)(RECEPTION_NAME));
52
+ // Convierte cada elemento del array a una cadena codificada para URL
53
+ const encodedWheres = wheres.map((where) => encodeURIComponent(where));
54
+ // Une los elementos codificados con '&'
55
+ const wheresQueryParam = encodedWheres.join("&");
56
+ fetcher.load(`/api/receptions?object=${RECEPTION_NAME}&wheres=${wheresQueryParam}`);
57
+ }
58
+ catch (ex) {
59
+ (0, index_js_1.showAlert)({
60
+ type: "error",
61
+ title: `Ocurrió un error al cargar el object de receptions: ${RECEPTION_NAME}.`,
62
+ description: "Error: " + ex,
63
+ });
64
+ }
65
+ }
66
+ }, []);
67
+ return data;
68
+ };
69
+ const useGetProcesses = (config) => useGetReceptionObject("queueNewReceptions", config);
70
+ exports.useGetProcesses = useGetProcesses;
71
+ const useGetPOReceptions = (config) => useGetReceptionObject("poReceptions", config);
72
+ exports.useGetPOReceptions = useGetPOReceptions;
73
+ const useGetBasketLots = () => useGetReceptionObject("basketLots");
74
+ exports.useGetBasketLots = useGetBasketLots;
75
+ const useGetRejectionInfo = () => useGetReceptionObject("rejectionInfo");
76
+ exports.useGetRejectionInfo = useGetRejectionInfo;
77
+ const useGetNewPurchaseOrderInfo = () => useGetReceptionObject("newPurchaseOrderInfo");
78
+ exports.useGetNewPurchaseOrderInfo = useGetNewPurchaseOrderInfo;
79
+ const useGetPurchaseOrderGeneralInfo = () => useGetReceptionObject("purchaseOrderGeneralInfo");
80
+ exports.useGetPurchaseOrderGeneralInfo = useGetPurchaseOrderGeneralInfo;
81
+ const useGetPesadas = (purchaseOrder) => {
82
+ const [pesadas, footerPesadas, headersPesadas] = (0, react_2.useMemo)(() => {
83
+ const tempPesadas = [
84
+ ...purchaseOrder.purchase_order_details?.map((x, index) => {
85
+ const parsedReference = x.reference?.split(","); //eg: "reference": "698,25,0", // peso neto, canastas, descuento
86
+ const totalWeight = parsedReference[0]
87
+ ? Number(parsedReference[0]) ?? 0
88
+ : 0;
89
+ const baskets = parsedReference[1]
90
+ ? Number(parsedReference[1]) ?? 0
91
+ : 0;
92
+ const discount = parsedReference[2]
93
+ ? Number(parsedReference[2]) ?? 0
94
+ : 0;
95
+ //TODO sacar el peso de la canasta de la API de Zauru
96
+ const basketWeight = 5;
97
+ let netWeight = totalWeight - baskets * basketWeight; //Se le resta el peso de las canastas
98
+ netWeight = netWeight * ((100 - discount) / 100); //Se le aplica el descuento
99
+ const weightByBasket = netWeight / baskets;
100
+ //Probable aprovechamiento en planta
101
+ const probableUtilization = netWeight * ((100 - purchaseOrder?.discount) / 100);
102
+ //libras o unidades descontadas
103
+ const lbDiscounted = netWeight - probableUtilization;
104
+ return {
105
+ id: index + 1,
106
+ baskets,
107
+ totalWeight,
108
+ discount,
109
+ netWeight: (0, common_1.toFixedIfNeeded)(netWeight),
110
+ weightByBasket: (0, common_1.toFixedIfNeeded)(weightByBasket),
111
+ probableUtilization,
112
+ lbDiscounted,
113
+ };
114
+ }),
115
+ ];
116
+ const totales = {
117
+ id: "",
118
+ baskets: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.baskets).reduce(common_1.reduceAdd, 0)),
119
+ totalWeight: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.totalWeight).reduce(common_1.reduceAdd, 0)),
120
+ discount: "-",
121
+ netWeight: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.netWeight)).reduce(common_1.reduceAdd, 0)),
122
+ weightByBasket: "-",
123
+ lbDiscounted: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.lbDiscounted)).reduce(common_1.reduceAdd, 0)),
124
+ probableUtilization: (0, common_1.toFixedIfNeeded)(tempPesadas
125
+ ?.map((x) => Number(x.probableUtilization))
126
+ .reduce(common_1.reduceAdd, 0)),
127
+ };
128
+ const headers = [
129
+ { label: "#", name: "id", type: "label", width: 5 },
130
+ { label: "Canastas", name: "baskets", type: "label" },
131
+ { label: "Peso báscula", name: "totalWeight", type: "label" },
132
+ { label: "Descuento (%)", name: "discount", type: "label" },
133
+ { label: "Peso Neto", name: "netWeight", type: "label" },
134
+ {
135
+ label: "Peso Neto - %Rechazo",
136
+ name: "probableUtilization",
137
+ type: "label",
138
+ },
139
+ {
140
+ label: "Lb o Unidades descontadas",
141
+ name: "lbDiscounted",
142
+ type: "label",
143
+ },
144
+ {
145
+ label: "Peso Neto por canasta",
146
+ name: "weightByBasket",
147
+ type: "label",
148
+ },
149
+ ];
150
+ return [tempPesadas, totales, headers];
151
+ }, [purchaseOrder]);
152
+ return [pesadas, footerPesadas, headersPesadas];
153
+ };
154
+ exports.useGetPesadas = useGetPesadas;
155
+ /**
156
+ * Sirve para imprimir offline
157
+ * @param formInput
158
+ * @returns
159
+ */
160
+ const getPesadasByForm = (formInput) => {
161
+ // Inicializar array de pesadas
162
+ const tempPesadas = [];
163
+ // Iterar sobre los campos del formulario y extraer la información de pesadas
164
+ let index = 0;
165
+ while (formInput.hasOwnProperty(`basket${index}`)) {
166
+ const baskets = Number(formInput[`basket${index}`] || 0);
167
+ const totalWeight = Number(formInput[`weight${index}`] || 0);
168
+ const discount = Number(formInput[`discount${index}`] || 0);
169
+ // Realizar los cálculos necesarios
170
+ const basketWeight = 5;
171
+ let netWeight = totalWeight - baskets * basketWeight;
172
+ netWeight = netWeight * ((100 - discount) / 100);
173
+ const weightByBasket = netWeight / baskets;
174
+ //Probable aprovechamiento en planta
175
+ const probableUtilization = netWeight * ((100 - (Number(formInput.porcentajeRechazo) ?? 0)) / 100);
176
+ //libras o unidades descontadas
177
+ const lbDiscounted = netWeight - probableUtilization;
178
+ // Añadir al array de pesadas
179
+ tempPesadas.push({
180
+ id: index + 1,
181
+ baskets,
182
+ totalWeight,
183
+ discount,
184
+ netWeight: (0, common_1.toFixedIfNeeded)(netWeight),
185
+ weightByBasket: (0, common_1.toFixedIfNeeded)(weightByBasket),
186
+ probableUtilization,
187
+ lbDiscounted,
188
+ });
189
+ index++;
190
+ }
191
+ const totales = {
192
+ id: "",
193
+ baskets: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.baskets).reduce(common_1.reduceAdd, 0)),
194
+ totalWeight: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.totalWeight).reduce(common_1.reduceAdd, 0)),
195
+ discount: "-",
196
+ netWeight: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.netWeight)).reduce(common_1.reduceAdd, 0)),
197
+ weightByBasket: "-",
198
+ lbDiscounted: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.lbDiscounted)).reduce(common_1.reduceAdd, 0)),
199
+ probableUtilization: (0, common_1.toFixedIfNeeded)(tempPesadas
200
+ ?.map((x) => Number(x.probableUtilization))
201
+ .reduce(common_1.reduceAdd, 0)),
202
+ };
203
+ const headers = [
204
+ { label: "#", name: "id", type: "label", width: 5 },
205
+ { label: "Canastas", name: "baskets", type: "label" },
206
+ { label: "Peso báscula", name: "totalWeight", type: "label" },
207
+ { label: "Descuento (%)", name: "discount", type: "label" },
208
+ { label: "Peso Neto", name: "netWeight", type: "label" },
209
+ {
210
+ label: "Peso Neto - %Rechazo",
211
+ name: "probableUtilization",
212
+ type: "label",
213
+ },
214
+ {
215
+ label: "Lb o Unidades descontadas",
216
+ name: "lbDiscounted",
217
+ type: "label",
218
+ },
219
+ {
220
+ label: "Peso Neto por canasta",
221
+ name: "weightByBasket",
222
+ type: "label",
223
+ },
224
+ ];
225
+ return { tempPesadas, totales, headers };
226
+ };
227
+ exports.getPesadasByForm = getPesadasByForm;
228
+ const useGetBasketDetails = (purchaseOrder) => {
229
+ const [basketsJoined, footerBasketsJoined, headersBasketsJoined] = (0, react_2.useMemo)(() => {
230
+ const bsq = purchaseOrder?.lots
231
+ ?.map((x) => {
232
+ const basket = (0, common_1.getBasketsSchema)(x.description);
233
+ return basket;
234
+ })
235
+ .flat(2) ?? [];
236
+ const bsqToCC = (0, common_1.getBasketsSchema)(purchaseOrder.memo);
237
+ const joinedBaskets = [];
238
+ for (let i = 0; i < bsq.length; i++) {
239
+ const found = joinedBaskets.find((item) => item.color === bsq[i].color);
240
+ const foundCC = bsqToCC.find((item) => item.color === bsq[i].color);
241
+ if (found) {
242
+ found.total += bsq[i].total;
243
+ }
244
+ else {
245
+ joinedBaskets.push({
246
+ id: i,
247
+ total: bsq[i].total + (foundCC ? foundCC.total : 0),
248
+ color: bsq[i].color,
249
+ cc: foundCC ? foundCC.total : 0,
250
+ });
251
+ }
252
+ }
253
+ const totales = {
254
+ id: "",
255
+ total: (0, common_1.toFixedIfNeeded)(joinedBaskets?.map((x) => x.total).reduce(common_1.reduceAdd, 0)),
256
+ cc: joinedBaskets?.map((x) => x.cc).reduce(common_1.reduceAdd, 0),
257
+ };
258
+ const headers = [
259
+ { label: "Color", name: "color", type: "label" },
260
+ { label: "Canastas recibidas", name: "total", type: "label" },
261
+ { label: "Enviadas a CC", name: "cc", type: "label" },
262
+ ];
263
+ return [joinedBaskets, totales, headers];
264
+ }, [purchaseOrder]);
265
+ return [basketsJoined, footerBasketsJoined, headersBasketsJoined];
266
+ };
267
+ exports.useGetBasketDetails = useGetBasketDetails;
268
+ /**
269
+ * Para imprimir en modo offline
270
+ * @param formInput
271
+ * @returns
272
+ */
273
+ const getBasketDetailsByForm = (formInput) => {
274
+ const basketDetailsArray = [];
275
+ // Regex para identificar los campos relevantes
276
+ const recPattern = /^rec\d+-(.+)$/;
277
+ const qCPattern = /^qC\d+-(.+)$/;
278
+ for (const key in formInput) {
279
+ if (formInput.hasOwnProperty(key)) {
280
+ let match;
281
+ // Comprobar si la clave es un campo "rec" y extraer el color y la cantidad
282
+ if ((match = recPattern.exec(key))) {
283
+ const color = match[1];
284
+ const total = Number(formInput[key] || 0);
285
+ const existingBasket = basketDetailsArray.find((item) => item.color === color);
286
+ if (existingBasket) {
287
+ existingBasket.total += total;
288
+ }
289
+ else {
290
+ basketDetailsArray.push({
291
+ id: basketDetailsArray.length,
292
+ total,
293
+ color,
294
+ cc: 0, // Inicializar cc a 0, se actualizará más adelante si existe
295
+ });
296
+ }
297
+ }
298
+ // Comprobar si la clave es un campo "qC" y actualizar el campo cc correspondiente
299
+ if ((match = qCPattern.exec(key))) {
300
+ const color = match[1];
301
+ const cc = Number(formInput[key] || 0);
302
+ const existingBasket = basketDetailsArray.find((item) => item.color === color);
303
+ if (existingBasket) {
304
+ existingBasket.cc += cc;
305
+ }
306
+ }
307
+ }
308
+ }
309
+ // Calcular los totales para footerBasketsDetails
310
+ const totales = {
311
+ id: "",
312
+ total: basketDetailsArray
313
+ .map((x) => x.total)
314
+ .reduce((acc, val) => acc + val, 0)
315
+ .toFixed(2),
316
+ cc: basketDetailsArray.map((x) => x.cc).reduce((acc, val) => acc + val, 0),
317
+ };
318
+ // Definir los encabezados de la tabla
319
+ const headers = [
320
+ { label: "Color", name: "color", type: "label" },
321
+ { label: "Canastas recibidas", name: "total", type: "label" },
322
+ { label: "Enviadas a CC", name: "cc", type: "label" },
323
+ ];
324
+ return { basketDetailsArray, totales, headers };
325
+ };
326
+ exports.getBasketDetailsByForm = getBasketDetailsByForm;
327
+ const useGetProviderNameByPurchaseOrder = (payees, purchaseOrder) => {
328
+ const providerName = (0, react_2.useMemo)(() => {
329
+ const provider = payees.find((x) => x.id == purchaseOrder.payee_id);
330
+ if (provider) {
331
+ return `<${provider.id_number}> ${provider.tin ? `${provider.tin} | ` : ""}${provider.name}`;
332
+ }
333
+ return null;
334
+ }, [payees, purchaseOrder]);
335
+ return providerName;
336
+ };
337
+ exports.useGetProviderNameByPurchaseOrder = useGetProviderNameByPurchaseOrder;
338
+ const useGetItemNameByPurchaseOrder = (items, purchaseOrder) => {
339
+ const itemName = (0, react_2.useMemo)(() => {
340
+ if (purchaseOrder.purchase_order_details.length > 0 && items.length > 0) {
341
+ const item = items.find((x) => x.id == purchaseOrder.purchase_order_details[0].item_id);
342
+ return `${item?.id} - ${item?.code} - ${item?.name}`;
343
+ }
344
+ return null;
345
+ }, [items, purchaseOrder]);
346
+ return itemName;
347
+ };
348
+ exports.useGetItemNameByPurchaseOrder = useGetItemNameByPurchaseOrder;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGetSessionAttribute = void 0;
4
+ const react_1 = require("@remix-run/react");
5
+ const redux_1 = require("@zauru-sdk/redux");
6
+ const react_2 = require("react");
7
+ const index_js_1 = require("./index.js");
8
+ /**
9
+ *
10
+ * @param attribute
11
+ * @returns
12
+ */
13
+ const useGetSessionAttribute = (name, type) => {
14
+ const fetcher = (0, react_1.useFetcher)();
15
+ const dispatch = (0, redux_1.useAppDispatch)();
16
+ const sessionData = (0, redux_1.useAppSelector)((state) => state.session[name]);
17
+ const [data, setData] = (0, react_2.useState)(sessionData);
18
+ (0, react_2.useEffect)(() => {
19
+ if (fetcher.data?.title) {
20
+ (0, index_js_1.showAlert)({
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) {
45
+ (0, index_js_1.showAlert)({
46
+ type: "error",
47
+ title: `Ocurrió un error al cargar la variable de configuración: ${name}.`,
48
+ description: "Error: " + ex,
49
+ });
50
+ }
51
+ }
52
+ }, []);
53
+ return data;
54
+ };
55
+ exports.useGetSessionAttribute = useGetSessionAttribute;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGetReceptionTemplate = void 0;
4
+ const react_1 = require("@remix-run/react");
5
+ const redux_1 = require("@zauru-sdk/redux");
6
+ const react_2 = require("react");
7
+ const index_js_1 = require("./index.js");
8
+ const useGetTemplateObject = (TEMPLATE_NAME, config = { online: false }) => {
9
+ const fetcher = (0, react_1.useFetcher)();
10
+ const dispatch = (0, redux_1.useAppDispatch)();
11
+ const objectData = (0, redux_1.useAppSelector)((state) => state.templates[TEMPLATE_NAME]);
12
+ const [data, setData] = (0, react_2.useState)({
13
+ data: Object.keys(objectData?.data).length
14
+ ? objectData?.data
15
+ : {},
16
+ loading: objectData.loading,
17
+ });
18
+ (0, react_2.useEffect)(() => {
19
+ if (fetcher.data?.title) {
20
+ (0, index_js_1.showAlert)({
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 (Object.keys(objectData?.data).length <= 0 || config?.online) {
41
+ try {
42
+ setData({ ...data, loading: true });
43
+ dispatch((0, redux_1.templateFetchStart)(TEMPLATE_NAME));
44
+ fetcher.load(`/api/templates?object=${TEMPLATE_NAME}`);
45
+ }
46
+ catch (ex) {
47
+ (0, index_js_1.showAlert)({
48
+ type: "error",
49
+ title: `Ocurrió un error al cargar el object de templates: ${TEMPLATE_NAME}.`,
50
+ description: "Error: " + ex,
51
+ });
52
+ }
53
+ }
54
+ }, []);
55
+ return data;
56
+ };
57
+ const useGetReceptionTemplate = (config) => useGetTemplateObject("receptionTemplate", config);
58
+ exports.useGetReceptionTemplate = useGetReceptionTemplate;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useWindowDimensions = void 0;
4
+ const react_1 = require("react");
5
+ function getWindowDimensions() {
6
+ if (typeof window !== "undefined") {
7
+ const { innerWidth: width } = window;
8
+ return width;
9
+ }
10
+ // Devolver un valor predeterminado si window no está definido
11
+ return 1000;
12
+ }
13
+ const useWindowDimensions = () => {
14
+ const [windowDimensions, setWindowDimensions] = (0, react_1.useState)(getWindowDimensions);
15
+ (0, react_1.useEffect)(() => {
16
+ if (typeof window !== "undefined") {
17
+ const handleResize = () => {
18
+ setWindowDimensions(getWindowDimensions());
19
+ };
20
+ // Use window load event to ensure accurate window size on initial load
21
+ window.addEventListener("load", handleResize);
22
+ window.addEventListener("resize", handleResize);
23
+ return () => {
24
+ window.removeEventListener("load", handleResize);
25
+ window.removeEventListener("resize", handleResize);
26
+ };
27
+ }
28
+ }, []);
29
+ return windowDimensions;
30
+ };
31
+ exports.useWindowDimensions = useWindowDimensions;
@@ -97,6 +97,6 @@ export declare const getBasketDetailsByForm: (formInput: FormInput) => {
97
97
  totales: BasketDetailsFooter;
98
98
  headers: GenericDynamicTableColumn[];
99
99
  };
100
- export declare const useGetProviderNameByPurchaseOrder: (payees: PayeeGraphQL[], purchaseOrder: PurchaseOrderGraphQL) => string | null;
101
- export declare const useGetItemNameByPurchaseOrder: (items: ItemGraphQL[], purchaseOrder: PurchaseOrderGraphQL) => string | null;
100
+ export declare const useGetProviderNameByPurchaseOrder: (payees: PayeeGraphQL[], purchaseOrder: PurchaseOrderGraphQL) => string;
101
+ export declare const useGetItemNameByPurchaseOrder: (items: ItemGraphQL[], purchaseOrder: PurchaseOrderGraphQL) => string;
102
102
  export {};
package/package.json CHANGED
@@ -1,46 +1,41 @@
1
1
  {
2
2
  "name": "@zauru-sdk/hooks",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "Hooks reutilizables dentro de las webapps de Zauru.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "type": "module",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.js",
7
+ "types": "./dist/index.d.ts",
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
11
  "scripts": {
12
- "build": "tsc",
12
+ "build": "npm run build:cjs && npm run build:esm",
13
+ "build:cjs": "tsc -p tsconfig.cjs.json",
14
+ "build:esm": "tsc -p tsconfig.esm.json",
13
15
  "test": "echo \"Error: no test specified\" && exit 1"
14
16
  },
17
+ "files": [
18
+ "dist"
19
+ ],
15
20
  "author": "Oscar Cuéllar",
16
21
  "license": "MIT",
17
22
  "devDependencies": {
18
23
  "@types/react": "^18.2.20",
19
24
  "@types/react-dom": "^18.2.7",
20
- "eslint": "^8.38.0",
21
- "eslint-config-prettier": "^9.0.0",
22
- "eslint-import-resolver-typescript": "^3.6.1",
23
- "eslint-plugin-import": "^2.28.1",
24
- "eslint-plugin-jsx-a11y": "^6.7.1",
25
- "eslint-plugin-react": "^7.33.2",
26
- "eslint-plugin-react-hooks": "^4.6.0",
27
25
  "tailwindcss": "^3.4.1",
28
26
  "typescript": "^5.1.6"
29
27
  },
30
28
  "dependencies": {
31
29
  "@remix-run/react": "^2.8.1",
32
- "@zauru-sdk/common": "^1.0.49",
30
+ "@zauru-sdk/common": "^1.0.50",
33
31
  "@zauru-sdk/graphql": "^1.0.48",
34
- "@zauru-sdk/icons": "^1.0.39",
35
- "@zauru-sdk/redux": "^1.0.49",
36
- "@zauru-sdk/services": "^1.0.49",
32
+ "@zauru-sdk/icons": "^1.0.50",
33
+ "@zauru-sdk/redux": "^1.0.51",
34
+ "@zauru-sdk/services": "^1.0.50",
37
35
  "@zauru-sdk/types": "^1.0.49",
38
- "@zauru-sdk/utils": "^1.0.49",
36
+ "@zauru-sdk/utils": "^1.0.50",
39
37
  "react": "^18.2.0",
40
38
  "react-dom": "^18.2.0"
41
39
  },
42
- "engines": {
43
- "node": ">=18.0.0"
44
- },
45
- "gitHead": "0d1f62f58f5f2e5283f03d7c2a39c6c85f8f6850"
40
+ "gitHead": "486709e3c5ca7b076f4d4ea882179b38c30998a8"
46
41
  }
package/.eslintrc.cjs DELETED
@@ -1,83 +0,0 @@
1
- /**
2
- * This is intended to be a basic starting point for linting in your app.
3
- * It relies on recommended configs out of the box for simplicity, but you can
4
- * and should modify this configuration to best suit your team's needs.
5
- */
6
-
7
- /** @type {import('eslint').Linter.Config} */
8
- module.exports = {
9
- root: true,
10
- parserOptions: {
11
- ecmaVersion: "latest",
12
- sourceType: "module",
13
- ecmaFeatures: {
14
- jsx: true,
15
- },
16
- },
17
- env: {
18
- browser: true,
19
- commonjs: true,
20
- es6: true,
21
- },
22
-
23
- // Base config
24
- extends: ["eslint:recommended"],
25
-
26
- overrides: [
27
- // React
28
- {
29
- files: ["**/*.{js,jsx,ts,tsx}"],
30
- plugins: ["react", "jsx-a11y"],
31
- extends: [
32
- "plugin:react/recommended",
33
- "plugin:react/jsx-runtime",
34
- "plugin:react-hooks/recommended",
35
- "plugin:jsx-a11y/recommended",
36
- ],
37
- settings: {
38
- react: {
39
- version: "detect",
40
- },
41
- formComponents: ["Form"],
42
- linkComponents: [
43
- { name: "Link", linkAttribute: "to" },
44
- { name: "NavLink", linkAttribute: "to" },
45
- ],
46
- "import/resolver": {
47
- typescript: {},
48
- },
49
- },
50
- },
51
-
52
- // Typescript
53
- {
54
- files: ["**/*.{ts,tsx}"],
55
- plugins: ["@typescript-eslint", "import"],
56
- parser: "@typescript-eslint/parser",
57
- settings: {
58
- "import/internal-regex": "^~/",
59
- "import/resolver": {
60
- node: {
61
- extensions: [".ts", ".tsx"],
62
- },
63
- typescript: {
64
- alwaysTryTypes: true,
65
- },
66
- },
67
- },
68
- extends: [
69
- "plugin:@typescript-eslint/recommended",
70
- "plugin:import/recommended",
71
- "plugin:import/typescript",
72
- ],
73
- },
74
-
75
- // Node
76
- {
77
- files: [".eslintrc.js"],
78
- env: {
79
- node: true,
80
- },
81
- },
82
- ],
83
- };