@zauru-sdk/hooks 1.0.13

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/.eslintrc.cjs ADDED
@@ -0,0 +1,83 @@
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
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [1.0.13](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.12...v1.0.13) (2024-03-21)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/hooks
package/LICENCE.md ADDED
@@ -0,0 +1,11 @@
1
+ # Released under MIT License
2
+
3
+ Copyright (c) 2013 Mark Otto.
4
+
5
+ Copyright (c) 2017 Andrew Fong.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ import type { FetcherWithComponents } from "@remix-run/react";
2
+ export declare const useValidateNotifications: (source: {
3
+ fetcher?: FetcherWithComponents<any>;
4
+ actionData?: any;
5
+ loaderData?: any;
6
+ }) => null;
package/dist/alerts.js ADDED
@@ -0,0 +1,33 @@
1
+ import { useEffect } from "react";
2
+ import { showAlert } from "src";
3
+ export const useValidateNotifications = (source) => {
4
+ const { actionData, fetcher, loaderData } = source;
5
+ useEffect(() => {
6
+ if (loaderData?.title) {
7
+ showAlert({
8
+ description: loaderData?.description?.toString() ?? "",
9
+ title: loaderData?.title,
10
+ type: loaderData?.type,
11
+ });
12
+ }
13
+ }, [loaderData]);
14
+ useEffect(() => {
15
+ if (fetcher?.data?.title) {
16
+ showAlert({
17
+ description: fetcher.data?.description,
18
+ title: fetcher.data?.title,
19
+ type: fetcher.data?.type,
20
+ });
21
+ }
22
+ }, [fetcher?.data]);
23
+ useEffect(() => {
24
+ if (actionData?.title) {
25
+ showAlert({
26
+ description: actionData?.description ?? "",
27
+ title: actionData?.title,
28
+ type: actionData?.type,
29
+ });
30
+ }
31
+ }, [actionData]);
32
+ return null;
33
+ };
@@ -0,0 +1,7 @@
1
+ import { AUTOMATIC_NUMBER_NAMES } from "@zauru-sdk/redux";
2
+ type ProfileType<T> = {
3
+ data: T;
4
+ loading: boolean;
5
+ };
6
+ export declare const useGetAutomaticNumber: <T>(AUTOMATIC_NUMBER_NAME: AUTOMATIC_NUMBER_NAMES) => ProfileType<T>;
7
+ export {};
@@ -0,0 +1,53 @@
1
+ import { useFetcher } from "@remix-run/react";
2
+ import { automaticNumberFetchStart, automaticNumberFetchSuccess, useAppDispatch, useAppSelector, } from "@zauru-sdk/redux";
3
+ import { useEffect, useState } from "react";
4
+ import { showAlert } from "src";
5
+ export const useGetAutomaticNumber = (AUTOMATIC_NUMBER_NAME) => {
6
+ const fetcher = useFetcher();
7
+ const dispatch = useAppDispatch();
8
+ const objectData = useAppSelector((state) => state.automaticNumbers[AUTOMATIC_NUMBER_NAME]);
9
+ const [data, setData] = useState({
10
+ data: Object.keys(objectData?.data).length
11
+ ? objectData?.data
12
+ : {},
13
+ loading: objectData.loading,
14
+ });
15
+ useEffect(() => {
16
+ if (fetcher.data?.title) {
17
+ showAlert({
18
+ description: fetcher.data?.description,
19
+ title: fetcher.data?.title,
20
+ type: fetcher.data?.type,
21
+ });
22
+ }
23
+ }, [fetcher.data]);
24
+ useEffect(() => {
25
+ if (fetcher.state === "idle" && fetcher.data != null) {
26
+ const receivedData = fetcher.data;
27
+ if (receivedData) {
28
+ setData({ data: receivedData[AUTOMATIC_NUMBER_NAME], loading: false });
29
+ dispatch(automaticNumberFetchSuccess({
30
+ name: AUTOMATIC_NUMBER_NAME,
31
+ data: receivedData[AUTOMATIC_NUMBER_NAME],
32
+ }));
33
+ }
34
+ }
35
+ }, [fetcher, dispatch, AUTOMATIC_NUMBER_NAME]);
36
+ useEffect(() => {
37
+ if (Object.keys(objectData?.data).length <= 0) {
38
+ try {
39
+ setData({ ...data, loading: true });
40
+ dispatch(automaticNumberFetchStart(AUTOMATIC_NUMBER_NAME));
41
+ fetcher.load(`/api/automaticNumbers?object=${AUTOMATIC_NUMBER_NAME}`);
42
+ }
43
+ catch (ex) {
44
+ showAlert({
45
+ type: "error",
46
+ title: `Ocurrió un error al cargar el object de automatic numbers: ${AUTOMATIC_NUMBER_NAME}.`,
47
+ description: "Error: " + ex,
48
+ });
49
+ }
50
+ }
51
+ }, []);
52
+ return data;
53
+ };
@@ -0,0 +1,144 @@
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 } from "@zauru-sdk/types";
2
+ import { ReduxParamsConfig } from "@zauru-sdk/redux";
3
+ /**
4
+ *
5
+ * ======================= HOOKS
6
+ */
7
+ export declare const useGetItems: (config?: ReduxParamsConfig) => {
8
+ loading: boolean;
9
+ data: ItemGraphQL[];
10
+ };
11
+ export declare const useGetItemsByReception: (config?: ReduxParamsConfig) => {
12
+ loading: boolean;
13
+ data: ItemGraphQL[];
14
+ };
15
+ export declare const useGetItemsByLab: (config?: ReduxParamsConfig) => {
16
+ loading: boolean;
17
+ data: ItemGraphQL[];
18
+ };
19
+ export declare const useGetMyAgencyLotStocks: (config?: ReduxParamsConfig) => {
20
+ loading: boolean;
21
+ data: LotStockGraphQL[];
22
+ };
23
+ export declare const useGetItemServicesByLab: (config?: ReduxParamsConfig) => {
24
+ loading: boolean;
25
+ data: ItemGraphQL[];
26
+ };
27
+ export declare const useGetItemCategoriesForLab: (config?: ReduxParamsConfig) => {
28
+ loading: boolean;
29
+ data: ItemCategoryGraphQL[];
30
+ };
31
+ export declare const useGetBookings: (config?: ReduxParamsConfig) => {
32
+ loading: boolean;
33
+ data: ShipmentGraphQL[];
34
+ };
35
+ export declare const useGetTemplates: (config?: ReduxParamsConfig) => {
36
+ loading: boolean;
37
+ data: WebAppRowGraphQL<Template>[];
38
+ };
39
+ export declare const useGetPayeeCategoriesLabPrices: (config?: {
40
+ withPriceListIdNull: boolean;
41
+ }) => {
42
+ loading: boolean;
43
+ data: PayeeCategoryGraphQL[];
44
+ };
45
+ export declare const useGetBundlesRecipForLab: (config?: ReduxParamsConfig) => {
46
+ loading: boolean;
47
+ data: BundleGraphQL[];
48
+ };
49
+ export declare const useGetBundlesForLab: (config?: ReduxParamsConfig) => {
50
+ loading: boolean;
51
+ data: BundleGraphQL[];
52
+ };
53
+ export declare const useGetCurrencies: (config?: ReduxParamsConfig) => {
54
+ loading: boolean;
55
+ data: CurrencyGraphQL[];
56
+ };
57
+ export declare const useGetReceptionTypes: (config?: ReduxParamsConfig) => {
58
+ loading: boolean;
59
+ data: WebAppRowGraphQL<ReceptionType>[];
60
+ };
61
+ export declare const useGetProviders: (config?: ReduxParamsConfig) => {
62
+ loading: boolean;
63
+ data: PayeeGraphQL[];
64
+ };
65
+ export declare const useGetMyCases: (config?: ReduxParamsConfig) => {
66
+ loading: boolean;
67
+ data: CaseGraphQL[];
68
+ };
69
+ export declare const useGetProviderCategories: (config?: ReduxParamsConfig) => {
70
+ loading: boolean;
71
+ data: PayeeCategoryGraphQL[];
72
+ };
73
+ export declare const useGetClientCategories: (config?: ReduxParamsConfig) => {
74
+ loading: boolean;
75
+ data: PayeeCategoryGraphQL[];
76
+ };
77
+ export declare const useGetPayees: (config?: ReduxParamsConfig) => {
78
+ loading: boolean;
79
+ data: PayeeGraphQL[];
80
+ };
81
+ export declare const useGetPayeesForLab: (config?: ReduxParamsConfig) => {
82
+ loading: boolean;
83
+ data: PayeeGraphQL[];
84
+ };
85
+ export declare const useGetAgencies: (config?: ReduxParamsConfig) => {
86
+ loading: boolean;
87
+ data: AgencyGraphQL[];
88
+ };
89
+ export declare const useGetSuggestedPrices: (config?: ReduxParamsConfig) => {
90
+ loading: boolean;
91
+ data: SuggestedPriceGraphQL[];
92
+ };
93
+ export declare const useGetPaymentTerms: (config?: ReduxParamsConfig) => {
94
+ loading: boolean;
95
+ data: PaymentTermGraphQL[];
96
+ };
97
+ export declare const useGetEmployeesByLab: (config?: ReduxParamsConfig) => {
98
+ loading: boolean;
99
+ data: EmployeeGraphQL[];
100
+ };
101
+ export declare const useGetEmployeesByCurrentAgency: (config?: ReduxParamsConfig) => {
102
+ loading: boolean;
103
+ data: EmployeeGraphQL[];
104
+ };
105
+ export declare const useGetShipmentsToMyAgency: (config?: ReduxParamsConfig) => {
106
+ loading: boolean;
107
+ data: ShipmentGraphQL[];
108
+ };
109
+ export declare const useGetInvoicesByLab: (config?: ReduxParamsConfig) => {
110
+ loading: boolean;
111
+ data: InvoiceGraphQL[];
112
+ };
113
+ export declare const useGetTiposDeMuestra: (config?: ReduxParamsConfig) => {
114
+ loading: boolean;
115
+ data: WebAppRowGraphQL<TipoMuestra>[];
116
+ };
117
+ export declare const useGetMotivosDeRechazo: (config?: ReduxParamsConfig) => {
118
+ loading: boolean;
119
+ data: WebAppRowGraphQL<MotivoRechazo>[];
120
+ };
121
+ export declare const useGetBitacoraRechazoMasivo: (config?: ReduxParamsConfig) => {
122
+ loading: boolean;
123
+ data: WebAppRowGraphQL<BitacoraPOMassive>[];
124
+ };
125
+ export declare const useGetInvoiceForms: (config?: ReduxParamsConfig) => {
126
+ loading: boolean;
127
+ data: FormGraphQL[];
128
+ };
129
+ export declare const useGetCaseForms: (config?: ReduxParamsConfig) => {
130
+ loading: boolean;
131
+ data: FormGraphQL[];
132
+ };
133
+ export declare const useGetInvoiceFormSubmissionsByAgencyId: (agency_id: number | string) => {
134
+ loading: boolean;
135
+ data: SubmissionInvoicesGraphQL[];
136
+ };
137
+ export declare const useGetMyCaseFormSubmissions: (config?: ReduxParamsConfig) => {
138
+ loading: boolean;
139
+ data: SubmissionCasesGraphQL[];
140
+ };
141
+ export declare const useGetInvoiceFormSubmissionsByInvoiceId: (invoice_id: number | string) => {
142
+ loading: boolean;
143
+ data: SubmissionInvoicesGraphQL[];
144
+ };
@@ -0,0 +1,230 @@
1
+ import { useFetcher } from "@remix-run/react";
2
+ import { useEffect, useState } from "react";
3
+ import { showAlert } from "src";
4
+ import { catalogsFetchStart, catalogsFetchSuccess, useAppDispatch, useAppSelector, } from "@zauru-sdk/redux";
5
+ const useApiCatalog = (CATALOG_NAME, otherParams) => {
6
+ const fetcher = useFetcher();
7
+ const [data, setData] = useState({
8
+ data: [],
9
+ loading: true,
10
+ });
11
+ useEffect(() => {
12
+ if (fetcher.data?.title) {
13
+ showAlert({
14
+ description: fetcher.data?.description?.toString(),
15
+ title: fetcher.data?.title?.toString(),
16
+ type: fetcher.data?.type?.toString(),
17
+ });
18
+ }
19
+ }, [fetcher.data]);
20
+ useEffect(() => {
21
+ if (fetcher.state === "idle" && fetcher.data != null) {
22
+ const receivedData = fetcher.data;
23
+ if (receivedData) {
24
+ setData({ data: receivedData[CATALOG_NAME], loading: false });
25
+ }
26
+ }
27
+ }, [fetcher, CATALOG_NAME]);
28
+ useEffect(() => {
29
+ try {
30
+ setData({ ...data, loading: true });
31
+ // Convert otherParams to query string
32
+ const paramsString = otherParams
33
+ ? Object.entries(otherParams)
34
+ .map(([key, value]) => `${key}=${value}`)
35
+ .join("&")
36
+ : "";
37
+ const url = `/api/catalogs?catalog=${CATALOG_NAME}${paramsString ? `&${paramsString}` : ""}`;
38
+ fetcher.load(url);
39
+ }
40
+ catch (ex) {
41
+ showAlert({
42
+ type: "error",
43
+ title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
44
+ description: "Error: " + ex,
45
+ });
46
+ }
47
+ }, []);
48
+ return data;
49
+ };
50
+ const useGetReduxCatalog = (CATALOG_NAME, { online = false, wheres = [], otherParams } = {}) => {
51
+ const fetcher = useFetcher();
52
+ const dispatch = useAppDispatch();
53
+ const catalogData = useAppSelector((state) => state.catalogs[CATALOG_NAME]);
54
+ const [data, setData] = useState({
55
+ data: catalogData?.data?.length ? catalogData.data : [],
56
+ loading: catalogData.loading,
57
+ });
58
+ useEffect(() => {
59
+ if (fetcher.data?.description) {
60
+ showAlert({
61
+ description: fetcher.data?.description?.toString(),
62
+ title: fetcher.data?.title?.toString(),
63
+ type: fetcher.data?.type?.toString(),
64
+ });
65
+ }
66
+ }, [fetcher.data]);
67
+ useEffect(() => {
68
+ if (fetcher.state === "idle" && fetcher.data != null) {
69
+ const receivedData = fetcher.data;
70
+ if (receivedData) {
71
+ setData({ data: receivedData[CATALOG_NAME], loading: false });
72
+ dispatch(catalogsFetchSuccess({
73
+ name: CATALOG_NAME,
74
+ data: receivedData[CATALOG_NAME],
75
+ }));
76
+ }
77
+ }
78
+ }, [fetcher, dispatch, CATALOG_NAME]);
79
+ useEffect(() => {
80
+ if (catalogData?.data?.length <= 0 || catalogData?.reFetch || online) {
81
+ try {
82
+ setData({ ...data, loading: true });
83
+ dispatch(catalogsFetchStart(CATALOG_NAME));
84
+ // Convierte cada elemento del array a una cadena codificada para URL
85
+ const encodedWheres = wheres.map((where) => encodeURIComponent(where));
86
+ // Une los elementos codificados con '&'
87
+ const wheresQueryParam = encodedWheres.join("&");
88
+ // Convert otherParams to query string
89
+ const paramsString = otherParams
90
+ ? Object.entries(otherParams)
91
+ .map(([key, value]) => `${key}=${value}`)
92
+ .join("&")
93
+ : "";
94
+ fetcher.load(`/api/catalogs?catalog=${CATALOG_NAME}&wheres=${wheresQueryParam}${paramsString ? `&${paramsString}` : ""}`);
95
+ }
96
+ catch (ex) {
97
+ showAlert({
98
+ type: "error",
99
+ title: `Ocurrió un error al cargar el catálogo: ${CATALOG_NAME}.`,
100
+ description: "Error: " + ex,
101
+ });
102
+ }
103
+ }
104
+ }, []);
105
+ return data;
106
+ };
107
+ /**
108
+ *
109
+ * ======================= HOOKS
110
+ */
111
+ export const useGetItems = (config) => useGetReduxCatalog("items", config);
112
+ export const useGetItemsByReception = (config) => useGetReduxCatalog("itemsByReception", config);
113
+ export const useGetItemsByLab = (config) => useGetReduxCatalog("itemsByLab", config);
114
+ export const useGetMyAgencyLotStocks = (config) => useGetReduxCatalog("myAgencyLotStocks", config);
115
+ export const useGetItemServicesByLab = (config) => useGetReduxCatalog("itemServicesByLab", config);
116
+ export const useGetItemCategoriesForLab = (config) => useGetReduxCatalog("itemCategoriesForLab", config);
117
+ export const useGetBookings = (config) => useGetReduxCatalog("bookings", config);
118
+ export const useGetTemplates = (config) => useGetReduxCatalog("templates", config);
119
+ export const useGetPayeeCategoriesLabPrices = (config = { withPriceListIdNull: false }) => {
120
+ const data = useGetReduxCatalog("payeeCategoriesLabPrices");
121
+ let tempData = data.data;
122
+ if (!config.withPriceListIdNull) {
123
+ tempData = data.data.filter((x) => x.price_list_id);
124
+ }
125
+ return { ...data, data: tempData };
126
+ };
127
+ export const useGetBundlesRecipForLab = (config) => useGetReduxCatalog("bundlesRecipForLab", config);
128
+ export const useGetBundlesForLab = (config) => useGetReduxCatalog("bundlesForLab", config);
129
+ export const useGetCurrencies = (config) => useGetReduxCatalog("currencies", config);
130
+ export const useGetReceptionTypes = (config) => useGetReduxCatalog("receptionTypes", config);
131
+ export const useGetProviders = (config) => useGetReduxCatalog("providers", config);
132
+ export const useGetMyCases = (config) => useGetReduxCatalog("myCases", config);
133
+ export const useGetProviderCategories = (config) => useGetReduxCatalog("providerCategories", config);
134
+ export const useGetClientCategories = (config) => useGetReduxCatalog("clientCategories", config);
135
+ export const useGetPayees = (config) => useGetReduxCatalog("payees", config);
136
+ export const useGetPayeesForLab = (config) => useGetReduxCatalog("payeesForLab", config);
137
+ export const useGetAgencies = (config) => useGetReduxCatalog("agencies", config);
138
+ export const useGetSuggestedPrices = (config) => useGetReduxCatalog("suggestedPrices", config);
139
+ export const useGetPaymentTerms = (config) => useGetReduxCatalog("paymentTerms", config);
140
+ export const useGetEmployeesByLab = (config) => useGetReduxCatalog("employeesByLab", config);
141
+ export const useGetEmployeesByCurrentAgency = (config) => useGetReduxCatalog("employeesByCurrentAgency", config);
142
+ export const useGetShipmentsToMyAgency = (config) => useGetReduxCatalog("shipmentsToMyAgency", config);
143
+ export const useGetInvoicesByLab = (config) => useGetReduxCatalog("invoicesByLab", config);
144
+ export const useGetTiposDeMuestra = (config) => useGetReduxCatalog("tiposDeMuestra", config);
145
+ export const useGetMotivosDeRechazo = (config) => useGetReduxCatalog("motivosRechazo", config);
146
+ export const useGetBitacoraRechazoMasivo = (config) => useGetReduxCatalog("bitacoraRechazoMasivo", config);
147
+ export const useGetInvoiceForms = (config) => {
148
+ const data = useGetReduxCatalog("invoiceForms", config);
149
+ // Filtrar los registros para obtener sólo los de la versión más alta.
150
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
151
+ const zid = record.zid;
152
+ if (!acc[zid]) {
153
+ acc[zid] = record;
154
+ }
155
+ return acc;
156
+ }, {});
157
+ const latestVersionRecords = Object.values(groupedByVersion);
158
+ return {
159
+ loading: data.loading,
160
+ data: latestVersionRecords.filter((x) => x.active),
161
+ };
162
+ };
163
+ export const useGetCaseForms = (config) => {
164
+ const data = useGetReduxCatalog("caseForms", config);
165
+ // Filtrar los registros para obtener sólo el primero de cada zid.
166
+ const firstRecordByZid = (data.data || []).reduce((acc, record) => {
167
+ const zid = record.zid;
168
+ if (!acc[zid]) {
169
+ acc[zid] = record;
170
+ }
171
+ return acc;
172
+ }, {});
173
+ const firstRecords = Object.values(firstRecordByZid);
174
+ return {
175
+ loading: data.loading,
176
+ data: firstRecords.filter((x) => x.active),
177
+ };
178
+ };
179
+ export const useGetInvoiceFormSubmissionsByAgencyId = (agency_id) => {
180
+ const data = useApiCatalog("invoiceFormSubmissionsByAgencyId", {
181
+ agency_id: `${agency_id}`,
182
+ });
183
+ // Filtrar los registros para obtener sólo los de la versión más alta.
184
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
185
+ const zid = record.settings_form_submission.zid;
186
+ if (!acc[zid]) {
187
+ acc[zid] = record;
188
+ }
189
+ return acc;
190
+ }, {});
191
+ const latestVersionRecords = Object.values(groupedByVersion);
192
+ return {
193
+ loading: data.loading,
194
+ data: latestVersionRecords,
195
+ };
196
+ };
197
+ export const useGetMyCaseFormSubmissions = (config) => {
198
+ const data = useGetReduxCatalog("myCaseFormSubmissions", config);
199
+ // Filtrar los registros para obtener sólo los de la versión más alta.
200
+ const groupedByVersion = (data.data || []).reduce((acc, record) => {
201
+ const zid = record.settings_form_submission.zid;
202
+ if (!acc[zid]) {
203
+ acc[zid] = record;
204
+ }
205
+ return acc;
206
+ }, {});
207
+ const latestVersionRecords = Object.values(groupedByVersion);
208
+ return {
209
+ loading: data.loading,
210
+ data: latestVersionRecords,
211
+ };
212
+ };
213
+ export const useGetInvoiceFormSubmissionsByInvoiceId = (invoice_id) => {
214
+ const data = useApiCatalog("invoiceFormSubmissionsByInvoiceId", {
215
+ invoice_id: `${invoice_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
+ };
@@ -0,0 +1,8 @@
1
+ export type AlertType = "success" | "error" | "info" | "warning";
2
+ export type AlertProps = {
3
+ type: AlertType;
4
+ title: string;
5
+ description: string;
6
+ onClose?: () => void;
7
+ };
8
+ export declare const showAlert: (alertProps: AlertProps) => void;