@arquimedes.co/eureka-forms 2.0.120 → 2.0.121

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.
@@ -0,0 +1,16 @@
1
+ import ErkValueTypes from '../constants/ErkValueTypes';
2
+ import { EurekaDraft } from './Draft/Draft';
3
+ export type ErkValue = StepErkValue | DraftErkValue | BooleanErkValue;
4
+ interface StepErkValue {
5
+ type: ErkValueTypes.STEP;
6
+ idStep: string;
7
+ }
8
+ interface DraftErkValue {
9
+ type: ErkValueTypes.DRAFT;
10
+ value: EurekaDraft;
11
+ }
12
+ interface BooleanErkValue {
13
+ type: ErkValueTypes.BOOLEAN;
14
+ value: boolean;
15
+ }
16
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ import FormStepTypes, { ClassifierOptionTypes, OptionTypes, RatingTypes, MapperS
2
2
  import IconTypes from '../constants/IconTypes';
3
3
  import { Condition } from './Condition';
4
4
  import { EurekaDraft } from './Draft/Draft';
5
+ import { ErkValue } from './ErkValue';
5
6
  import * as GSteps from './GenericFormSteps';
6
7
  import { Time } from './Time';
7
8
  export type FormStep = Title | TimePicker | Rating | CheckBox | TextArea | TextInput | DatePicker | FileUpload | Separator | FormSelector | ClassifierSelector | Collapsible | EntityValuePicker | ApiSelector | Mapper;
@@ -146,7 +147,7 @@ export interface ValueEntityValuePickerPath {
146
147
  type: EntityValueDataTypes.VALUE;
147
148
  idEntityValue: string | null;
148
149
  }
149
- export type EntityValuePickerFilter = StepEntityValuePickerFilter | ValueEntityValuePickerFilter | CurrentAgentEntityValuePickerFilter;
150
+ export type EntityValuePickerFilter = StepEntityValuePickerFilter | ValueEntityValuePickerFilter | CurrentAgentEntityValuePickerFilter | IntegrationEntityValuePickerFilter;
150
151
  export interface StepEntityValuePickerFilter {
151
152
  idProperty: string;
152
153
  type: EntityValueDataTypes.STEP;
@@ -163,6 +164,12 @@ export interface CurrentAgentEntityValuePickerFilter {
163
164
  idProperty: string;
164
165
  type: EntityValueDataTypes.CURRENT_AGENT;
165
166
  }
167
+ export interface IntegrationEntityValuePickerFilter {
168
+ idProperty: string;
169
+ type: EntityValueDataTypes.INTEGRATION;
170
+ idIntegration: string;
171
+ values?: Record<string, ErkValue>;
172
+ }
166
173
  export interface ApiSelector extends GSteps.GSmartSelect {
167
174
  type: FormStepTypes.API_SELECTOR;
168
175
  icon?: IconTypes;
@@ -65,13 +65,53 @@ import FormContext from '../../../Contexts/FormContext';
65
65
  import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
66
66
  import { evaluateCondition } from '../../StepFunctions';
67
67
  import { recursivelyCalcConditionSteps, selectDependencies, } from '../../StepHooks';
68
- import { useAppSelector } from '../../../hooks';
68
+ import { useApiSubscribe, useAppSelector } from '../../../hooks';
69
69
  import MaterialEntityValueDialog from './MaterialEntityValueDialog/MaterialEntityValueDialog';
70
+ import ErkValueTypes from '../../../constants/ErkValueTypes';
71
+ import { IntegrationsApi } from '../../../Services/IntegrationService';
72
+ import { IdFormContext } from '../../../App/App';
70
73
  function EntityValuePickerStep(_a) {
74
+ var _this = this;
71
75
  var _b, _c;
72
76
  var step = _a.step, editable = _a.editable;
77
+ var subscribe = useApiSubscribe();
73
78
  var form = useContext(FormContext);
79
+ var idForm = useContext(IdFormContext);
80
+ // const mapDraftEntities = useContext(CustomContext).mapDraftEntities;
74
81
  var _d = useState(), dialogs = _d[0], setDialogs = _d[1];
82
+ // const path = useMemo(
83
+ // () => [...step.stepPath, step.id].join('.'),
84
+ // [step.stepPath, step.id]
85
+ // );
86
+ // //TODO: Esto toca revisarlo, es un borrador.
87
+ // const mapDraft = useCallback(
88
+ // async (property: string): Promise<EurekaDraft | undefined> => {
89
+ // const state = await dispatch(getAppState({ idForm })).unwrap();
90
+ // const dependencies = selectDependencies(state, step.dependencies);
91
+ // return await subscribe(
92
+ // DraftApi.endpoints.mapDraft.initiate({
93
+ // idForm,
94
+ // property: `${path}.${property}`,
95
+ // dependencies,
96
+ // mapDraftEntities,
97
+ // })
98
+ // );
99
+ // },
100
+ // [subscribe, idForm, mapDraftEntities, path]
101
+ // );
102
+ var fetchFilterIntegration = useCallback(function (idIntegration, payload) { return __awaiter(_this, void 0, void 0, function () {
103
+ var _a;
104
+ return __generator(this, function (_b) {
105
+ switch (_b.label) {
106
+ case 0: return [4 /*yield*/, subscribe(IntegrationsApi.endpoints.fetchFilterIntegration.initiate({
107
+ idForm: idForm,
108
+ payload: payload,
109
+ idIntegration: idIntegration,
110
+ }))];
111
+ case 1: return [2 /*return*/, ((_a = (_b.sent())) !== null && _a !== void 0 ? _a : [])];
112
+ }
113
+ });
114
+ }); }, [subscribe, idForm]);
75
115
  var dialogsIdStepDeps = useMemo(function () {
76
116
  var ids = [];
77
117
  if (!step.dialogs)
@@ -96,7 +136,17 @@ function EntityValuePickerStep(_a) {
96
136
  : undefined;
97
137
  });
98
138
  }, []);
99
- return (_jsxs(React.Fragment, { children: [dialogs !== undefined && ((_b = form.entities) === null || _b === void 0 ? void 0 : _b[step.idEntity]) && (_jsx(MaterialEntityValueDialog, { type: dialogs.current.type, entity: (_c = form.entities) === null || _c === void 0 ? void 0 : _c[step.idEntity], entityValue: dialogs.value, message: dialogs.current.message, handleClose: handleCloseDialog })), _jsx(StepFillerContainer, __assign({ step: step }, { children: _jsx(SmartSelect, { editable: editable, step: step, icon: step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined, getOptions: getEntityValueOptions, getOptionalDependencies: getOptionalDependencies, getOptionSelected: function (option, value) {
139
+ var getOptions = useCallback(function (step, dependencyStore, ids) { return __awaiter(_this, void 0, void 0, function () {
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, getEntityValueOptions(step, dependencyStore, ids,
143
+ // mapDraft
144
+ fetchFilterIntegration)];
145
+ case 1: return [2 /*return*/, _a.sent()];
146
+ }
147
+ });
148
+ }); }, [fetchFilterIntegration]);
149
+ return (_jsxs(React.Fragment, { children: [dialogs !== undefined && ((_b = form.entities) === null || _b === void 0 ? void 0 : _b[step.idEntity]) && (_jsx(MaterialEntityValueDialog, { type: dialogs.current.type, entity: (_c = form.entities) === null || _c === void 0 ? void 0 : _c[step.idEntity], entityValue: dialogs.value, message: dialogs.current.message, handleClose: handleCloseDialog })), _jsx(StepFillerContainer, __assign({ step: step }, { children: _jsx(SmartSelect, { editable: editable, step: step, icon: step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined, getOptions: getOptions, getOptionalDependencies: getOptionalDependencies, getOptionSelected: function (option, value) {
100
150
  return option._id === value._id;
101
151
  }, calcDepError: function (steps) {
102
152
  for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
@@ -171,13 +221,15 @@ function EntityValuePickerStep(_a) {
171
221
  } }) }))] }));
172
222
  }
173
223
  export default EntityValuePickerStep;
174
- var getEntityValueOptions = function (step, dependencyStore, _a) {
224
+ var getEntityValueOptions = function (step, dependencyStore, _a, fetchFilterIntegration
225
+ // mapDraftEntities: (property: string) => Promise<EurekaDraft | undefined>
226
+ ) {
175
227
  var idOrganization = _a.idOrganization, idCurrentAgent = _a.idCurrentAgent;
176
228
  return __awaiter(void 0, void 0, void 0, function () {
177
- var urlPath, _i, _b, path, idEntityValue, currentValue, params, _c, _d, filter, currentValue, url, response;
178
- var _e, _f, _g, _h, _j;
179
- return __generator(this, function (_k) {
180
- switch (_k.label) {
229
+ var urlPath, _i, _b, path, idEntityValue, currentValue, params, _c, _d, filter, _e, payload, _f, _g, _h, key, erkValue, currentValue, filtered, currentValue, url, response;
230
+ var _j, _k, _l, _m, _o, _p, _q, _r;
231
+ return __generator(this, function (_s) {
232
+ switch (_s.label) {
181
233
  case 0:
182
234
  if (!idOrganization)
183
235
  return [2 /*return*/, null];
@@ -187,56 +239,106 @@ var getEntityValueOptions = function (step, dependencyStore, _a) {
187
239
  idEntityValue = 'null';
188
240
  switch (path.type) {
189
241
  case EntityValueDataTypes.STEP: {
190
- currentValue = (_e = dependencyStore[path.idStep]) === null || _e === void 0 ? void 0 : _e.value;
242
+ currentValue = (_j = dependencyStore[path.idStep]) === null || _j === void 0 ? void 0 : _j.value;
191
243
  if (!currentValue)
192
244
  return [2 /*return*/, null];
193
245
  if (typeof currentValue === 'string')
194
246
  idEntityValue = currentValue;
195
247
  else
196
- idEntityValue = (_f = currentValue._id) !== null && _f !== void 0 ? _f : currentValue.id;
248
+ idEntityValue = (_k = currentValue._id) !== null && _k !== void 0 ? _k : currentValue.id;
197
249
  break;
198
250
  }
199
251
  case EntityValueDataTypes.VALUE:
200
252
  default:
201
- idEntityValue = (_g = path.idEntityValue) !== null && _g !== void 0 ? _g : 'null';
253
+ idEntityValue = (_l = path.idEntityValue) !== null && _l !== void 0 ? _l : 'null';
202
254
  break;
203
255
  }
204
256
  urlPath +=
205
257
  '/' + path.idEntity + (idEntityValue ? '/' + idEntityValue : '');
206
258
  }
207
259
  params = new URLSearchParams({});
208
- for (_c = 0, _d = step.filters; _c < _d.length; _c++) {
209
- filter = _d[_c];
210
- switch (filter.type) {
211
- case EntityValueDataTypes.STEP: {
212
- currentValue = (_h = dependencyStore[filter.idStep]) === null || _h === void 0 ? void 0 : _h.value;
260
+ _c = 0, _d = step.filters;
261
+ _s.label = 1;
262
+ case 1:
263
+ if (!(_c < _d.length)) return [3 /*break*/, 8];
264
+ filter = _d[_c];
265
+ _e = filter.type;
266
+ switch (_e) {
267
+ case EntityValueDataTypes.INTEGRATION: return [3 /*break*/, 2];
268
+ case EntityValueDataTypes.STEP: return [3 /*break*/, 4];
269
+ case EntityValueDataTypes.CURRENT_AGENT: return [3 /*break*/, 5];
270
+ case EntityValueDataTypes.VALUE: return [3 /*break*/, 6];
271
+ }
272
+ return [3 /*break*/, 6];
273
+ case 2:
274
+ payload = {};
275
+ for (_f = 0, _g = Object.entries((_m = filter.values) !== null && _m !== void 0 ? _m : {}); _f < _g.length; _f++) {
276
+ _h = _g[_f], key = _h[0], erkValue = _h[1];
277
+ switch (erkValue.type) {
278
+ case ErkValueTypes.BOOLEAN:
279
+ payload[key] = erkValue.value;
280
+ break;
281
+ case ErkValueTypes.DRAFT: {
282
+ //TODO: Hacer esto bien, la lambda tiene que ser capaz de calcular un draft en un filtro
283
+ // values[key] = await mapDraftEntities(
284
+ // `filters[${index}].values.${key}`
285
+ // );
286
+ break;
287
+ }
288
+ case ErkValueTypes.STEP: {
289
+ currentValue = (_o = dependencyStore[erkValue.idStep]) === null || _o === void 0 ? void 0 : _o.value;
213
290
  if (currentValue) {
214
291
  if (typeof currentValue === 'string')
215
- params.set(filter.idProperty, currentValue);
292
+ payload[key] = currentValue;
216
293
  else
217
- params.set(filter.idProperty, (_j = currentValue._id) !== null && _j !== void 0 ? _j : currentValue.id);
218
- }
219
- else if (filter.required) {
220
- return [2 /*return*/, null];
294
+ payload[key] =
295
+ (_p = currentValue._id) !== null && _p !== void 0 ? _p : currentValue.id;
221
296
  }
297
+ else
298
+ payload[key] = null;
222
299
  break;
223
300
  }
224
- case EntityValueDataTypes.CURRENT_AGENT:
225
- if (idCurrentAgent)
226
- params.set(filter.idProperty, idCurrentAgent);
227
- break;
228
- case EntityValueDataTypes.VALUE:
229
- default:
230
- params.set(filter.idProperty, filter.value);
231
- break;
232
301
  }
233
302
  }
303
+ return [4 /*yield*/, fetchFilterIntegration(filter.idIntegration, payload)];
304
+ case 3:
305
+ filtered = _s.sent();
306
+ if (filtered.length === 0)
307
+ return [2 /*return*/, null];
308
+ params.set(filter.idProperty, filtered.join(','));
309
+ return [3 /*break*/, 7];
310
+ case 4:
311
+ {
312
+ currentValue = (_q = dependencyStore[filter.idStep]) === null || _q === void 0 ? void 0 : _q.value;
313
+ if (currentValue) {
314
+ if (typeof currentValue === 'string')
315
+ params.set(filter.idProperty, currentValue);
316
+ else
317
+ params.set(filter.idProperty, (_r = currentValue._id) !== null && _r !== void 0 ? _r : currentValue.id);
318
+ }
319
+ else if (filter.required) {
320
+ return [2 /*return*/, null];
321
+ }
322
+ return [3 /*break*/, 7];
323
+ }
324
+ _s.label = 5;
325
+ case 5:
326
+ if (idCurrentAgent)
327
+ params.set(filter.idProperty, idCurrentAgent);
328
+ return [3 /*break*/, 7];
329
+ case 6:
330
+ params.set(filter.idProperty, filter.value);
331
+ return [3 /*break*/, 7];
332
+ case 7:
333
+ _c++;
334
+ return [3 /*break*/, 1];
335
+ case 8:
234
336
  url = "".concat(idOrganization, "/entities/").concat(step.idEntity).concat(urlPath, "?").concat(params.toString());
235
337
  return [4 /*yield*/, widgetInstance.get(url, {
236
338
  timeout: 120000,
237
339
  })];
238
- case 1:
239
- response = _k.sent();
340
+ case 9:
341
+ response = _s.sent();
240
342
  return [2 /*return*/, response.data.filter(function (option) { var _a; return ((_a = step.options[option._id]) === null || _a === void 0 ? void 0 : _a.type) !== EntityValueOptionTypes.HIDE; })];
241
343
  }
242
344
  });
@@ -62,14 +62,11 @@ export var DraftApi = RootApi.injectEndpoints({
62
62
  if (!apiKey)
63
63
  return [2 /*return*/, { data: undefined }];
64
64
  if (!idOrganization) return [3 /*break*/, 4];
65
- return [4 /*yield*/, widgetInstance.post("/form/draft/".concat(apiKey, "?idOrganization=").concat(idOrganization), {
66
- property: property,
67
- dependencies: dependencies,
68
- })];
65
+ return [4 /*yield*/, widgetInstance.post("/form/draft/".concat(apiKey, "?idOrganization=").concat(idOrganization), { property: property, dependencies: dependencies })];
69
66
  case 3:
70
67
  response = _d.sent();
71
68
  return [3 /*break*/, 6];
72
- case 4: return [4 /*yield*/, axiosInstance.post("/form/draft/".concat(apiKey), dependencies)];
69
+ case 4: return [4 /*yield*/, axiosInstance.post("/form/draft/".concat(apiKey), { property: property, dependencies: dependencies })];
73
70
  case 5:
74
71
  response = _d.sent();
75
72
  _d.label = 6;
@@ -0,0 +1,21 @@
1
+ export declare const IntegrationsApi: import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<{
2
+ url: string;
3
+ timeout?: number | undefined;
4
+ method?: string | undefined;
5
+ body?: any;
6
+ params?: any;
7
+ headers?: Record<string, any> | undefined;
8
+ }, unknown, unknown, {}, {}>, {
9
+ fetchFilterIntegration: import("@reduxjs/toolkit/query").QueryDefinition<{
10
+ idForm: string;
11
+ idIntegration: string;
12
+ payload: Record<string, any>;
13
+ }, import("@reduxjs/toolkit/query").BaseQueryFn<{
14
+ url: string;
15
+ timeout?: number | undefined;
16
+ method?: string | undefined;
17
+ body?: any;
18
+ params?: any;
19
+ headers?: Record<string, any> | undefined;
20
+ }, unknown, unknown, {}, {}>, never, string[] | undefined, "api">;
21
+ }, "api", never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/dist/query/react").reactHooksModuleName>;
@@ -0,0 +1,69 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { RootApi } from '../Utils/_api';
38
+ import axiosInstance from '../Utils/AxiosAPI';
39
+ import widgetInstance from '../Utils/AxiosWidget';
40
+ export var IntegrationsApi = RootApi.injectEndpoints({
41
+ endpoints: function (build) { return ({
42
+ fetchFilterIntegration: build.query({
43
+ queryFn: function (_a, _b) {
44
+ var idForm = _a.idForm, idIntegration = _a.idIntegration, payload = _a.payload;
45
+ var getState = _b.getState;
46
+ return __awaiter(void 0, void 0, void 0, function () {
47
+ var idOrganization, response;
48
+ return __generator(this, function (_c) {
49
+ switch (_c.label) {
50
+ case 0:
51
+ idOrganization = getState().forms[idForm]
52
+ .global.idOrganization;
53
+ if (!idOrganization) return [3 /*break*/, 2];
54
+ return [4 /*yield*/, widgetInstance.post("/form/integrations/".concat(idIntegration, "?idOrganization=").concat(idOrganization), payload)];
55
+ case 1:
56
+ response = _c.sent();
57
+ return [3 /*break*/, 4];
58
+ case 2: return [4 /*yield*/, axiosInstance.post("/form/integrations/".concat(idIntegration), payload)];
59
+ case 3:
60
+ response = _c.sent();
61
+ _c.label = 4;
62
+ case 4: return [2 /*return*/, { data: response.data }];
63
+ }
64
+ });
65
+ });
66
+ },
67
+ }),
68
+ }); },
69
+ });
@@ -0,0 +1,6 @@
1
+ export declare enum ErkValueTypes {
2
+ DRAFT = "DRAFT",
3
+ STEP = "STEP",
4
+ BOOLEAN = "BOOLEAN"
5
+ }
6
+ export default ErkValueTypes;
@@ -0,0 +1,7 @@
1
+ export var ErkValueTypes;
2
+ (function (ErkValueTypes) {
3
+ ErkValueTypes["DRAFT"] = "DRAFT";
4
+ ErkValueTypes["STEP"] = "STEP";
5
+ ErkValueTypes["BOOLEAN"] = "BOOLEAN";
6
+ })(ErkValueTypes || (ErkValueTypes = {}));
7
+ export default ErkValueTypes;
@@ -57,7 +57,8 @@ export declare enum MapperStyleTypes {
57
57
  export declare enum EntityValueDataTypes {
58
58
  STEP = "STEP",
59
59
  VALUE = "VALUE",
60
- CURRENT_AGENT = "CURRENT_AGENT"
60
+ CURRENT_AGENT = "CURRENT_AGENT",
61
+ INTEGRATION = "INTEGRATION"
61
62
  }
62
63
  export declare enum ApiSelectorParamTypes {
63
64
  STEP = "STEP",
@@ -68,6 +68,7 @@ export var EntityValueDataTypes;
68
68
  EntityValueDataTypes["STEP"] = "STEP";
69
69
  EntityValueDataTypes["VALUE"] = "VALUE";
70
70
  EntityValueDataTypes["CURRENT_AGENT"] = "CURRENT_AGENT";
71
+ EntityValueDataTypes["INTEGRATION"] = "INTEGRATION";
71
72
  })(EntityValueDataTypes || (EntityValueDataTypes = {}));
72
73
  export var ApiSelectorParamTypes;
73
74
  (function (ApiSelectorParamTypes) {
package/dist/hooks.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import type { TypedUseSelectorHook } from 'react-redux';
2
2
  import { type RootState, type AppDispatch } from './Utils/store';
3
+ import { ThunkAction } from '@reduxjs/toolkit';
4
+ import { QueryActionCreatorResult, QueryDefinition, ResultTypeFrom } from '@reduxjs/toolkit/query';
3
5
  export declare const useAppDispatch: () => AppDispatch;
4
6
  export declare const useAppSelector: TypedUseSelectorHook<RootState>;
5
7
  export declare const selectBreakPoint: (state: RootState) => number;
8
+ export declare function useApiSubscribe(): <D extends QueryDefinition<any, any, any, any>>(subscription: ThunkAction<QueryActionCreatorResult<D>, any, any, any>) => Promise<ResultTypeFrom<D> | undefined>;
package/dist/hooks.js CHANGED
@@ -1,6 +1,42 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
1
37
  import { createDispatchHook, createSelectorHook } from 'react-redux';
2
38
  import { defaultRootState, } from './Utils/store';
3
- import { useContext } from 'react';
39
+ import { useCallback, useContext, useEffect, useRef } from 'react';
4
40
  import { IdFormContext } from './App/App';
5
41
  import { StoreContext } from './Utils/StoreContext';
6
42
  var useSelector = createSelectorHook(StoreContext);
@@ -22,3 +58,28 @@ export var useAppSelector = function (selector, options) {
22
58
  export var selectBreakPoint = function (state) {
23
59
  return state.widthStats.currentBreakPoint;
24
60
  };
61
+ export function useApiSubscribe() {
62
+ var _this = this;
63
+ var dispatch = useAppDispatch();
64
+ var subscriptions = useRef([]);
65
+ useEffect(function () {
66
+ return function () {
67
+ subscriptions.current.forEach(function (unsubscribe) { return unsubscribe(); });
68
+ };
69
+ }, []);
70
+ var subscribe = useCallback(function (subscription) { return __awaiter(_this, void 0, void 0, function () {
71
+ var result;
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0:
75
+ result = dispatch(subscription);
76
+ result.unsubscribe();
77
+ return [4 /*yield*/, result];
78
+ case 1:
79
+ // subscriptions.current.push(() => result.unsubscribe());
80
+ return [2 /*return*/, (_a.sent()).data];
81
+ }
82
+ });
83
+ }); }, [dispatch]);
84
+ return subscribe;
85
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version": "2.0.120",
4
+ "version": "2.0.121",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",