@zauru-sdk/hooks 2.32.4 → 6.0.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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@zauru-sdk/hooks",
3
- "version": "2.32.4",
3
+ "version": "6.0.0",
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",
7
7
  "types": "./dist/index.d.ts",
8
8
  "publishConfig": {
9
- "access": "public"
9
+ "access": "public",
10
+ "registry": "https://registry.npmjs.org/"
10
11
  },
11
12
  "scripts": {
12
13
  "build": "npm run build:esm",
@@ -26,12 +27,12 @@
26
27
  },
27
28
  "dependencies": {
28
29
  "@remix-run/react": "^2.8.1",
29
- "@zauru-sdk/common": "^2.32.3",
30
- "@zauru-sdk/icons": "^2.32.0",
31
- "@zauru-sdk/redux": "^2.32.4",
32
- "@zauru-sdk/types": "^2.32.3",
30
+ "@zauru-sdk/common": "^6.0.0",
31
+ "@zauru-sdk/icons": "^6.0.0",
32
+ "@zauru-sdk/redux": "^6.0.0",
33
+ "@zauru-sdk/types": "^6.0.0",
33
34
  "react": "^18.2.0",
34
35
  "react-dom": "^18.2.0"
35
36
  },
36
- "gitHead": "2e43f7898ae8b560f36a386b10872e9e41c98b20"
37
+ "gitHead": "32fe3db68a20bc4bfec9b59db37bd1bf221acc34"
37
38
  }
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useGetItemByPurchaseOrder = exports.useGetItemNameByPurchaseOrder = exports.useGetProviderNameByPurchaseOrder = 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 useGetReceptionObject = (RECEPTION_NAME, { online = false, wheres = [] } = {}) => {
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.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 = (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) {
60
- (0, index_js_1.showAlert)({
61
- type: "error",
62
- title: `Ocurrió un error al cargar el object de receptions: ${RECEPTION_NAME}.`,
63
- description: "Error: " + ex,
64
- });
65
- }
66
- }
67
- }, []);
68
- return data;
69
- }
70
- catch (ex) {
71
- (0, index_js_1.showAlert)({
72
- type: "error",
73
- title: `Ocurrió un error al cargar el object de receptions: ${RECEPTION_NAME}.`,
74
- description: "Error: " + ex,
75
- });
76
- return { data: {}, loading: false };
77
- }
78
- };
79
- const useGetProcesses = (config) => useGetReceptionObject("queueReceptions", config);
80
- exports.useGetProcesses = useGetProcesses;
81
- const useGetPOReceptions = (config) => useGetReceptionObject("poReceptions", config);
82
- exports.useGetPOReceptions = useGetPOReceptions;
83
- const useGetBasketLots = () => useGetReceptionObject("basketLots");
84
- exports.useGetBasketLots = useGetBasketLots;
85
- const useGetRejectionInfo = () => useGetReceptionObject("rejectionInfo");
86
- exports.useGetRejectionInfo = useGetRejectionInfo;
87
- const useGetNewPurchaseOrderInfo = () => useGetReceptionObject("newPurchaseOrderInfo");
88
- exports.useGetNewPurchaseOrderInfo = useGetNewPurchaseOrderInfo;
89
- const useGetPurchaseOrderGeneralInfo = () => useGetReceptionObject("purchaseOrderGeneralInfo");
90
- exports.useGetPurchaseOrderGeneralInfo = useGetPurchaseOrderGeneralInfo;
91
- const useGetProviderNameByPurchaseOrder = (payees, purchaseOrder) => {
92
- const providerName = (0, react_2.useMemo)(() => {
93
- if (!purchaseOrder)
94
- return null;
95
- const provider = payees.find((x) => x.id == purchaseOrder.payee_id);
96
- if (provider) {
97
- return `<${provider.id_number}> ${provider.tin ? `${provider.tin} | ` : ""}${provider.name}`;
98
- }
99
- return null;
100
- }, [payees, purchaseOrder]);
101
- return providerName;
102
- };
103
- exports.useGetProviderNameByPurchaseOrder = useGetProviderNameByPurchaseOrder;
104
- const useGetItemNameByPurchaseOrder = (items, purchaseOrder) => {
105
- const itemName = (0, react_2.useMemo)(() => {
106
- if (!purchaseOrder)
107
- return null;
108
- if (purchaseOrder.purchase_order_details.length > 0 && items.length > 0) {
109
- const item = items.find((x) => x.id == purchaseOrder.purchase_order_details[0].item_id);
110
- return `${item?.id} - ${item?.code} - ${item?.name}`;
111
- }
112
- return null;
113
- }, [items, purchaseOrder]);
114
- return itemName;
115
- };
116
- exports.useGetItemNameByPurchaseOrder = useGetItemNameByPurchaseOrder;
117
- const useGetItemByPurchaseOrder = (items, purchaseOrder) => {
118
- const item = (0, react_2.useMemo)(() => {
119
- if (!purchaseOrder)
120
- return null;
121
- if (purchaseOrder.purchase_order_details.length > 0 && items.length > 0) {
122
- const item = items.find((x) => x.id == purchaseOrder.purchase_order_details[0].item_id);
123
- return item;
124
- }
125
- return null;
126
- }, [items, purchaseOrder]);
127
- return item;
128
- };
129
- exports.useGetItemByPurchaseOrder = useGetItemByPurchaseOrder;
@@ -1,41 +0,0 @@
1
- import { ItemAssociatedLots, ItemGraphQL, NewPurchaseOrderResponse, PayeeGraphQL, PurchaseOrderGraphQL, WebAppRowGraphQL, QueueFormReceptionWebAppTable, RejectionWebAppTableObject, PurchaseOrderGeneralInfo } from "@zauru-sdk/types";
2
- type ConfigProps = {
3
- online?: boolean;
4
- wheres?: string[];
5
- };
6
- export declare const useGetProcesses: (config?: ConfigProps) => {
7
- loading: boolean;
8
- data: WebAppRowGraphQL<QueueFormReceptionWebAppTable>[];
9
- };
10
- export declare const useGetPOReceptions: (config?: ConfigProps) => {
11
- loading: boolean;
12
- data: PurchaseOrderGraphQL[];
13
- };
14
- export declare const useGetBasketLots: () => {
15
- loading: boolean;
16
- data: ItemAssociatedLots;
17
- };
18
- export declare const useGetRejectionInfo: () => {
19
- loading: boolean;
20
- data: RejectionWebAppTableObject;
21
- };
22
- export declare const useGetNewPurchaseOrderInfo: () => {
23
- loading: boolean;
24
- data: NewPurchaseOrderResponse;
25
- };
26
- export declare const useGetPurchaseOrderGeneralInfo: () => {
27
- loading: boolean;
28
- data: PurchaseOrderGeneralInfo;
29
- };
30
- /**
31
- * ---------------- Hooks personalizados
32
- */
33
- export type FooterColumnConfig = {
34
- content: React.ReactNode;
35
- className?: string;
36
- name?: string;
37
- };
38
- export declare const useGetProviderNameByPurchaseOrder: (payees: PayeeGraphQL[], purchaseOrder?: PurchaseOrderGraphQL) => string;
39
- export declare const useGetItemNameByPurchaseOrder: (items: ItemGraphQL[], purchaseOrder?: PurchaseOrderGraphQL) => string;
40
- export declare const useGetItemByPurchaseOrder: (items: ItemGraphQL[], purchaseOrder?: PurchaseOrderGraphQL) => ItemGraphQL;
41
- export {};