@arquimedes.co/eureka-forms 1.4.5-test → 1.4.8-test

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/App.js CHANGED
@@ -68,18 +68,10 @@ import widgetInstance from './AxiosWidget';
68
68
  function App(_a) {
69
69
  var _this = this;
70
70
  var _b, _c, _d, _e;
71
- var apiKey = _a.apiKey, domain = _a.domain, preview = _a.preview, formData = _a.formData, postview = _a.postview, isWidget = _a.isWidget, internal = _a.internal, valuesData = _a.valuesData, _f = _a.customSend, customSend = _f === void 0 ? function (a, b) { return __awaiter(_this, void 0, void 0, function () {
72
- return __generator(this, function (_a) {
73
- // eslint-disable-next-line no-console
74
- console.log('HOLA', a, b);
75
- return [2 /*return*/];
76
- });
77
- }); } : _f, customSteps = _a.customSteps, handleConfirmed = _a.handleConfirmed, others = __rest(_a, ["apiKey", "domain", "preview", "formData", "postview", "isWidget", "internal", "valuesData", "customSend", "customSteps", "handleConfirmed"]);
78
- // eslint-disable-next-line no-console
79
- console.log(formData, valuesData, customSend);
80
- var _g = useState(undefined), form = _g[0], setForm = _g[1];
81
- var _h = useState({}), originalValues = _h[0], setOriginalValues = _h[1];
82
- var _j = useState(undefined), organizationInfo = _j[0], setOrganizationInfo = _j[1];
71
+ var apiKey = _a.apiKey, domain = _a.domain, preview = _a.preview, formData = _a.formData, postview = _a.postview, isWidget = _a.isWidget, internal = _a.internal, valuesData = _a.valuesData, customSend = _a.customSend, customSteps = _a.customSteps, handleConfirmed = _a.handleConfirmed, others = __rest(_a, ["apiKey", "domain", "preview", "formData", "postview", "isWidget", "internal", "valuesData", "customSend", "customSteps", "handleConfirmed"]);
72
+ var _f = useState(undefined), form = _f[0], setForm = _f[1];
73
+ var _g = useState({}), originalValues = _g[0], setOriginalValues = _g[1];
74
+ var _h = useState(undefined), organizationInfo = _h[0], setOrganizationInfo = _h[1];
83
75
  function fetchPreview(formData) {
84
76
  return __awaiter(this, void 0, void 0, function () {
85
77
  var response;
@@ -257,12 +257,13 @@ function stringToDraft(text) {
257
257
  return draftStructure;
258
258
  }
259
259
  function calcDependencies(steps, originalValues) {
260
+ var _a;
260
261
  var dependencies = {};
261
- for (var _i = 0, _a = Object.values(steps); _i < _a.length; _i++) {
262
- var step = _a[_i];
262
+ for (var _i = 0, _b = Object.values(steps); _i < _b.length; _i++) {
263
+ var step = _b[_i];
263
264
  if (step.dependencies) {
264
- for (var _b = 0, _c = step.dependencies; _b < _c.length; _b++) {
265
- var idDep = _c[_b];
265
+ for (var _c = 0, _d = step.dependencies; _c < _d.length; _c++) {
266
+ var idDep = _d[_c];
266
267
  var depStep = steps[idDep];
267
268
  if (depStep && dependencies[idDep] === undefined) {
268
269
  switch (depStep === null || depStep === void 0 ? void 0 : depStep.type) {
@@ -277,13 +278,12 @@ function calcDependencies(steps, originalValues) {
277
278
  break;
278
279
  }
279
280
  default:
280
- dependencies[idDep] = originalValues[idDep];
281
+ dependencies[idDep] = (_a = originalValues[idDep]) !== null && _a !== void 0 ? _a : null;
281
282
  break;
282
283
  }
283
284
  }
284
285
  }
285
286
  }
286
287
  }
287
- dependencies['CBR_PROYECTO'] = null; //REMOVE
288
288
  return dependencies;
289
289
  }
@@ -57,8 +57,13 @@ function CBRLocativasStep(props) {
57
57
  marginTop: 2,
58
58
  } }, void 0), getOptions: getLocativasOptions, getOptionSelected: function (option, value) {
59
59
  return option.id === value.id;
60
- }, valueOverwrite: function (value) {
61
- return __assign(__assign({}, value), { subStep: props.step.subStep });
60
+ }, calcDepError: calcDepError, calcInvalidDeps: calcInvaidDependencies, valueOverwrite: function (value) {
61
+ if (value) {
62
+ return __assign(__assign({}, value), { subStep: props.step.subStep });
63
+ }
64
+ else {
65
+ return null;
66
+ }
62
67
  }, iconComponent: LeakIconComponent }, { children: _jsx(LocativasSubStepRenderer, {}, void 0) }), void 0));
63
68
  }
64
69
  export default CBRLocativasStep;
@@ -77,7 +82,7 @@ function LocativasSubStepRenderer(_a) {
77
82
  height: 23,
78
83
  width: 23,
79
84
  marginTop: 2,
80
- } }, void 0), getOptions: getLocativasOptions, getOptionSelected: function (option, value) {
85
+ } }, void 0), calcInvalidDeps: calcInvaidDependencies, getOptions: getLocativasOptions, calcDepError: calcDepError, getOptionSelected: function (option, value) {
81
86
  return option.id === value.id;
82
87
  }, iconComponent: LeakIconComponent }, { children: _jsx(LocativasSubStepRenderer, {}, void 0) }), void 0));
83
88
  }
@@ -91,18 +96,22 @@ function LeakIconComponent(props) {
91
96
  }
92
97
  var getLocativasOptions = function (step, dependencyStore) { return __awaiter(void 0, void 0, void 0, function () {
93
98
  var idProyecto, response, father_1, locativasList;
94
- var _a, _b;
95
- return __generator(this, function (_c) {
99
+ var _a;
100
+ return __generator(this, function (_b) {
96
101
  if (step.dependencies) {
97
102
  idProyecto = (_a = dependencyStore[step.dependencies[0]]) === null || _a === void 0 ? void 0 : _a.id;
98
103
  if (!idProyecto) {
99
104
  return [2 /*return*/, null]; //null para indicar que falta la depedency
100
105
  }
101
106
  response = LocativasData;
102
- father_1 = (_b = dependencyStore[step.dependencies[1]]) === null || _b === void 0 ? void 0 : _b.id;
107
+ father_1 = dependencyStore[step.dependencies[1]];
108
+ if (father_1 !== undefined && father_1.id === undefined) {
109
+ return [2 /*return*/, null];
110
+ }
103
111
  locativasList = response.lstLocativas.TipoLocativas.filter(function (locativa) {
104
- if (father_1) {
105
- return (locativa.Id.startsWith(father_1) && locativa.Id !== father_1);
112
+ if (father_1 === null || father_1 === void 0 ? void 0 : father_1.id) {
113
+ return (locativa.Id.startsWith(father_1.id) &&
114
+ locativa.Id !== father_1.id);
106
115
  }
107
116
  else {
108
117
  return locativa.Id.length === 2;
@@ -121,4 +130,29 @@ var getLocativasOptions = function (step, dependencyStore) { return __awaiter(vo
121
130
  return [2 /*return*/];
122
131
  });
123
132
  }); };
133
+ var calcInvaidDependencies = function (step, dependencyStore) {
134
+ var _a;
135
+ var deps = [];
136
+ if (step.dependencies) {
137
+ for (var _i = 0, _b = step.dependencies; _i < _b.length; _i++) {
138
+ var idDep = _b[_i];
139
+ if (((_a = dependencyStore[idDep]) === null || _a === void 0 ? void 0 : _a.id) === undefined) {
140
+ deps.push(idDep);
141
+ }
142
+ }
143
+ }
144
+ return deps;
145
+ };
146
+ var calcDepError = function (types) {
147
+ for (var _i = 0, _a = types; _i < _a.length; _i++) {
148
+ var type = _a[_i];
149
+ if (type === CBRFormStepTypes.CBR_PROYECTO) {
150
+ return 'Selecciona un proyecto';
151
+ }
152
+ if (type === CBRFormStepTypes.CBR_LOCATIVAS) {
153
+ return 'Selecciona un padre';
154
+ }
155
+ }
156
+ return undefined;
157
+ };
124
158
  var Leak = function (props) { return (_jsxs("svg", __assign({ fill: props.fill, className: props.class, style: props.style, height: "512pt", viewBox: "0 -86 512.00056 512", width: "512pt", xmlns: "http://www.w3.org/2000/svg" }, { children: [_jsx("path", { d: "m203.484375 196.359375c2.402344 0 4.753906-.867187 6.601563-2.492187l26.621093-23.394532c3.03125-2.664062 4.164063-6.890625 2.871094-10.714844l-9.21875-27.257812 21.613281-18.996094c3.03125-2.664062 4.164063-6.890625 2.871094-10.714844l-11.359375-33.570312c-1.070313-3.167969-3.652344-5.589844-6.882813-6.457031l-57.925781-15.519531c-5.335937-1.433594-10.816406 1.734374-12.246093 7.070312-1.429688 5.335938 1.734374 10.820312 7.070312 12.25l52.753906 14.132812 7.507813 22.1875-21.613281 18.996094c-3.03125 2.664063-4.164063 6.890625-2.871094 10.714844l9.21875 27.257812-17.59375 15.460938-130.027344-34.839844 30.992188-115.667968c.6875-2.5625.328124-5.292969-.996094-7.589844-1.328125-2.296875-3.511719-3.972656-6.074219-4.660156l-45.574219-12.210938c-5.332031-1.429688-10.816406 1.734375-12.246094 7.070312l-36.636718 136.722657c-.6875 2.5625-.324219 5.292969 1 7.589843 1.324218 2.292969 3.511718 3.972657 6.070312 4.65625l45.574219 12.210938c.867187.234375 1.738281.34375 2.597656.34375 4.414063 0 8.453125-2.945312 9.652344-7.414062l.464844-1.734376 135.199219 36.226563c.851562.230469 1.722656.34375 2.585937.34375zm-181.238281-56.703125 31.460937-117.40625 26.253907 7.035156-31.457032 117.40625zm0 0" }, void 0), _jsx("path", { d: "m511.660156 144.136719-36.636718-136.722657c-1.429688-5.332031-6.910157-8.5-12.246094-7.070312l-45.574219 12.210938c-2.5625.6875-4.746094 2.363281-6.070313 4.660156-1.328124 2.296875-1.6875 5.023437-1 7.585937l.464844 1.734375-135.199218 36.226563c-3.28125.878906-5.894532 3.367187-6.933594 6.605469-1.039063 3.238281-.363282 6.777343 1.796875 9.40625l19.121093 23.265624-5.867187 25.070313c-.796875 3.40625.242187 6.980469 2.738281 9.425781l19.386719 18.988282-6.847656 28.496093c-.824219 3.429688.21875 7.039063 2.742187 9.5 1.894532 1.84375 4.40625 2.839844 6.980469 2.839844.863281 0 1.730469-.113281 2.585937-.34375l57.925782-15.519531c5.335937-1.429688 8.5-6.914063 7.070312-12.25-1.429687-5.332032-6.914062-8.5-12.246094-7.070313l-41.683593 11.171875 4.246093-17.664062c.820313-3.421875-.214843-7.023438-2.726562-9.484375l-19.417969-19.015625 5.714844-24.398438c.710937-3.035156-.035156-6.222656-2.011719-8.628906l-12.40625-15.09375 120.207032-32.207031 30.992187 115.667969c1.199219 4.46875 5.238281 7.414062 9.65625 7.414062.855469 0 1.726563-.109375 2.59375-.339844l45.574219-12.210937c2.5625-.6875 4.746094-2.363281 6.070312-4.660157 1.328125-2.296874 1.6875-5.027343 1-7.589843zm-48.160156 2.554687-30.996094-115.667968s0 0 0-.003907v-.003906l-.464844-1.730469 26.257813-7.035156 31.457031 117.40625zm0 0" }, void 0), _jsx("path", { d: "m263.386719 203.265625c-1.894531-2.078125-4.574219-3.261719-7.386719-3.261719-2.808594 0-5.492188 1.183594-7.386719 3.261719-.78125.855469-1.640625 1.789063-2.570312 2.792969-14.488281 15.730468-44.640625 48.457031-44.640625 79.34375 0 30.105468 24.492187 54.601562 54.597656 54.601562s54.597656-24.496094 54.597656-54.601562c0-30.886719-30.148437-63.613282-44.640625-79.339844-.925781-1.007812-1.789062-1.941406-2.570312-2.796875zm-7.386719 116.738281c-19.078125 0-34.597656-15.523437-34.597656-34.601562 0-20.492188 20.960937-45.539063 34.597656-60.601563 13.636719 15.0625 34.597656 40.109375 34.597656 60.601563 0 19.078125-15.519531 34.601562-34.597656 34.601562zm0 0" }, void 0), _jsx("path", { d: "m129.878906 54.871094c.917969.261718 1.839844.386718 2.75.386718 4.351563 0 8.355469-2.863281 9.609375-7.253906 1.519531-5.3125-1.554687-10.847656-6.867187-12.363281h-.007813c-5.308593-1.519531-10.839843 1.554687-12.359375 6.867187-1.515625 5.308594 1.5625 10.847657 6.875 12.363282zm0 0" }, void 0), _jsx("path", { d: "m407.335938 149.527344-.007813.003906c-5.335937 1.421875-8.507813 6.898438-7.082031 12.238281 1.191406 4.472657 5.238281 7.421875 9.65625 7.421875.855468 0 1.722656-.109375 2.585937-.339844 5.335938-1.421874 8.507813-6.902343 7.085938-12.238281-1.425781-5.335937-6.90625-8.511719-12.238281-7.085937zm0 0" }, void 0)] }), void 0)); };
@@ -66,18 +66,43 @@ import React from 'react';
66
66
  function SmartSelect(_a) {
67
67
  var _this = this;
68
68
  var _b, _c, _d;
69
- var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, trigger = _a.trigger, children = _a.children, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, calcDepError = _a.calcDepError, iconComponent = _a.iconComponent, valueOverwrite = _a.valueOverwrite, dependencyStore = _a.dependencyStore, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "trigger", "children", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "calcDepError", "iconComponent", "valueOverwrite", "dependencyStore", "getOptionSelected", "setDependencyStore"]);
70
- var _e = useState(), options = _e[0], setOptions = _e[1];
71
- var _f = useState(), depError = _f[0], setDepError = _f[1];
72
- var calcOptions = function () { return __awaiter(_this, void 0, void 0, function () {
73
- var resp;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
69
+ var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, trigger = _a.trigger, children = _a.children, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, calcDepError = _a.calcDepError, iconComponent = _a.iconComponent, valueOverwrite = _a.valueOverwrite, dependencyStore = _a.dependencyStore, _e = _a.calcInvalidDeps, calcInvalidDeps = _e === void 0 ? function (step, depStore) {
70
+ var _a;
71
+ var missingDeps = [];
72
+ for (var _i = 0, _b = (_a = step.dependencies) !== null && _a !== void 0 ? _a : []; _i < _b.length; _i++) {
73
+ var idDep = _b[_i];
74
+ if (depStore[idDep] === null) {
75
+ missingDeps.push(idDep);
76
+ }
77
+ }
78
+ return missingDeps;
79
+ } : _e, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "trigger", "children", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "calcDepError", "iconComponent", "valueOverwrite", "dependencyStore", "calcInvalidDeps", "getOptionSelected", "setDependencyStore"]);
80
+ var _f = useState(true), first = _f[0], setFirst = _f[1];
81
+ var _g = useState(), options = _g[0], setOptions = _g[1];
82
+ var _h = useState(), error = _h[0], setError = _h[1];
83
+ var calcOptions = function (currentValue, invalidDeps) { return __awaiter(_this, void 0, void 0, function () {
84
+ var resp, currentOption, invalids;
85
+ var _a;
86
+ return __generator(this, function (_b) {
87
+ switch (_b.label) {
76
88
  case 0: return [4 /*yield*/, (getOptions === null || getOptions === void 0 ? void 0 : getOptions(step, dependencyStore))];
77
89
  case 1:
78
- resp = _a.sent();
90
+ resp = _b.sent();
79
91
  if (resp !== null) {
80
- setDepError(undefined);
92
+ if (invalidDeps !== undefined && currentValue) {
93
+ currentOption = resp.find(function (option) {
94
+ return getOptionSelected(option, currentValue);
95
+ });
96
+ if (!currentOption) {
97
+ setError('Este campo es obligatorio');
98
+ }
99
+ }
100
+ else {
101
+ invalids = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
102
+ if (invalids.length === 0) {
103
+ setError(undefined);
104
+ }
105
+ }
81
106
  }
82
107
  setOptions(resp);
83
108
  return [2 /*return*/];
@@ -85,26 +110,29 @@ function SmartSelect(_a) {
85
110
  });
86
111
  }); };
87
112
  useEffect(function () {
88
- if (value) {
89
- onChange(null);
113
+ if (first) {
114
+ setFirst(false);
115
+ var invalids = calcInvalidDeps(step, dependencyStore);
116
+ setError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalids.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
117
+ calcOptions(value, invalids);
118
+ }
119
+ else {
120
+ if (value)
121
+ onChange(null);
122
+ calcOptions(null);
90
123
  }
91
- calcOptions();
92
124
  }, (_c = (_b = step.dependencies) === null || _b === void 0 ? void 0 : _b.map(function (dep) { return dependencyStore[dep]; })) !== null && _c !== void 0 ? _c : []);
93
125
  var handleMissingDep = function () { return __awaiter(_this, void 0, void 0, function () {
94
- var missingDeps, _i, _a, idDep;
95
- return __generator(this, function (_b) {
126
+ var invalids;
127
+ return __generator(this, function (_a) {
96
128
  if (step.dependencies) {
97
- missingDeps = [];
98
- for (_i = 0, _a = step.dependencies; _i < _a.length; _i++) {
99
- idDep = _a[_i];
100
- if (dependencyStore[idDep] === null) {
101
- missingDeps.push(idDep);
129
+ invalids = calcInvalidDeps(step, dependencyStore);
130
+ setError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalids.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
131
+ if (!value) {
132
+ if (invalids.length > 0) {
133
+ trigger(invalids, { shouldFocus: true });
102
134
  }
103
135
  }
104
- setDepError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(missingDeps.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
105
- if (missingDeps.length > 0) {
106
- trigger(missingDeps, { shouldFocus: true });
107
- }
108
136
  }
109
137
  return [2 /*return*/];
110
138
  });
@@ -126,16 +154,18 @@ function SmartSelect(_a) {
126
154
  valueOverwrite
127
155
  ? onChange(valueOverwrite(value))
128
156
  : onChange(value);
129
- }, getOptionSelected: getOptionSelected, helperText: depError !== null && depError !== void 0 ? depError : (errors[step.id]
157
+ setError(undefined);
158
+ }, getOptionSelected: getOptionSelected, helperText: error !== null && error !== void 0 ? error : (errors[step.id]
130
159
  ? errors[step.id].message
131
- : step.description), error: depError !== undefined || !!errors[step.id] }, void 0) }), void 0), children &&
160
+ : step.description), error: error !== undefined || !!errors[step.id] }, void 0) }), void 0), children &&
132
161
  cloneElement(children, {
133
162
  value: value,
134
163
  stepProps: __assign({ step: step, form: form, errors: errors, trigger: trigger, postview: postview, formStyle: formStyle, widthStats: widthStats, dependencyStore: dependencyStore, setDependencyStore: setDependencyStore }, others),
135
164
  })] }, void 0));
136
165
  }
137
166
  function SmartSelectStep(props) {
138
- return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: null, rules: {
167
+ var _a;
168
+ return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: (_a = props.originalValues[props.step.id]) !== null && _a !== void 0 ? _a : null, rules: {
139
169
  required: props.step.required
140
170
  ? 'Este campo es obligatorio'
141
171
  : undefined,
@@ -10,15 +10,17 @@ export interface SmartSelectStepProps extends Omit<StepProps, 'step'> {
10
10
  /** The iconComponent to display in the selector */
11
11
  iconComponent?: any;
12
12
  /** Function to call to get the options of the selector, return null if dependency is not met */
13
- getOptions?: (step: GSmartSelect, dependencyStore: Record<string, any>) => Promise<any[] | null>;
13
+ getOptions: (step: GSmartSelect, dependencyStore: Record<string, any>) => Promise<any[] | null>;
14
14
  /** Function to determine the currently selected option */
15
- getOptionSelected?: (option: any, value: any) => boolean;
15
+ getOptionSelected: (option: any, value: any) => boolean;
16
16
  /** Function that returns the error message based on the types of the missing Dependencies, undefined if no error msg */
17
17
  calcDepError?: (types: Types[]) => string | undefined;
18
+ /** Function that returns the missing dependencies based on the current value */
19
+ calcInvalidDeps?: (step: GSmartSelect, dependencyStore: Record<string, any>) => string[];
18
20
  /** children to render */
19
21
  children?: React.ReactElement<any, string>;
20
22
  /** Function that overwrites the value before setting it */
21
- valueOverwrite?: (value: any) => any;
23
+ valueOverwrite?: (value: any | null) => any;
22
24
  }
23
25
  declare function SmartSelectStep(props: SmartSelectStepProps): JSX.Element;
24
26
  export default SmartSelectStep;
@@ -143,7 +143,7 @@ export default function RoundedSmartSelect(_a) {
143
143
  if (typeof option === 'string') {
144
144
  return option;
145
145
  }
146
- else if (option.inputValue) {
146
+ else if (option === null || option === void 0 ? void 0 : option.inputValue) {
147
147
  return option.inputValue;
148
148
  }
149
149
  else {
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":"1.4.5-test",
4
+ "version":"1.4.8-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",