@zauru-sdk/hooks 2.30.0 → 2.31.1
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/catalogs.d.ts +11 -2
- package/dist/esm/catalogs.js +29 -8
- package/package.json +3 -3
package/dist/catalogs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgencyGraphQL, BitacoraPOMassive, BundleGraphQL, CaseGraphQL, CurrencyGraphQL, EmployeeGraphQL, FormGraphQL, InvoiceGraphQL, ItemCategoryGraphQL, ItemGraphQL, LotStockGraphQL, MotivoRechazo, PayeeCategoryGraphQL, PayeeGraphQL, PaymentTermGraphQL, ReceptionType, ShipmentGraphQL, SubmissionCasesGraphQL, SubmissionInvoicesGraphQL, SuggestedPriceGraphQL, Template, TipoMuestra, WebAppRowGraphQL, PrintTemplateGraphQL, PaymentMethodGraphQL, CCPorcentajeRechazo, SolicitudEliminacionPO, AuthorizationUpdateDiscountPO, PoDiscountHistory, PesoMaximoPorCanasta } from "@zauru-sdk/types";
|
|
1
|
+
import type { AgencyGraphQL, BitacoraPOMassive, BundleGraphQL, CaseGraphQL, CurrencyGraphQL, EmployeeGraphQL, FormGraphQL, InvoiceGraphQL, ItemCategoryGraphQL, ItemGraphQL, LotStockGraphQL, MotivoRechazo, PayeeCategoryGraphQL, PayeeGraphQL, PaymentTermGraphQL, ReceptionType, ShipmentGraphQL, SubmissionCasesGraphQL, SubmissionInvoicesGraphQL, SuggestedPriceGraphQL, Template, TipoMuestra, WebAppRowGraphQL, PrintTemplateGraphQL, PaymentMethodGraphQL, CCPorcentajeRechazo, SolicitudEliminacionPO, AuthorizationUpdateDiscountPO, PoDiscountHistory, PesoMaximoPorCanasta, Programacion } from "@zauru-sdk/types";
|
|
2
2
|
import { CATALOGS_NAMES, ReduxParamsConfig } from "@zauru-sdk/redux";
|
|
3
3
|
type CatalogType<T> = {
|
|
4
4
|
data: T[];
|
|
@@ -15,8 +15,13 @@ type CatalogType<T> = {
|
|
|
15
15
|
* otherParams: {
|
|
16
16
|
includeDiscounts: "true",
|
|
17
17
|
}
|
|
18
|
+
*
|
|
19
|
+
* staleWhileRevalidate: true — if Redux already has data, show it at once and
|
|
20
|
+
* refetch in the background; on success data is replaced silently, on error the
|
|
21
|
+
* cache is kept. When there is no cached data, behavior matches a normal load
|
|
22
|
+
* (loading true until the first response).
|
|
18
23
|
*/
|
|
19
|
-
export declare function useGetReduxCatalog<T>(CATALOG_NAME: CATALOGS_NAMES, { online, wheres, otherParams }?: ReduxParamsConfig): CatalogType<T>;
|
|
24
|
+
export declare function useGetReduxCatalog<T>(CATALOG_NAME: CATALOGS_NAMES, { online, staleWhileRevalidate, wheres, otherParams, }?: ReduxParamsConfig): CatalogType<T>;
|
|
20
25
|
/**
|
|
21
26
|
*
|
|
22
27
|
* ======================= HOOKS
|
|
@@ -159,6 +164,10 @@ export declare const useGetCCPorcentajesDeRechazo: (config?: ReduxParamsConfig)
|
|
|
159
164
|
loading: boolean;
|
|
160
165
|
data: WebAppRowGraphQL<CCPorcentajeRechazo>[];
|
|
161
166
|
};
|
|
167
|
+
export declare const useGetProgramaciones: (config?: ReduxParamsConfig) => {
|
|
168
|
+
loading: boolean;
|
|
169
|
+
data: WebAppRowGraphQL<Programacion>[];
|
|
170
|
+
};
|
|
162
171
|
export declare const useGet4pinosSolicitudEliminacionPO: (config?: ReduxParamsConfig) => {
|
|
163
172
|
loading: boolean;
|
|
164
173
|
data: WebAppRowGraphQL<SolicitudEliminacionPO>[];
|
package/dist/esm/catalogs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useGetInvoiceFormSubmissionsByInvoiceId = exports.useGetCaseFormSubmissionsByCaseId = exports.useGetMyCaseFormSubmissions = exports.useGetInvoiceFormSubmissionsByAgencyId = exports.useGetCaseForms = exports.useGetInvoiceForms = exports.useGetAllForms = exports.useGetBitacoraRechazoMasivo = exports.useGetAuthorizationsUpdateDiscountPO = exports.useGet4pinosPoDiscountHistory = exports.useGet4pinosWeightLimitPerBasket = exports.useGet4pinosSolicitudEliminacionPO = exports.useGetCCPorcentajesDeRechazo = exports.useGetMotivosDeRechazo = exports.useGetTiposDeMuestra = exports.useGetInvoicesByCurrentAgency = exports.useGetInvoicesByLab = exports.useGetShipmentsToMyAgency = exports.useGetEmployees = exports.useGetEmployeesByCurrentAgency = exports.useGetEmployeesByLab = exports.useGetPaymentMethods = exports.useGetPaymentTerms = exports.useGetSuggestedPrices = exports.useGetAgencies = exports.useGetPrintTemplates = exports.useGetPayeesForLab = exports.useGetPayees = exports.useGetClientCategories = exports.useGetProviderCategories = exports.useGetCases = exports.useGetProviders = exports.useGetReceptionTypes = exports.useGetCurrencies = exports.useGetBundlesForLab = exports.useGetBundlesRecipForLab = exports.useGetPayeeCategoriesLabPrices = exports.useGetPayeeCategories = exports.useGetTemplates = exports.useGetBookings = exports.useGetItemCategoriesForLab = exports.useGetItemServicesByLab = exports.useGetMyAgencyLotStocks = exports.useGetItemsByLab = exports.useGetItemsByReception = exports.useGetItems = void 0;
|
|
3
|
+
exports.useGetInvoiceFormSubmissionsByInvoiceId = exports.useGetCaseFormSubmissionsByCaseId = exports.useGetMyCaseFormSubmissions = exports.useGetInvoiceFormSubmissionsByAgencyId = exports.useGetCaseForms = exports.useGetInvoiceForms = exports.useGetAllForms = exports.useGetBitacoraRechazoMasivo = exports.useGetAuthorizationsUpdateDiscountPO = exports.useGet4pinosPoDiscountHistory = exports.useGet4pinosWeightLimitPerBasket = exports.useGet4pinosSolicitudEliminacionPO = exports.useGetProgramaciones = exports.useGetCCPorcentajesDeRechazo = exports.useGetMotivosDeRechazo = exports.useGetTiposDeMuestra = exports.useGetInvoicesByCurrentAgency = exports.useGetInvoicesByLab = exports.useGetShipmentsToMyAgency = exports.useGetEmployees = exports.useGetEmployeesByCurrentAgency = exports.useGetEmployeesByLab = exports.useGetPaymentMethods = exports.useGetPaymentTerms = exports.useGetSuggestedPrices = exports.useGetAgencies = exports.useGetPrintTemplates = exports.useGetPayeesForLab = exports.useGetPayees = exports.useGetClientCategories = exports.useGetProviderCategories = exports.useGetCases = exports.useGetProviders = exports.useGetReceptionTypes = exports.useGetCurrencies = exports.useGetBundlesForLab = exports.useGetBundlesRecipForLab = exports.useGetPayeeCategoriesLabPrices = exports.useGetPayeeCategories = exports.useGetTemplates = exports.useGetBookings = exports.useGetItemCategoriesForLab = exports.useGetItemServicesByLab = exports.useGetMyAgencyLotStocks = exports.useGetItemsByLab = exports.useGetItemsByReception = exports.useGetItems = void 0;
|
|
4
4
|
exports.useGetReduxCatalog = useGetReduxCatalog;
|
|
5
5
|
const react_1 = require("@remix-run/react");
|
|
6
6
|
const react_2 = require("react");
|
|
@@ -17,8 +17,13 @@ const redux_1 = require("@zauru-sdk/redux");
|
|
|
17
17
|
* otherParams: {
|
|
18
18
|
includeDiscounts: "true",
|
|
19
19
|
}
|
|
20
|
+
*
|
|
21
|
+
* staleWhileRevalidate: true — if Redux already has data, show it at once and
|
|
22
|
+
* refetch in the background; on success data is replaced silently, on error the
|
|
23
|
+
* cache is kept. When there is no cached data, behavior matches a normal load
|
|
24
|
+
* (loading true until the first response).
|
|
20
25
|
*/
|
|
21
|
-
function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherParams } = {}) {
|
|
26
|
+
function useGetReduxCatalog(CATALOG_NAME, { online = false, staleWhileRevalidate = false, wheres = [], otherParams, } = {}) {
|
|
22
27
|
const dispatch = (0, redux_1.useAppDispatch)();
|
|
23
28
|
const fetcher = (0, react_1.useFetcher)();
|
|
24
29
|
const [fetchTriggered, setFetchTriggered] = (0, react_2.useState)(false);
|
|
@@ -36,14 +41,28 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
36
41
|
* Lógica:
|
|
37
42
|
* - Si `online: true`, forzamos el fetch.
|
|
38
43
|
* - Si `reFetch: true`, también forzamos el fetch.
|
|
39
|
-
* - Si `
|
|
40
|
-
*
|
|
44
|
+
* - Si `staleWhileRevalidate: true` y hay data en Redux, forzamos fetch en segundo plano
|
|
45
|
+
* sin poner `loading: true` (se muestra la caché hasta que llegue respuesta o falle).
|
|
46
|
+
* - Si `online: false` y SÍ tenemos data local y no aplica lo anterior, NO hacemos fetch.
|
|
47
|
+
* - Si no hay data local, SÍ hacemos fetch (porque no hay nada que mostrar).
|
|
41
48
|
*/
|
|
42
49
|
(0, react_2.useEffect)(() => {
|
|
43
|
-
const
|
|
50
|
+
const revalidateInBackground = Boolean(staleWhileRevalidate) && hasLocalData;
|
|
51
|
+
const mustFetch = online ||
|
|
52
|
+
catalogData?.reFetch ||
|
|
53
|
+
!hasLocalData ||
|
|
54
|
+
revalidateInBackground;
|
|
44
55
|
if (mustFetch) {
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
if (revalidateInBackground) {
|
|
57
|
+
setData({
|
|
58
|
+
data: catalogData?.data || [],
|
|
59
|
+
loading: false,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
setData((prev) => ({ ...prev, loading: true }));
|
|
64
|
+
dispatch((0, redux_1.catalogsFetchStart)(CATALOG_NAME));
|
|
65
|
+
}
|
|
47
66
|
// Construimos el query para `wheres` y `otherParams`
|
|
48
67
|
const encodedWheres = (wheres || []).map((where) => encodeURIComponent(where));
|
|
49
68
|
const wheresQueryParam = encodedWheres.join("&");
|
|
@@ -93,7 +112,7 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
93
112
|
});
|
|
94
113
|
}
|
|
95
114
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
-
}, [online, catalogData?.reFetch, hasLocalData]);
|
|
115
|
+
}, [online, staleWhileRevalidate, catalogData?.reFetch, hasLocalData]);
|
|
97
116
|
/**
|
|
98
117
|
* Efecto que observa la finalización del fetch (fetcher.state === "idle")
|
|
99
118
|
* y decide qué hacer con la data o error recibidos.
|
|
@@ -270,6 +289,8 @@ const useGetMotivosDeRechazo = (config) => useGetReduxCatalog("motivosRechazo",
|
|
|
270
289
|
exports.useGetMotivosDeRechazo = useGetMotivosDeRechazo;
|
|
271
290
|
const useGetCCPorcentajesDeRechazo = (config) => useGetReduxCatalog("ccPorcentajesDeRechazo", config);
|
|
272
291
|
exports.useGetCCPorcentajesDeRechazo = useGetCCPorcentajesDeRechazo;
|
|
292
|
+
const useGetProgramaciones = (config) => useGetReduxCatalog("programaciones4pinos", config);
|
|
293
|
+
exports.useGetProgramaciones = useGetProgramaciones;
|
|
273
294
|
const useGet4pinosSolicitudEliminacionPO = (config) => useGetReduxCatalog("solicitudesEliminacionPO", config);
|
|
274
295
|
exports.useGet4pinosSolicitudEliminacionPO = useGet4pinosSolicitudEliminacionPO;
|
|
275
296
|
const useGet4pinosWeightLimitPerBasket = (config) => useGetReduxCatalog("pesoMaximoPorCanasta", config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/hooks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.31.1",
|
|
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",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"@remix-run/react": "^2.8.1",
|
|
29
29
|
"@zauru-sdk/common": "^2.30.0",
|
|
30
30
|
"@zauru-sdk/icons": "^2.0.188",
|
|
31
|
-
"@zauru-sdk/redux": "^2.
|
|
31
|
+
"@zauru-sdk/redux": "^2.31.1",
|
|
32
32
|
"@zauru-sdk/types": "^2.30.0",
|
|
33
33
|
"react": "^18.2.0",
|
|
34
34
|
"react-dom": "^18.2.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "220d939967adc34a44c6cf0671f0234253bbfa45"
|
|
37
37
|
}
|