@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.
- package/dist/alerts.d.ts +1 -1
- package/dist/{alerts.js → cjs/alerts.js} +13 -9
- package/dist/{automaticNumbers.js → cjs/automaticNumbers.js} +20 -16
- package/dist/cjs/catalogs.js +267 -0
- package/dist/{components → cjs/components}/Alert.js +18 -15
- package/dist/cjs/components/index.js +17 -0
- package/dist/cjs/index.js +26 -0
- package/dist/{onlineStatus.js → cjs/onlineStatus.js} +8 -4
- package/dist/cjs/profiles.js +64 -0
- package/dist/{receptions.js → cjs/receptions.js} +67 -52
- package/dist/{session.js → cjs/session.js} +19 -15
- package/dist/{templates.js → cjs/templates.js} +20 -16
- package/dist/{useWindowDimensions.js → cjs/useWindowDimensions.js} +8 -4
- package/dist/esm/alerts.js +37 -0
- package/dist/esm/automaticNumbers.js +57 -0
- package/dist/esm/catalogs.js +267 -0
- package/dist/esm/components/Alert.js +100 -0
- package/dist/esm/components/index.js +17 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/onlineStatus.js +31 -0
- package/dist/esm/profiles.js +64 -0
- package/dist/esm/receptions.js +348 -0
- package/dist/esm/session.js +55 -0
- package/dist/esm/templates.js +58 -0
- package/dist/esm/useWindowDimensions.js +31 -0
- package/dist/receptions.d.ts +2 -2
- package/package.json +16 -21
- package/.eslintrc.cjs +0 -83
- package/CHANGELOG.md +0 -224
- package/dist/catalogs.js +0 -230
- package/dist/components/index.js +0 -1
- package/dist/index.js +0 -10
- package/dist/profiles.js +0 -57
- package/src/alerts.ts +0 -43
- package/src/automaticNumbers.ts +0 -74
- package/src/catalogs.ts +0 -557
- package/src/components/Alert.tsx +0 -149
- package/src/components/index.ts +0 -1
- package/src/index.ts +0 -11
- package/src/onlineStatus.ts +0 -34
- package/src/profiles.ts +0 -103
- package/src/receptions.ts +0 -548
- package/src/session.ts +0 -69
- package/src/templates.ts +0 -84
- package/src/useWindowDimensions.ts +0 -34
- package/tsconfig.json +0 -26
package/src/catalogs.ts
DELETED
|
@@ -1,557 +0,0 @@
|
|
|
1
|
-
import { useFetcher } from "@remix-run/react";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import { AlertType, showAlert } from "./components/index.js";
|
|
4
|
-
import type {
|
|
5
|
-
AgencyGraphQL,
|
|
6
|
-
BitacoraPOMassive,
|
|
7
|
-
BundleGraphQL,
|
|
8
|
-
CaseGraphQL,
|
|
9
|
-
CurrencyGraphQL,
|
|
10
|
-
EmployeeGraphQL,
|
|
11
|
-
FormGraphQL,
|
|
12
|
-
InvoiceGraphQL,
|
|
13
|
-
ItemCategoryGraphQL,
|
|
14
|
-
ItemGraphQL,
|
|
15
|
-
LotStockGraphQL,
|
|
16
|
-
MotivoRechazo,
|
|
17
|
-
PayeeCategoryGraphQL,
|
|
18
|
-
PayeeGraphQL,
|
|
19
|
-
PaymentTermGraphQL,
|
|
20
|
-
ReceptionType,
|
|
21
|
-
ShipmentGraphQL,
|
|
22
|
-
SubmissionCasesGraphQL,
|
|
23
|
-
SubmissionInvoicesGraphQL,
|
|
24
|
-
SuggestedPriceGraphQL,
|
|
25
|
-
Template,
|
|
26
|
-
TipoMuestra,
|
|
27
|
-
WebAppRowGraphQL,
|
|
28
|
-
} from "@zauru-sdk/types";
|
|
29
|
-
import {
|
|
30
|
-
CATALOGS_NAMES,
|
|
31
|
-
ONLINE_CATALOGS_NAMES,
|
|
32
|
-
ReduxParamsConfig,
|
|
33
|
-
catalogsFetchStart,
|
|
34
|
-
catalogsFetchSuccess,
|
|
35
|
-
useAppDispatch,
|
|
36
|
-
useAppSelector,
|
|
37
|
-
} from "@zauru-sdk/redux";
|
|
38
|
-
|
|
39
|
-
type CatalogType<T> = {
|
|
40
|
-
data: T[];
|
|
41
|
-
loading: boolean;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const useApiCatalog = <T>(
|
|
45
|
-
CATALOG_NAME: CATALOGS_NAMES | ONLINE_CATALOGS_NAMES,
|
|
46
|
-
otherParams?: { [key: string]: string }
|
|
47
|
-
): CatalogType<T> => {
|
|
48
|
-
const fetcher = useFetcher<
|
|
49
|
-
| {
|
|
50
|
-
title: string;
|
|
51
|
-
description: string;
|
|
52
|
-
type: AlertType;
|
|
53
|
-
}
|
|
54
|
-
| { [key: string]: T[] }
|
|
55
|
-
>();
|
|
56
|
-
const [data, setData] = useState<CatalogType<T>>({
|
|
57
|
-
data: [],
|
|
58
|
-
loading: true,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (fetcher.data?.title) {
|
|
63
|
-
showAlert({
|
|
64
|
-
description: fetcher.data?.description?.toString(),
|
|
65
|
-
title: fetcher.data?.title?.toString(),
|
|
66
|
-
type: fetcher.data?.type?.toString() as AlertType,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}, [fetcher.data]);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
73
|
-
const receivedData = fetcher.data as { [key: string]: T[] };
|
|
74
|
-
if (receivedData) {
|
|
75
|
-
setData({ data: receivedData[CATALOG_NAME], loading: false });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}, [fetcher, CATALOG_NAME]);
|
|
79
|
-
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
try {
|
|
82
|
-
setData({ ...data, loading: true });
|
|
83
|
-
// Convert otherParams to query string
|
|
84
|
-
const paramsString = otherParams
|
|
85
|
-
? Object.entries(otherParams)
|
|
86
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
87
|
-
.join("&")
|
|
88
|
-
: "";
|
|
89
|
-
|
|
90
|
-
const url = `/api/catalogs?catalog=${CATALOG_NAME}${
|
|
91
|
-
paramsString ? `&${paramsString}` : ""
|
|
92
|
-
}`;
|
|
93
|
-
|
|
94
|
-
fetcher.load(url);
|
|
95
|
-
} catch (ex) {
|
|
96
|
-
showAlert({
|
|
97
|
-
type: "error",
|
|
98
|
-
title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
|
|
99
|
-
description: "Error: " + ex,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, []);
|
|
103
|
-
|
|
104
|
-
return data;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const useGetReduxCatalog = <T>(
|
|
108
|
-
CATALOG_NAME: CATALOGS_NAMES,
|
|
109
|
-
{ online = false, wheres = [], otherParams }: ReduxParamsConfig = {}
|
|
110
|
-
): CatalogType<T> => {
|
|
111
|
-
const fetcher = useFetcher<
|
|
112
|
-
| {
|
|
113
|
-
title: string;
|
|
114
|
-
description: string;
|
|
115
|
-
type: AlertType;
|
|
116
|
-
}
|
|
117
|
-
| { [key: string]: T[] }
|
|
118
|
-
>();
|
|
119
|
-
const dispatch = useAppDispatch();
|
|
120
|
-
const catalogData = useAppSelector((state) => state.catalogs[CATALOG_NAME]);
|
|
121
|
-
const [data, setData] = useState<CatalogType<T>>({
|
|
122
|
-
data: catalogData?.data?.length ? (catalogData.data as T[]) : [],
|
|
123
|
-
loading: catalogData.loading,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
if (fetcher.data?.description) {
|
|
128
|
-
showAlert({
|
|
129
|
-
description: fetcher.data?.description?.toString(),
|
|
130
|
-
title: fetcher.data?.title?.toString(),
|
|
131
|
-
type: fetcher.data?.type?.toString() as AlertType,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}, [fetcher.data]);
|
|
135
|
-
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
if (fetcher.state === "idle" && fetcher.data != null) {
|
|
138
|
-
const receivedData = fetcher.data as { [key: string]: T[] };
|
|
139
|
-
if (receivedData) {
|
|
140
|
-
setData({ data: receivedData[CATALOG_NAME], loading: false });
|
|
141
|
-
dispatch(
|
|
142
|
-
catalogsFetchSuccess({
|
|
143
|
-
name: CATALOG_NAME,
|
|
144
|
-
data: receivedData[CATALOG_NAME],
|
|
145
|
-
})
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}, [fetcher, dispatch, CATALOG_NAME]);
|
|
150
|
-
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
if (catalogData?.data?.length <= 0 || catalogData?.reFetch || online) {
|
|
153
|
-
try {
|
|
154
|
-
setData({ ...data, loading: true });
|
|
155
|
-
dispatch(catalogsFetchStart(CATALOG_NAME));
|
|
156
|
-
// Convierte cada elemento del array a una cadena codificada para URL
|
|
157
|
-
const encodedWheres = wheres.map((where) => encodeURIComponent(where));
|
|
158
|
-
// Une los elementos codificados con '&'
|
|
159
|
-
const wheresQueryParam = encodedWheres.join("&");
|
|
160
|
-
|
|
161
|
-
// Convert otherParams to query string
|
|
162
|
-
const paramsString = otherParams
|
|
163
|
-
? Object.entries(otherParams)
|
|
164
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
165
|
-
.join("&")
|
|
166
|
-
: "";
|
|
167
|
-
|
|
168
|
-
fetcher.load(
|
|
169
|
-
`/api/catalogs?catalog=${CATALOG_NAME}&wheres=${wheresQueryParam}${
|
|
170
|
-
paramsString ? `&${paramsString}` : ""
|
|
171
|
-
}`
|
|
172
|
-
);
|
|
173
|
-
} catch (ex) {
|
|
174
|
-
showAlert({
|
|
175
|
-
type: "error",
|
|
176
|
-
title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
|
|
177
|
-
description: "Error: " + ex,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}, []);
|
|
182
|
-
|
|
183
|
-
return data;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
*
|
|
188
|
-
* ======================= HOOKS
|
|
189
|
-
*/
|
|
190
|
-
export const useGetItems = (
|
|
191
|
-
config?: ReduxParamsConfig
|
|
192
|
-
): {
|
|
193
|
-
loading: boolean;
|
|
194
|
-
data: ItemGraphQL[];
|
|
195
|
-
} => useGetReduxCatalog<ItemGraphQL>("items", config);
|
|
196
|
-
|
|
197
|
-
export const useGetItemsByReception = (
|
|
198
|
-
config?: ReduxParamsConfig
|
|
199
|
-
): {
|
|
200
|
-
loading: boolean;
|
|
201
|
-
data: ItemGraphQL[];
|
|
202
|
-
} => useGetReduxCatalog<ItemGraphQL>("itemsByReception", config);
|
|
203
|
-
|
|
204
|
-
export const useGetItemsByLab = (
|
|
205
|
-
config?: ReduxParamsConfig
|
|
206
|
-
): {
|
|
207
|
-
loading: boolean;
|
|
208
|
-
data: ItemGraphQL[];
|
|
209
|
-
} => useGetReduxCatalog<ItemGraphQL>("itemsByLab", config);
|
|
210
|
-
|
|
211
|
-
export const useGetMyAgencyLotStocks = (
|
|
212
|
-
config?: ReduxParamsConfig
|
|
213
|
-
): {
|
|
214
|
-
loading: boolean;
|
|
215
|
-
data: LotStockGraphQL[];
|
|
216
|
-
} => useGetReduxCatalog<LotStockGraphQL>("myAgencyLotStocks", config);
|
|
217
|
-
|
|
218
|
-
export const useGetItemServicesByLab = (
|
|
219
|
-
config?: ReduxParamsConfig
|
|
220
|
-
): {
|
|
221
|
-
loading: boolean;
|
|
222
|
-
data: ItemGraphQL[];
|
|
223
|
-
} => useGetReduxCatalog<ItemGraphQL>("itemServicesByLab", config);
|
|
224
|
-
|
|
225
|
-
export const useGetItemCategoriesForLab = (
|
|
226
|
-
config?: ReduxParamsConfig
|
|
227
|
-
): {
|
|
228
|
-
loading: boolean;
|
|
229
|
-
data: ItemCategoryGraphQL[];
|
|
230
|
-
} => useGetReduxCatalog<ItemCategoryGraphQL>("itemCategoriesForLab", config);
|
|
231
|
-
|
|
232
|
-
export const useGetBookings = (
|
|
233
|
-
config?: ReduxParamsConfig
|
|
234
|
-
): {
|
|
235
|
-
loading: boolean;
|
|
236
|
-
data: ShipmentGraphQL[];
|
|
237
|
-
} => useGetReduxCatalog<ShipmentGraphQL>("bookings", config);
|
|
238
|
-
|
|
239
|
-
export const useGetTemplates = (
|
|
240
|
-
config?: ReduxParamsConfig
|
|
241
|
-
): {
|
|
242
|
-
loading: boolean;
|
|
243
|
-
data: WebAppRowGraphQL<Template>[];
|
|
244
|
-
} => useGetReduxCatalog<WebAppRowGraphQL<Template>>("templates", config);
|
|
245
|
-
|
|
246
|
-
export const useGetPayeeCategoriesLabPrices = (
|
|
247
|
-
config: {
|
|
248
|
-
withPriceListIdNull: boolean;
|
|
249
|
-
} = { withPriceListIdNull: false }
|
|
250
|
-
): {
|
|
251
|
-
loading: boolean;
|
|
252
|
-
data: PayeeCategoryGraphQL[];
|
|
253
|
-
} => {
|
|
254
|
-
const data = useGetReduxCatalog<PayeeCategoryGraphQL>(
|
|
255
|
-
"payeeCategoriesLabPrices"
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
let tempData = data.data;
|
|
259
|
-
if (!config.withPriceListIdNull) {
|
|
260
|
-
tempData = data.data.filter((x) => x.price_list_id);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return { ...data, data: tempData };
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
export const useGetBundlesRecipForLab = (
|
|
267
|
-
config?: ReduxParamsConfig
|
|
268
|
-
): {
|
|
269
|
-
loading: boolean;
|
|
270
|
-
data: BundleGraphQL[];
|
|
271
|
-
} => useGetReduxCatalog<BundleGraphQL>("bundlesRecipForLab", config);
|
|
272
|
-
|
|
273
|
-
export const useGetBundlesForLab = (
|
|
274
|
-
config?: ReduxParamsConfig
|
|
275
|
-
): {
|
|
276
|
-
loading: boolean;
|
|
277
|
-
data: BundleGraphQL[];
|
|
278
|
-
} => useGetReduxCatalog<BundleGraphQL>("bundlesForLab", config);
|
|
279
|
-
|
|
280
|
-
export const useGetCurrencies = (
|
|
281
|
-
config?: ReduxParamsConfig
|
|
282
|
-
): {
|
|
283
|
-
loading: boolean;
|
|
284
|
-
data: CurrencyGraphQL[];
|
|
285
|
-
} => useGetReduxCatalog<CurrencyGraphQL>("currencies", config);
|
|
286
|
-
|
|
287
|
-
export const useGetReceptionTypes = (
|
|
288
|
-
config?: ReduxParamsConfig
|
|
289
|
-
): {
|
|
290
|
-
loading: boolean;
|
|
291
|
-
data: WebAppRowGraphQL<ReceptionType>[];
|
|
292
|
-
} =>
|
|
293
|
-
useGetReduxCatalog<WebAppRowGraphQL<ReceptionType>>("receptionTypes", config);
|
|
294
|
-
|
|
295
|
-
export const useGetProviders = (
|
|
296
|
-
config?: ReduxParamsConfig
|
|
297
|
-
): {
|
|
298
|
-
loading: boolean;
|
|
299
|
-
data: PayeeGraphQL[];
|
|
300
|
-
} => useGetReduxCatalog<PayeeGraphQL>("providers", config);
|
|
301
|
-
|
|
302
|
-
export const useGetMyCases = (
|
|
303
|
-
config?: ReduxParamsConfig
|
|
304
|
-
): {
|
|
305
|
-
loading: boolean;
|
|
306
|
-
data: CaseGraphQL[];
|
|
307
|
-
} => useGetReduxCatalog<CaseGraphQL>("myCases", config);
|
|
308
|
-
|
|
309
|
-
export const useGetProviderCategories = (
|
|
310
|
-
config?: ReduxParamsConfig
|
|
311
|
-
): {
|
|
312
|
-
loading: boolean;
|
|
313
|
-
data: PayeeCategoryGraphQL[];
|
|
314
|
-
} => useGetReduxCatalog<PayeeCategoryGraphQL>("providerCategories", config);
|
|
315
|
-
|
|
316
|
-
export const useGetClientCategories = (
|
|
317
|
-
config?: ReduxParamsConfig
|
|
318
|
-
): {
|
|
319
|
-
loading: boolean;
|
|
320
|
-
data: PayeeCategoryGraphQL[];
|
|
321
|
-
} => useGetReduxCatalog<PayeeCategoryGraphQL>("clientCategories", config);
|
|
322
|
-
|
|
323
|
-
export const useGetPayees = (
|
|
324
|
-
config?: ReduxParamsConfig
|
|
325
|
-
): {
|
|
326
|
-
loading: boolean;
|
|
327
|
-
data: PayeeGraphQL[];
|
|
328
|
-
} => useGetReduxCatalog<PayeeGraphQL>("payees", config);
|
|
329
|
-
|
|
330
|
-
export const useGetPayeesForLab = (
|
|
331
|
-
config?: ReduxParamsConfig
|
|
332
|
-
): {
|
|
333
|
-
loading: boolean;
|
|
334
|
-
data: PayeeGraphQL[];
|
|
335
|
-
} => useGetReduxCatalog<PayeeGraphQL>("payeesForLab", config);
|
|
336
|
-
|
|
337
|
-
export const useGetAgencies = (
|
|
338
|
-
config?: ReduxParamsConfig
|
|
339
|
-
): {
|
|
340
|
-
loading: boolean;
|
|
341
|
-
data: AgencyGraphQL[];
|
|
342
|
-
} => useGetReduxCatalog<AgencyGraphQL>("agencies", config);
|
|
343
|
-
|
|
344
|
-
export const useGetSuggestedPrices = (
|
|
345
|
-
config?: ReduxParamsConfig
|
|
346
|
-
): {
|
|
347
|
-
loading: boolean;
|
|
348
|
-
data: SuggestedPriceGraphQL[];
|
|
349
|
-
} => useGetReduxCatalog<SuggestedPriceGraphQL>("suggestedPrices", config);
|
|
350
|
-
|
|
351
|
-
export const useGetPaymentTerms = (
|
|
352
|
-
config?: ReduxParamsConfig
|
|
353
|
-
): {
|
|
354
|
-
loading: boolean;
|
|
355
|
-
data: PaymentTermGraphQL[];
|
|
356
|
-
} => useGetReduxCatalog<PaymentTermGraphQL>("paymentTerms", config);
|
|
357
|
-
|
|
358
|
-
export const useGetEmployeesByLab = (
|
|
359
|
-
config?: ReduxParamsConfig
|
|
360
|
-
): {
|
|
361
|
-
loading: boolean;
|
|
362
|
-
data: EmployeeGraphQL[];
|
|
363
|
-
} => useGetReduxCatalog<EmployeeGraphQL>("employeesByLab", config);
|
|
364
|
-
|
|
365
|
-
export const useGetEmployeesByCurrentAgency = (
|
|
366
|
-
config?: ReduxParamsConfig
|
|
367
|
-
): {
|
|
368
|
-
loading: boolean;
|
|
369
|
-
data: EmployeeGraphQL[];
|
|
370
|
-
} => useGetReduxCatalog<EmployeeGraphQL>("employeesByCurrentAgency", config);
|
|
371
|
-
|
|
372
|
-
export const useGetShipmentsToMyAgency = (
|
|
373
|
-
config?: ReduxParamsConfig
|
|
374
|
-
): {
|
|
375
|
-
loading: boolean;
|
|
376
|
-
data: ShipmentGraphQL[];
|
|
377
|
-
} => useGetReduxCatalog<ShipmentGraphQL>("shipmentsToMyAgency", config);
|
|
378
|
-
|
|
379
|
-
export const useGetInvoicesByLab = (
|
|
380
|
-
config?: ReduxParamsConfig
|
|
381
|
-
): {
|
|
382
|
-
loading: boolean;
|
|
383
|
-
data: InvoiceGraphQL[];
|
|
384
|
-
} => useGetReduxCatalog<InvoiceGraphQL>("invoicesByLab", config);
|
|
385
|
-
|
|
386
|
-
export const useGetTiposDeMuestra = (
|
|
387
|
-
config?: ReduxParamsConfig
|
|
388
|
-
): {
|
|
389
|
-
loading: boolean;
|
|
390
|
-
data: WebAppRowGraphQL<TipoMuestra>[];
|
|
391
|
-
} =>
|
|
392
|
-
useGetReduxCatalog<WebAppRowGraphQL<TipoMuestra>>("tiposDeMuestra", config);
|
|
393
|
-
|
|
394
|
-
export const useGetMotivosDeRechazo = (
|
|
395
|
-
config?: ReduxParamsConfig
|
|
396
|
-
): {
|
|
397
|
-
loading: boolean;
|
|
398
|
-
data: WebAppRowGraphQL<MotivoRechazo>[];
|
|
399
|
-
} =>
|
|
400
|
-
useGetReduxCatalog<WebAppRowGraphQL<MotivoRechazo>>("motivosRechazo", config);
|
|
401
|
-
|
|
402
|
-
export const useGetBitacoraRechazoMasivo = (
|
|
403
|
-
config?: ReduxParamsConfig
|
|
404
|
-
): {
|
|
405
|
-
loading: boolean;
|
|
406
|
-
data: WebAppRowGraphQL<BitacoraPOMassive>[];
|
|
407
|
-
} =>
|
|
408
|
-
useGetReduxCatalog<WebAppRowGraphQL<BitacoraPOMassive>>(
|
|
409
|
-
"bitacoraRechazoMasivo",
|
|
410
|
-
config
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
export const useGetInvoiceForms = (
|
|
414
|
-
config?: ReduxParamsConfig
|
|
415
|
-
): {
|
|
416
|
-
loading: boolean;
|
|
417
|
-
data: FormGraphQL[];
|
|
418
|
-
} => {
|
|
419
|
-
const data = useGetReduxCatalog<FormGraphQL>("invoiceForms", config);
|
|
420
|
-
|
|
421
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
422
|
-
const groupedByVersion = (data.data || []).reduce((acc, record) => {
|
|
423
|
-
const zid = record.zid;
|
|
424
|
-
|
|
425
|
-
if (!acc[zid]) {
|
|
426
|
-
acc[zid] = record;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
return acc;
|
|
430
|
-
}, {} as { [key: string]: FormGraphQL });
|
|
431
|
-
|
|
432
|
-
const latestVersionRecords = Object.values(groupedByVersion);
|
|
433
|
-
|
|
434
|
-
return {
|
|
435
|
-
loading: data.loading,
|
|
436
|
-
data: latestVersionRecords.filter((x) => x.active),
|
|
437
|
-
};
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
export const useGetCaseForms = (
|
|
441
|
-
config?: ReduxParamsConfig
|
|
442
|
-
): {
|
|
443
|
-
loading: boolean;
|
|
444
|
-
data: FormGraphQL[];
|
|
445
|
-
} => {
|
|
446
|
-
const data = useGetReduxCatalog<FormGraphQL>("caseForms", config);
|
|
447
|
-
|
|
448
|
-
// Filtrar los registros para obtener sólo el primero de cada zid.
|
|
449
|
-
const firstRecordByZid = (data.data || []).reduce((acc, record) => {
|
|
450
|
-
const zid = record.zid;
|
|
451
|
-
|
|
452
|
-
if (!acc[zid]) {
|
|
453
|
-
acc[zid] = record;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return acc;
|
|
457
|
-
}, {} as { [key: string]: FormGraphQL });
|
|
458
|
-
|
|
459
|
-
const firstRecords = Object.values(firstRecordByZid);
|
|
460
|
-
|
|
461
|
-
return {
|
|
462
|
-
loading: data.loading,
|
|
463
|
-
data: firstRecords.filter((x) => x.active),
|
|
464
|
-
};
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
export const useGetInvoiceFormSubmissionsByAgencyId = (
|
|
468
|
-
agency_id: number | string
|
|
469
|
-
): {
|
|
470
|
-
loading: boolean;
|
|
471
|
-
data: SubmissionInvoicesGraphQL[];
|
|
472
|
-
} => {
|
|
473
|
-
const data = useApiCatalog<SubmissionInvoicesGraphQL>(
|
|
474
|
-
"invoiceFormSubmissionsByAgencyId",
|
|
475
|
-
{
|
|
476
|
-
agency_id: `${agency_id}`,
|
|
477
|
-
}
|
|
478
|
-
);
|
|
479
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
480
|
-
const groupedByVersion = (data.data || []).reduce((acc, record) => {
|
|
481
|
-
const zid = record.settings_form_submission.zid;
|
|
482
|
-
|
|
483
|
-
if (!acc[zid]) {
|
|
484
|
-
acc[zid] = record;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
return acc;
|
|
488
|
-
}, {} as { [key: string]: SubmissionInvoicesGraphQL });
|
|
489
|
-
|
|
490
|
-
const latestVersionRecords = Object.values(groupedByVersion);
|
|
491
|
-
|
|
492
|
-
return {
|
|
493
|
-
loading: data.loading,
|
|
494
|
-
data: latestVersionRecords,
|
|
495
|
-
};
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
export const useGetMyCaseFormSubmissions = (
|
|
499
|
-
config?: ReduxParamsConfig
|
|
500
|
-
): {
|
|
501
|
-
loading: boolean;
|
|
502
|
-
data: SubmissionCasesGraphQL[];
|
|
503
|
-
} => {
|
|
504
|
-
const data = useGetReduxCatalog<SubmissionCasesGraphQL>(
|
|
505
|
-
"myCaseFormSubmissions",
|
|
506
|
-
config
|
|
507
|
-
);
|
|
508
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
509
|
-
const groupedByVersion = (data.data || []).reduce((acc, record) => {
|
|
510
|
-
const zid = record.settings_form_submission.zid;
|
|
511
|
-
|
|
512
|
-
if (!acc[zid]) {
|
|
513
|
-
acc[zid] = record;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return acc;
|
|
517
|
-
}, {} as { [key: string]: SubmissionCasesGraphQL });
|
|
518
|
-
|
|
519
|
-
const latestVersionRecords = Object.values(groupedByVersion);
|
|
520
|
-
|
|
521
|
-
return {
|
|
522
|
-
loading: data.loading,
|
|
523
|
-
data: latestVersionRecords,
|
|
524
|
-
};
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
export const useGetInvoiceFormSubmissionsByInvoiceId = (
|
|
528
|
-
invoice_id: number | string
|
|
529
|
-
): {
|
|
530
|
-
loading: boolean;
|
|
531
|
-
data: SubmissionInvoicesGraphQL[];
|
|
532
|
-
} => {
|
|
533
|
-
const data = useApiCatalog<SubmissionInvoicesGraphQL>(
|
|
534
|
-
"invoiceFormSubmissionsByInvoiceId",
|
|
535
|
-
{
|
|
536
|
-
invoice_id: `${invoice_id}`,
|
|
537
|
-
}
|
|
538
|
-
);
|
|
539
|
-
|
|
540
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
541
|
-
const groupedByVersion = (data.data || []).reduce((acc, record) => {
|
|
542
|
-
const zid = record.settings_form_submission.zid;
|
|
543
|
-
|
|
544
|
-
if (!acc[zid]) {
|
|
545
|
-
acc[zid] = record;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
return acc;
|
|
549
|
-
}, {} as { [key: string]: SubmissionInvoicesGraphQL });
|
|
550
|
-
|
|
551
|
-
const latestVersionRecords = Object.values(groupedByVersion);
|
|
552
|
-
|
|
553
|
-
return {
|
|
554
|
-
loading: data.loading,
|
|
555
|
-
data: latestVersionRecords,
|
|
556
|
-
};
|
|
557
|
-
};
|
package/src/components/Alert.tsx
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect } from "react";
|
|
2
|
-
import { ExitSvg } from "@zauru-sdk/icons";
|
|
3
|
-
import { createRoot } from "react-dom/client";
|
|
4
|
-
import { AnimatePresence, motion } from "framer-motion";
|
|
5
|
-
|
|
6
|
-
export type AlertType = "success" | "error" | "info" | "warning";
|
|
7
|
-
|
|
8
|
-
export type AlertProps = {
|
|
9
|
-
type: AlertType;
|
|
10
|
-
title: string;
|
|
11
|
-
description: string;
|
|
12
|
-
onClose?: () => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const Alert: React.FC<AlertProps> = ({ type, title, description, onClose }) => {
|
|
16
|
-
const [, setLifetime] = useState(4000);
|
|
17
|
-
const [progress, setProgress] = useState(0);
|
|
18
|
-
const intervalRef = useRef<any>(null);
|
|
19
|
-
|
|
20
|
-
const getColor = () => {
|
|
21
|
-
switch (type) {
|
|
22
|
-
case "success":
|
|
23
|
-
return "bg-green-100 text-green-800";
|
|
24
|
-
case "error":
|
|
25
|
-
return "bg-red-100 text-red-800";
|
|
26
|
-
case "info":
|
|
27
|
-
return "bg-blue-100 text-blue-800";
|
|
28
|
-
case "warning":
|
|
29
|
-
return "bg-yellow-100 text-yellow-800";
|
|
30
|
-
default:
|
|
31
|
-
return "bg-gray-100 text-gray-800";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
const startTimer = () => {
|
|
37
|
-
intervalRef.current = setInterval(() => {
|
|
38
|
-
setLifetime((lifetime) => {
|
|
39
|
-
if (lifetime <= 0) {
|
|
40
|
-
onClose && onClose();
|
|
41
|
-
clearInterval(intervalRef.current);
|
|
42
|
-
return 0;
|
|
43
|
-
} else {
|
|
44
|
-
setProgress((4000 - lifetime) / 4000);
|
|
45
|
-
return lifetime - 50;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}, 50);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const pauseTimer = () => {
|
|
52
|
-
clearInterval(intervalRef.current);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
startTimer();
|
|
56
|
-
return () => {
|
|
57
|
-
pauseTimer();
|
|
58
|
-
};
|
|
59
|
-
}, [onClose]);
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<motion.div
|
|
63
|
-
initial={{ y: -50, opacity: 0 }}
|
|
64
|
-
animate={{ y: 0, opacity: 1 }}
|
|
65
|
-
exit={{ y: -50, opacity: 0 }}
|
|
66
|
-
className={`fixed top-0 right-0 w-80 mt-10 mr-10 rounded-md shadow-lg ${getColor()} p-4 transition-transform duration-300`}
|
|
67
|
-
style={{
|
|
68
|
-
zIndex: 1000,
|
|
69
|
-
transform: `translateY(calc(var(--alert-offset, 0)))`,
|
|
70
|
-
}}
|
|
71
|
-
onMouseEnter={() => clearInterval(intervalRef.current)}
|
|
72
|
-
onMouseLeave={() => {
|
|
73
|
-
intervalRef.current = setInterval(() => {
|
|
74
|
-
setLifetime((lifetime) => {
|
|
75
|
-
if (lifetime <= 0) {
|
|
76
|
-
onClose && onClose();
|
|
77
|
-
clearInterval(intervalRef.current);
|
|
78
|
-
return 0;
|
|
79
|
-
} else {
|
|
80
|
-
setProgress((4000 - lifetime) / 4000);
|
|
81
|
-
return lifetime - 50;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}, 50);
|
|
85
|
-
}}
|
|
86
|
-
>
|
|
87
|
-
<div className="flex items-center justify-between">
|
|
88
|
-
<h3 className="font-semibold">{title}</h3>
|
|
89
|
-
<button
|
|
90
|
-
className="text-gray-400 hover:text-gray-500 focus:outline-none focus:text-gray-500 transition duration-150 ease-in-out"
|
|
91
|
-
onClick={() => {
|
|
92
|
-
setLifetime(0);
|
|
93
|
-
onClose && onClose();
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
<ExitSvg />
|
|
97
|
-
</button>
|
|
98
|
-
</div>
|
|
99
|
-
<div className="mt-2">
|
|
100
|
-
<p className="text-sm overflow-wrap break-words">{description}</p>
|
|
101
|
-
</div>
|
|
102
|
-
<div className="relative h-1 mt-4 bg-gray-200 rounded">
|
|
103
|
-
<div
|
|
104
|
-
className={`absolute left-0 top-0 h-full ${getColor()} rounded`}
|
|
105
|
-
style={{ width: `${progress * 100}%` }}
|
|
106
|
-
></div>
|
|
107
|
-
</div>
|
|
108
|
-
</motion.div>
|
|
109
|
-
);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
let activeAlerts: HTMLElement[] = [];
|
|
113
|
-
|
|
114
|
-
export const showAlert = (alertProps: AlertProps) => {
|
|
115
|
-
if (typeof document === "undefined") {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const container = document.createElement("div");
|
|
119
|
-
document.body.appendChild(container);
|
|
120
|
-
|
|
121
|
-
const onClose = () => {
|
|
122
|
-
root.unmount();
|
|
123
|
-
container.remove();
|
|
124
|
-
activeAlerts = activeAlerts.filter((alert) => alert !== container);
|
|
125
|
-
updateAlertOffsets();
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const asyncOnClose = () => {
|
|
129
|
-
setTimeout(() => {
|
|
130
|
-
onClose();
|
|
131
|
-
}, 0);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
activeAlerts.push(container);
|
|
135
|
-
updateAlertOffsets();
|
|
136
|
-
|
|
137
|
-
const root = createRoot(container);
|
|
138
|
-
root.render(
|
|
139
|
-
<AnimatePresence>
|
|
140
|
-
<Alert {...alertProps} onClose={asyncOnClose} />
|
|
141
|
-
</AnimatePresence>
|
|
142
|
-
);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const updateAlertOffsets = () => {
|
|
146
|
-
activeAlerts.forEach((alertContainer, index) => {
|
|
147
|
-
alertContainer.style.setProperty("--alert-offset", `${index * 100}px`);
|
|
148
|
-
});
|
|
149
|
-
};
|
package/src/components/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Alert.js";
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./components/index.js";
|
|
2
|
-
|
|
3
|
-
export * from "./alerts.js";
|
|
4
|
-
export * from "./automaticNumbers.js";
|
|
5
|
-
export * from "./catalogs.js";
|
|
6
|
-
export * from "./onlineStatus.js";
|
|
7
|
-
export * from "./profiles.js";
|
|
8
|
-
export * from "./receptions.js";
|
|
9
|
-
export * from "./session.js";
|
|
10
|
-
export * from "./templates.js";
|
|
11
|
-
export * from "./useWindowDimensions.js";
|